簡體   English   中英

MongoDB find()。count()-語法錯誤:缺少:在屬性ID(shell)之后:1

[英]MongoDB find().count() - SyntaxError: missing : after property id (shell):1

有一個.json數據提供的推文集合。

希望計算會話中的刪除請求:

db.tweets.find({"delete"}).count()

而且此語法是不正確的,因為SyntaxError: missing : after property id (shell):1

有更多的find()count()操作要執行,但是錯誤是一致的。

這就是Delete-Request的樣子(其中“ ”是一系列字母和/或數字)

{
    "_id" : ObjectId("…"),
    "delete" : {
        "status" : {
            "id" : NumberLong("…"),
            "user_id" : …,
            "id_str" : "…",
            "user_id_str" : "…"
        }
    }
}

find()函數中,您必須傳遞一個對象。 您錯過了鍵/值,因為{"delete"}不是有效的對象。

我認為您想獲取具有刪除鍵的文檔數。 為此,您必須使用具有true值的$exists運算符。

db.tweets.find({ "delete": { $exists: true } }).count();

或直接

db.tweets.count({ "delete": { $exists: true } });

文檔

如果為true,則$ exists選擇包含該字段的文檔。 如果為false,則查詢僅返回不包含該字段的文檔。 不返回包含該字段但值為null的文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM