显示 MongoDB 中的数据库
要在 MongoDB 中显示数据库的数量,您需要至少在一个数据库中创建一份文档。
比如说,您创建了一个数据库,但没有在其中添加任何文档。那么在数据库列表中,该特定数据库将不可见。
以下是创建数据库的查询 −
> use app; switched to db app
以下是显示所有数据库的查询 −
> show dbs;
这将产生以下输出。因为我们还没有添加至少一份文档,新的数据库 “app” 将不可见 −
admin 0.002GB business 0.000GB config 0.000GB local 0.000GB main 0.000GB my 0.001GB sample 0.003GB sampleDemo 0.000GB studentSearch 0.000GB test 0.022GB university 0.000GB web 0.001GB webcustomertracker 0.000GB
让我们首先在 “app” 数据库中使用文档创建一个集合 −
> db.demo.insert({"StudentName":"Chris"});
WriteResult({ "nInserted" : 1 })以下是使用 find() 方法从集合中显示所有文档的查询 −
> db.demo.find();
这将产生以下输出 −
{ "_id" : ObjectId("5e07250e25ddae1f53b62204"), "StudentName" : "Chris" }以下是对 MongoDB 中所有数据库进行显示的查询 −
> show dbs;
这将产生以下输出。现在 “app” 数据库将显示在数据库列表中 −
admin 0.002GB app 0.000GB business 0.000GB config 0.000GB local 0.000GB main 0.000GB my 0.001GB sample 0.003GB sampleDemo 0.000GB studentSearch 0.000GB test 0.022GB university 0.000GB web 0.001GB webcustomertracker 0.000GB
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP