如何透過命令列連線到我的 MongoDB 表?


想要透過命令列連線到我的表,你需要使用 db 命令

db.yourCollectionName.find();

比方說我們有一個帶一些集合的“sample”資料庫。首先檢查當前資料庫

> use sample;
switched to db sample
> db;
Sample
Now we have reached the database sample. The database “sample” is having the following collections:
> show collections;

這將產生以下輸出

arraySizeErrorDemo
basicInformationDemo
copyThisCollectionToSampleDatabaseDemo
deleteAllRecordsDemo
deleteDocuments
deleteDocumentsDemo
deleteSomeInformation
documentWithAParticularFieldValueDemo
employee
findListOfIdsDemo
findSubstring
getAllRecordsFromSourceCollectionDemo
getElementWithMaxIdDemo
internalArraySizeDemo
largestDocumentDemo
makingStudentInformationClone
oppositeAddToSetDemo
prettyDemo
returnOnlyUniqueValuesDemo
selectWhereInDemo
sourceCollection
studentInformation
sumOfValueDemo
sumTwoFieldsDemo
truncateDemo
updateInformation
userInformation

以下是連線到表(即集合)的正確方式。你需要使用 db 命令。以下即該查詢

> db.userInformation.find();

這將產生以下輸出

{ "_id" : ObjectId("5c6a765964f3d70fcc9147f5"), "Name" : "John", "Age" : 30, "isStudent" : false, "Subjects" : [ "Introduction to java", "Introduction to MongoDB" ] }

更新於:2019 年 7 月 30 日

171 人次瀏覽

開啟你的 職業生涯

完成課程以獲得認證

開始
廣告
© . All rights reserved.