[英]MongoDB find().count() - SyntaxError: missing : after property id (shell):1
Have a .json data-supplied collection of tweets.. 有一个.json数据提供的推文集合。
Looking to count Delete-Requests in Sessions: 希望计算会话中的删除请求:
db.tweets.find({"delete"}).count()
And this syntax is incorrect because SyntaxError: missing : after property id (shell):1
而且此语法是不正确的,因为
SyntaxError: missing : after property id (shell):1
Have more find()
and count()
operations to perform, but the error is consistent. 有更多的
find()
和count()
操作要执行,但是错误是一致的。
This is what a Delete-Request looks like (where " … " is either a series of letters and/or numbers) : 这就是Delete-Request的样子(其中“ … ”是一系列字母和/或数字) :
{
"_id" : ObjectId("…"),
"delete" : {
"status" : {
"id" : NumberLong("…"),
"user_id" : …,
"id_str" : "…",
"user_id_str" : "…"
}
}
}
In the find()
function you have to pass an object. 在
find()
函数中,您必须传递一个对象。 You missed the key/value, because {"delete"}
isn't a valid object. 您错过了键/值,因为
{"delete"}
不是有效的对象。
I think that you want to get the number of documents that have the delete key. 我认为您想获取具有删除键的文档数。 For this you have to use
$exists
operator with true
value. 为此,您必须使用具有
true
值的$exists
运算符。
db.tweets.find({ "delete": { $exists: true } }).count();
or directly 或直接
db.tweets.count({ "delete": { $exists: true } });
From documentation : 从文档 :
$exists selects the documents that contain the field if is true.
如果为true,则$ exists选择包含该字段的文档。 If is false, the query only returns the documents that do not contain the field.
如果为false,则查询仅返回不包含该字段的文档。 Documents that contain the field but has the value null are not returned.
不返回包含该字段但值为null的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.