Command Line
You can select the database to use on the mongo command line, eg for 'mydb':
mongo mydb
If a database name is not provided, 'test' will be used.
In .mongorc.js
If you want to set a default database without specifying on the command line each time, you can add a line to the .mongorc.js
file in your home directory:
db = db.getSiblingDB("mydb")
The .mongorc.js
file is executed after the mongo
shell is started, so if you set a default here it will override a database specified on the command line.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…