[英]how to find documents with all elements in the array in the document?
Hello I want to kno if is possible do a query for retrieve documents like this您好,我想知道是否可以查询这样的检索文档
Document文档
[
{
...
id:1
tags:['a', 'b', 'c']
...
},
{
...
id:2
tags:['b', 'c']
...
},
{
...
id:3
tags:['d']
...
}
]
findone({tags:{$all:['a', 'b']}})
-> 1 because a and b are only in doc 1 findone({tags:{$all:['b']}})
-> 1, 2 because b are only in doc 2 findone({tags:{$all:['a', 'b', 'd']}})
-> nothing, because any document has all tags inside array findone({tags:{$all:['d']}})
-> 3 because d are only in doc 3 findone({tags:{$all:['a', 'b']}})
-> 1 因为 a 和 b 只在 doc 1 findone({tags:{$all:['b']}})
-> 1, 2 因为findone({tags:{$all:['a', 'b', 'd']}})
只在文档findone({tags:{$all:['d']}})
-> 3 因为 d 只在文档 3 中
There are any way of do this query?有什么办法可以做这个查询?
Thanks谢谢
Query询问
$setDifference
$setDifference
aggregate(
[{"$match":
{"$expr":
{"$eq": [{"$setDifference": [["a", "b", "d"], "$tags"]}, []]}}}])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.