MongoDB加上docker-compose:如何创建用户和数据库

时间:2018-10-01 17:26:02

标签: mongodb docker-compose seeding

我正在阅读mongodb的docker文档,以了解如何使用docker-compose创建用户空数据库。原来你做不到。除非您插入实际数据,否则不会有数据库。

mongo

MONGO_INITDB_DATABASE

This variable allows you to specify the name of a database to be used for    creation scripts in /docker-entrypoint-initdb.d/*.js (see Initializing a fresh instance below). MongoDB is fundamentally designed for "create on first use", so if you do not insert data with your JavaScript files, then no database is created.

不幸的是,他们没有提供数据播种部分的示例。

对于用户创建部分,我将其放在我的资产/1_mongodb-setup.js中

db.createUser(
{
  user: "test",
  pwd: "test",
  roles: [
    { role: "readWrite", db: "doug_DB" }
  ]
})

但是如何处理数据?应该在单独的.js文件中吗? 什么是cmd?

0 个答案:

没有答案