显示我目前在 MongoDB 中使用的数据库的命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16004182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 13:09:40  来源:igfitidea点击:

Command to show the db that I'm currently using in MongoDB?

mongodb

提问by HaoQi Li

What is the command to show the current db in the MongoDB shell?

在 MongoDB shell 中显示当前数据库的命令是什么?

(I failed to find it on Google)

(我在谷歌上没找到)

回答by HaoQi Li

Found it by guessing :) Simply:

通过猜测找到它:) 简单地说:

db

db

回答by Asya Kamsky

The command to get database name in the shell is:

在shell中获取数据库名称的命令是:

> db.getName()

While just typing db works, you will find that this only works interactively and if you're working on a script this may not give the result you want.

虽然只是输入 db 有效,但您会发现这只能以交互方式工作,如果您正在处理脚本,这可能不会给出您想要的结果。

回答by kat3ng

db.current

db.current

is a CLI command that will show you the database you are currently working in

是一个 CLI 命令,它将显示您当前正在使用的数据库