Mongo:按键深度一级查询 [英] Mongo: query by key one level deep

查看:74
本文介绍了Mongo:按键深度一级查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在Mongo查询中使用存在"之类的东西来基于ID返回此记录?

Is it possible to use something like 'exists' in a Mongo query to return this record based on an ID?

类似于选择"ids"包含键"123456"的地方?

  {
      "department": "Digging",
      "ids": {
        "123456": {
          "color": "blue"
        },
        "123457": {
          "color": "red"
        }
      }
    }

推荐答案

在搜索具有给定名称的字段时,$ exists是您需要的运算符(请参见

As you're searching for the existence of a field with a given name, $exists is the operator you need (see Advanced Queries).

例如像这样:

db.YourCollection.find({ "ids.123456" : {$exists: true}});

这篇关于Mongo:按键深度一级查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆