Alex Rivera | Logout

How to load initial data in MongoDB?

Asked 2010-08-08T12:33:27.533
27

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 using a SQL command. This is extremely useful for unit testing.

Is it possible to do this with the mongo shell? For example, write down a list of shell statements into a file, and get the mongo shell to read the file and execute the statements.

Edit
Report

1 Answer

19

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"
answered 2010-08-08T13:05:16.820

Your Answer