本文介绍了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:按键深度一级查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!