Reputation: 973
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
use main; // not taking, throw error when using "mongo myscript.js"
Upvotes: 4
Views: 3810
Reputation: 230356
Use this in your script
db = db.getSiblingDB('main');
The default DB is test
. This statement gets a "sibling" database of test
.
Upvotes: 11