【问题标题】:$all type of operator for subdocuments in mongodbmongodb 中子文档的 $all 类型的运算符
【发布时间】:2015-10-14 09:50:48
【问题描述】:
Mongo Document
{"objects":
      { 1 : { Type: "A"},
      { 2 : { Type: "B"},
      { 3 : { Type: "C"},
      { 4 : { Type: "A"}
}
Desired result:
{ 
  1 : { Type : "A"},
  4 : { Type : "A"}
}

如何查询上面的Mongo Document得到上面的Desired result

【问题讨论】:

标签: mongodb mongoose mongodb-query mongodb-java nosql


【解决方案1】:

看起来我进入了标准的 MongoDB 新手陷阱,假设您可以从 MongoDB 的基本定义中获得任何 JSON 结构...... 看起来我们无法在 MongoDB 中查询以下文档结构

elements:{ 
 1 : { Type : "A"},
 4 : { Type : "B"}
}

这是我最终文档的样子:

elements: [
 {id: 1, Type: "A"},
 {id: 4, Type: "B"}
]

上述文档在MongoDb中可以这样查询:{"elements.id":1}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    • 2015-07-14
    • 1970-01-01
    • 2012-04-30
    相关资源
    最近更新 更多