MongoDB external script file

bash, linux, mongodb

Solution

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.

Problem

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

Original source