mongodb - 如何在嵌入文档中找到某个元素
问题描述
有没有什么办法只返回B级商店的字段?
我试过了:db.restaurant.find( {"Result.Grade" : "B"} )
但它会返回所有 B 级文档内容。
谢谢!!
解决方案
查询中的第一个参数find
用于过滤器。使用第二个参数并传递您要检索的字段。
db.restaurant.find(
{ "Result.Grade" : "B" }, //filter
{ "Name": 1, "Number": 1 } //projection
)
使用 mongodb 节点驱动使用.project()
游标方法
db.restaurant.find(
{ "Result.Grade" : "B" },
).project({ "Name": 1, "Number": 1 })
推荐阅读
- c# - 错误“无法加载 DLL 'vjsnativ':找不到指定的模块。” 将应用程序转换为 .NET 4.5 后
- java - 使用 IntelliJ UI Designer 时如何向 JComboBox 添加文本?
- java - Android 闪屏仅在某些设备上不断崩溃
- javascript - 解析名称以使字符大写和小写
- git - 在 Bitbucket 的这句话中,“源”和“您的更新”以及“目标”和“原始代码”之间有什么区别?
- excel - 匹配索引多个条件与大于问题
- java - 如何将百分比计算为指数级数?
- r - 如何使用 R、stingr 分割字符串
- machine-learning - 如何在使用更快的 rcnn/ssd 模型的同时加快对象检测
- python-3.x - 用 Python 从电视节目中提取星期几