【问题标题】:Return Every Certain Object in MongoDB返回 MongoDB 中的每个特定对象
【发布时间】:2018-01-09 00:35:23
【问题描述】:

如何编写返回 NoSQL 数据库中名为“address”的“每个”对象的查询? ...请注意它可能“嵌套”到其他对象。

我试过了

.find({
  'result.extractorData.data[0].group[0].address': {
    $exists: true
  }
});

但这不起作用,BTW 数据看起来像:

【问题讨论】:

    标签: mongodb mongoose nosql


    【解决方案1】:

    我认为对于嵌套数组,您最好使用 elemMatch 运算符

    查看类似问题herehere

    $elemMatch 运算符匹配包含数组字段且至少有一个元素匹配所有指定查询条件的文档。

    更多关于elemMatch

    还有另一种方法:

    .find({
      'result.extractorData.data.group.address': {
        $exists: true
      }
    });
    

    【讨论】:

    • 请问有什么例子吗?
    • @Microsmsm 你能列出你期望的输出示例吗?
    猜你喜欢
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    相关资源
    最近更新 更多