[英]Find which field's size is greater than 20000 in a collection (mongodb)
[英]How to find the document in mongodb where array size is greater than 1
我想找到所有存在且数组大小大于 1 的文档
我的 MongoDB 集合看起来像
{
"_id" : ObjectId("5eaaeedd00101108e1123452"),
"type" : ["admin","teacher","student"]
}
{
"_id" : ObjectId("5eaaeedd00101108e1123453"),
"type" : ["student"],
}
我如何找到超过 1 种类型的文档
你可以做这样的事情。 这是工作版本> 4.2
db.collection.find({
$expr: {
$gt: [
{
$size: "$type"
},
1
]
}
})
如果您使用较少,则可以执行以下操作
db.collection.find({
type: {
$gt: {
$size: 1
}
}
})
此问题的唯一有效解决方案如下:
db.collection.find({
$expr: {
$gt: [
{
$size: "$arrayfield"
},
1
]
}
})
所有其他解决方案都不起作用。 试过了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.