本文介绍了在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":"www.something" } }如何获取在元数据中具有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中查找包含给定子字段的所有记录
发布评论