在 mongodb 中查找包含给定子字段的所有记录 [英] Finding all records containing a given subfield in mongodb

查看:14
本文介绍了在 mongodb 中查找包含给定子字段的所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 mongodb 中,我可以使用以下查询在数据库 db 的集合中找到包含特定字段的所有记录

In mongodb, i can find all those records in a collection in database db that contain a particular field using the following query

var doc = db.collection_name.find({field_name:{$exists:true}})

现在考虑以下文档:

{
  "somefield":"someval",
  "metadata": {"id":"someval",
               "client_url":"http://www.something.com"

              }
}

获取元数据中具有 id 字段的所有记录的查询是什么?

What would be the query for getting all records having the id field in metadata ?

请帮忙.谢谢你

推荐答案

您可以使用点符号来引用子文档字段

You can use dot notation to reference sub-document fields

var doc = db.collection_name.find({"metadata.id":{$exists:true}})

这篇关于在 mongodb 中查找包含给定子字段的所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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