在MongoDB中使用$ all使用多个$ elemMatch表达式来匹配数组值?

编程入门 行业动态 更新时间:2024-10-06 22:23:36
本文介绍了在MongoDB中使用$ all使用多个$ elemMatch表达式来匹配数组值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在问题我找到了一种使用$ elemMatch搜索数组值的有趣解决方案.

In the answer to a question I found a interesting solution for searching array values using $elemMatch.

如果我们的收藏夹中包含以下文档:

If we have the following documents in our collection:

{ foo : [ { bar : "xy", baz : 1 }, { bar : "a", baz : 10 } ] }, { foo : [ { bar : "xy", baz : 5 }, { bar : "b", baz : 50 } ] }

以下查询将仅匹配第一个文档:

The following query will match only the first document:

db.test.find({ foo : { "$all" : [ { "$elemMatch" : { bar : "xy", baz : 1} }, { "$elemMatch" : { bar : "a", baz : 10 } } ] } });

我用其他几个示例进行了尝试,它确实有效.但是 $ all 运算符的官方文档没有谈谈结合这两个查询的任何事情.

I tried it with several other examples and it really works. But the official documentation for $all operator doesn't say anything about combining these two queries.

这是预期的行为还是错误?还是这只是文档未涵盖此用例的问题?

Is this the intended behavior or a bug? Or is this just a problem that the documentation does not cover this use case?

推荐答案

这是预期的行为.文档没有涵盖此用例,我们正在努力使其变得更好.但是,很难记录每个可能的查询组合.

This is the intended behavior. The documentation doesn't cover this use case and we are working on it to make it better. Its difficult, however, to document every possible query combination.

更多推荐

在MongoDB中使用$ all使用多个$ elemMatch表达式来匹配数组值?

本文发布于:2023-10-19 01:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1506023.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   数组   表达式   MongoDB   elemMatch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!