在 shell 指令碼中使用 MongoDB 中的結果?
我們首先建立一個帶有文件的集合 −
>db.useResultDemo.insertOne({"StudentFirstName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5cda70f5b50a6c6dd317adcd") }
在 find() 方法的幫助下顯示來自集合的所有文件 −
> db.useResultDemo.find();
以下為輸出 −
{ "_id" : ObjectId("5cda70f5b50a6c6dd317adcd"), "StudentFirstName" : "Robert" }
以下是使用 var 關鍵字在 shell 指令碼中使用 MongoDB 結果的查詢 −
> var studentName=db.useResultDemo.findOne({},{_id:0}); > studentName
以下為輸出 −
{ "StudentFirstName" : "Robert" }
廣告