mongodb:数组中的值查询文档
我有这些文档:
{"_id" : 1, "actors" : [{"matricule" : "AVB", "name":"XXX"}, {"matricule" : "AVB", "name":"YYY"}]}
{"_id" : 2, "actors" : [{"matricule" : "PMH", "name":"FFF"}, {"matricule" : "BNG", "name":"HHH"}]}
我只想获取第一个文档,因为它是相同的矩阵,但名称不同。
我使用此查询:
{
$expr:{$eq:["$actors.0.matricule", "$actors.1.matricule"]}
}
但是它不起作用,我没有任何结果。 你知道为什么吗?
I have those documents :
{"_id" : 1, "actors" : [{"matricule" : "AVB", "name":"XXX"}, {"matricule" : "AVB", "name":"YYY"}]}
{"_id" : 2, "actors" : [{"matricule" : "PMH", "name":"FFF"}, {"matricule" : "BNG", "name":"HHH"}]}
I would like to get only the first document because it's the same matricule but a different name.
I use this query :
{
$expr:{$eq:["$actors.0.matricule", "$actors.1.matricule"]}
}
But it doesn't work, I don't have any results.
Do you know why ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
$ arrayElemat
这是 mongo Playgrounger 供您参考。
Try to use
$arrayElemAt
Here is the Mongo playground for your reference.
查询
*如果您在演员阵列中有一个或多个成员
Playmongo
Query
*can work if you have one or many members inside the actors array
Playmongo