Connect to a specific default database in mongodb

I am running mongodb in linux box. Therefore, every time I connect to it from the console (by typing mongo), I get something like this:

MongoDB shell version: 2.4.9
connecting to: test

And then I use myDatabase(where myDatabase is 99% the same). So basically, I always do an unnecessary type of work. Is there a way to configure mongo to connect to by default myDatabase?

+4
source share
1 answer

Surprised that I did not find a duplicate of this. Ok, now we have the content.

From the command line, simply do the following:

$ mongo myDatabase

, . , <db address> .

, :

$ mongo --help
MongoDB shell version: 2.4.9
usage: mongo [options] [db address] [file names (ending in .js)]
db address can be:
    foo                   foo database on local machine
    192.169.0.5/foo       foo database on 192.168.0.5 machine
    192.169.0.5:9999/foo  foo database on 192.168.0.5 machine on port 9999

, .

, , , .mongorc.js:

db=db.getSiblingDB("myDatabase")

db :

db.collection.find()

myDatabase.

+8

Source: https://habr.com/ru/post/1531878/


All Articles