How to load initial data in MongoDB?

后端 未结 2 715
我在风中等你
我在风中等你 2020-12-29 21:07

Does anyone know how to populate mongodb with initial data? For example, with a traditional SQL database, you can put all your SQL statements in a textfile, then load that u

相关标签:
2条回答
  • 2020-12-29 22:01

    ./mongo server:27017/dbname --quiet my_commands.js

    In my_commands.js:

    db.users.insert({name:"john", email:"john@doe.com", age:12});
    
    0 讨论(0)
  • 2020-12-29 22:02

    You can use the mongoimport tool that comes with MongoDB to import raw data.

    To run scripts from a file, e.g. to recreate indexes, pass the file name as a command line argument:

    mongo file.js "another file.js"
    
    0 讨论(0)
提交回复
热议问题