json - MongoDB find()。count()-SyntaxError : missing : after property id (shell):1

标签 json mongodb count find syntax-error

有一个.json数据提供的推文集合。

希望计算 session 中的删除请求:

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"}不是有效的对象。

我认为您想获取具有删除键的文档数。为此,您必须将$exists运算符与true值一起使用。

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

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

documentation:

$exists selects the documents that contain the field if is true. If is false, the query only returns the documents that do not contain the field. Documents that contain the field but has the value null are not returned.

关于json - MongoDB find()。count()-SyntaxError : missing : after property id (shell):1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16637636/

相关文章:

python - 使用字典计算每个字母在单词中出现的次数

计算 C 中整数的个数

javascript - 解析 JSON 文件 - 子数组或方括号内的 node.js

node.js - 用 Mongoose 和日期查询

mongodb - 构建mongo容器并导入数据

php - 根据出现次数显示数据 MYSQL

java - Spring RestTemplate boolean 值反序列化

json - 如何定义 JSON 架构中的属性序列?

javascript - 访问 JSON 中的元素(Node js)

mongodb - 如何从子集合中删除列