I am attempting to seed my MongoDB in Docker. my docker-compose.yml file is pretty straight forward, here is my volume though:
...
volumes:
- ./mongo/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
- ./mongo/mongod.conf:/etc/mongod.conf:ro
- ./mongo/mongo-volume:/data/db
...
I have init-mongo.js mapped as a volume, here is its contents:
db.createUser({
user: 'root',
pwd: 'toor',
roles: [
{
role: 'readWrite',
db: 'testDB',
},
],
});
db.createCollection('users', { capped: false });
db.createCollection('test', { capped: false });
db.test.insert([
{ "item": 1 },
{ "item": 2 },
{ "item": 3 },
{ "item": 4 },
{ "item": 5 }
]);
The user root and the database testDB as well as the collections users and test are all created with no problem.
The issue is that db.test.insert([]) seems to be missed all together, and NO documents are inserted into the test collection.
Any Ideas why that is? I would absolutely love to get this working and would really appreciate any assistance with this.
Thanks, -Kevin