1
我对查询的集合与:为什么子文档查询的顺序会影响MongoDB中的结果?
> db.things.find({ "entity":{entityType:"Location", id: "26802"}})
返回0的结果,但如果我与entityType
和id
模式查询:
> db.things.find({ "entity":{id: "26802", entityType:"Location"}})
3返回结果。
3结果也返回两种:
> db.things.find({ "entity.id": "26802", "entity.entityType":"Location"})
> db.things.find({ "entity.entityType":"Location", "entity.id": "26802"})
这是为什么?
上有entity
{
"v" : 1,
"key" : {
"entity" : 1
},
"name" : "entity_1",
"ns" : "db_name.things"
}
刚刚发现它的文档,而不是一个错误。 https://docs.mongodb.org/manual/core/index-single/#indexes-on-subdocuments,但我仍然不明白为什么这将是有用/不令人惊讶的行为。 – lyjackal