How do I search for an object by its ObjectId in the mongo console?

問題:

I've found this question answered for C# and Perl, but not in the native interface.我發現這個問題在 C# 和 Perl 中得到了回答,但在本機界面中沒有。 I thought this would work:我認爲這會奏效:

db.theColl.find( { _id: ObjectId("4ecbe7f9e8c1c9092c000027") } )

The query returned no results.查詢未返回任何結果。 I found the 4ecbe7f9e8c1c9092c000027 by doing db.theColl.find() and grabbing an ObjectId.我通過執行db.theColl.find()並獲取 ObjectId 找到了 4ecbe7f9e8c1c9092c000027。 There are several thousand objects in that collection.該集合中有數千個對象。

I've read all the pages that I could find on the mongodb.org website and didn't find it.我已經閱讀了可以在 mongodb.org 網站上找到的所有頁面,但沒有找到。 Is this just a strange thing to do?這只是一件奇怪的事情嗎? It seems pretty normal to me.對我來說似乎很正常。


解決方案:

參考一: https://en.stackoom.com/question/YXmY
參考二: https://stackoom.com/question/YXmY
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章