views:

500

answers:

3

Hey,

I am using mongoDB and am curious to whether you can import scripts like you can in MySQL:

mysql -uuser -ppassword database < script.sql

Can you do this with mongoDB?

Cheers

Eef

+1  A: 

I think you need to use a library like PyMongo to access the db, but after installing you should be able to script aggainst the mongoDB very well using python.

zoidbeck
+2  A: 

You can use mongoimport, a utility that ships with mongodb. Here are some docs:

http://www.mongodb.org/display/DOCS/Import+Export+Tools?focusedCommentId=4554852#ImportExportTools-mongoimport

There's also mongodump and mongorestore.

Kyle Banker
+3  A: 

You can pass a list of JS files to the mongo JavaScript shell and those will get executed:

$ echo "print('hello');" > test.js
$ ./mongo test.js
MongoDB shell version: 1.3.2-
url: test
connecting to: test
hello

You can use the normal mongo command line arguments if you need to specify a specific db, username, or password like you do in your above example.

mdirolf