顯示 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
廣告