-
Hey @pkosiec thanks for this cool tool. I noticed that I export an array of 6 objects from the collection folder, but 7 documents are created in the collection after seeding the database. Here is my code: // User roles is an array of 6 roles
module.exports = userRoles.map((role) => ({
title: role,
permissions: permissions[role],
})); import { Seeder } from "mongo-seeding";
import path from "path";
import config from "../config";
const {
dbHost, dbPort, dbName, dbUser, dbPassword,
} = config;
const seeder = new Seeder({
database: "dburl",
dropDatabase: false,
dropCollections: true,
});
const collections = seeder.readCollectionsFromPath(
path.resolve(__dirname, "../seeders"),
);
seeder.import(collections)
.then(() => {
console.log("Successfully seeded database");
})
.catch((err) => {
console.log("Failed to seed the database", err);
}); All 6 documents get created successfully, but one additional document containing just an ID is created also. It looks like this: {"_id":{"$oid":"5ef62ba3b2928a7520202a01"}} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @georgeben, are you sure the Also, are you sure there are no other files in the |
Beta Was this translation helpful? Give feedback.
-
Hey @pkosiec thank you for your quick reply. You're right, there was another file in my seeders directory. I am using babel to transpile my code before running it. After building my source code, I noticed babel was including some additional files that was causing that extra document to be created. I have resolved it now, so I'm closing this issue. Thanks once again. |
Beta Was this translation helpful? Give feedback.
-
@georgeben No problem - I'm glad you resolved your issue 🙂 Cheers! |
Beta Was this translation helpful? Give feedback.
Hi @georgeben, are you sure the
userRoles
array doesn't contain any null/undefined value? Could you please print what exactly is in the array?Also, are you sure there are no other files in the
seeders
directory?