有一个.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/