Skip to content

How to skip load more fixtures without removing existing entries. #17

@krzywiecki

Description

@krzywiecki

Hello guys! Thanks a lot for a great job!

I have a question about how can I load some fixtures to my database without removing existing entries from the collection. My use case is that I have a list of categories in my app with some categories defined at the start by myself (these I want to load from fixtures) but users of the app can also create more categories. So what I want to do is to only add entries defined in fixtures but not removing existing ones. I did manage to do it by removing unload() function from my file but then I'm getting an error as it tries to add entries that already exist (the key name in the collection has to be unique).

My file looks like this:

require('dotenv').config();
const Fixtures = require('node-mongodb-fixtures');
const fixtures = new Fixtures({
  dir: './fixtures',
});

fixtures
  .connect(process.env.DB_CONNECTION_URL)
  .then(() => fixtures.load())
  .catch(e => console.error(e))
  .then(() => fixtures.disconnect());

As you can see I'm catching these errors so it works but I'm wondering if there is a better solution for my use case?

Thanks!

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions