8

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

2 Answers 2

14

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.