I am running a mongodb on a linux box. So every time I connect to it from the console (typing mongo
) I get something like this:
MongoDB shell version: 2.4.9
connecting to: test
And then I am doing use myDatabase
(where myDatabase is 99% is the same). So basically I always do some unneeded type of work. Is there a way to configure mongo, so that it will connect to myDatabase
by default?
Surprised that I don't find a duplicate of this. Okay, now we have content.
From the command line, just do this:
This actually is covered in the documentation, albeit down the page somewhat. No direct link but search for
<db address>
and the same example is there.Of course you could have done:
Which shows the usage along with other options you can pass in.
Another thing, not quite a default connect but a shortcut is you can do this in the
.mongorc.js
file:Which assigns the variable
db
to that database so now:Is acting on
myDatabase
.