我的条目是:
{
"_id": 722,
"mappings": [
{
"name": "sercan",
"test2": {
"code": "PI"
},
"codes": {
"individual": "false",
"servicetype": "APPART"
}
}
]
}
查询是:
db.myCollection.find({
"mappings.codes":
{ "individual" : "false",
"servicetype" : "APPART"
}
})
这将返回条目。但下面的查询不是:
db.myCollection.find({
"mappings.codes":
{
"servicetype" : "APPART" ,
"individual" : "false"
}
})
如您所见,只有代码顺序不同。我该如何处理这个问题?
提前致谢
最佳答案
在您的集合中,mappings
是一个数组。因此您需要使用$elemMatch
。试试这个:
db.myCollection.find({"mappings":{$elemMatch:{"test.codes":{"individual":"false","servicetype":"APPART"}}}}).pretty()
关于java - 查询 mongodb 的 map 类型字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25569128/