4

I can run the script in the specific database like

 mongo main myscript.js<br/>

where main is a database name. The same thing I am unable to run inside the script like

myscript.js

 use main;   // not taking, throw error when using "mongo myscript.js"

1 Answer 1

11

Use this in your script

db = db.getSiblingDB('main');

The default DB is test. This statement gets a "sibling" database of test.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.