내 "_id"필드에 포함 된 문서가 포함되어 있고 포함 된 문서의 필드에 대해 비교 연산자 ($ gte/$ lte)를 사용하는 경우가 있습니다.임베디드 문서의 MongoDB 인덱스 범위
"_id"
db.DocumentWithCompoundKeyCollection.find() 이제
{ "_id" : { "Part1" : 1, "Part2" : 1 }, "SomeValue" : BinData(3,"B8+yWvTV4kS/u3e6Cv8Kcw==") }
{ "_id" : { "Part1" : 1, "Part2" : 2 }, "SomeValue" : BinData(3,"eLS1ONAoGUawW+v+vQdFDQ==") }
{ "_id" : { "Part1" : 1, "Part2" : 3 }, "SomeValue" : BinData(3,"m7WsIyInIEmsgWUMcsJPAw==") }
{ "_id" : { "Part1" : 2, "Part2" : 4 }, "SomeValue" : BinData(3,"z7/2j0g4AUikqS5K1TzZig==") }
{ "_id" : { "Part1" : 2, "Part2" : 5 }, "SomeValue" : BinData(3,"WudfqGYE8U+YwWe3Q0qL1w==") }
{ "_id" : { "Part1" : 2, "Part2" : 6 }, "SomeValue" : BinData(3,"B60SpSmXdUGn6AJDu1JIzg==") }
{ "_id" : { "Part1" : 3, "Part2" : 7 }, "SomeValue" : BinData(3,"xVmhanYiV0+dOdTx7PAZkw==") }
{ "_id" : { "Part1" : 3, "Part2" : 8 }, "SomeValue" : BinData(3,"5NNdVzErt0qephmCMRR1nQ==") }
{ "_id" : { "Part1" : 3, "Part2" : 9 }, "SomeValue" : BinData(3,"mhTiJoHGKkCPUeglCfLUoQ==") }
나는 모든 문서를 반환하는 쿼리를 실행 등의 임베디드 문서 9 문서를 가지고 아래의 수집, 각을 고려 "Part1"> = 1 및 "Part1"< = 3 인 경우 모든 9 개의 문서를 가져야하지만 문고는 6 개의 문서 만 반환합니다 ({ "Part1": 3 ...}이있는 모든 문서는 건너 뜁니다)
db.DocumentWithCompoundKeyCollection.find ({ "_id"{ "$ GTE"{ "제 1 부"1}, "$의 LTE"{ "제 1 부": 3}}})
{ "_id" : { "Part1" : 1, "Part2" : 1 }, "SomeValue" : BinData(3,"B8+yWvTV4kS/u3e6Cv8Kcw==") }
{ "_id" : { "Part1" : 1, "Part2" : 2 }, "SomeValue" : BinData(3,"eLS1ONAoGUawW+v+vQdFDQ==") }
{ "_id" : { "Part1" : 1, "Part2" : 3 }, "SomeValue" : BinData(3,"m7WsIyInIEmsgWUMcsJPAw==") }
{ "_id" : { "Part1" : 2, "Part2" : 4 }, "SomeValue" : BinData(3,"z7/2j0g4AUikqS5K1TzZig==") }
{ "_id" : { "Part1" : 2, "Part2" : 5 }, "SomeValue" : BinData(3,"WudfqGYE8U+YwWe3Q0qL1w==") }
{ "_id" : { "Part1" : 2, "Part2" : 6 }, "SomeValue" : BinData(3,"B60SpSmXdUGn6AJDu1JIzg==") }
.explain()을 추가하면 올바른 indexBounds가 예상대로 반환되므로 마지막 3 개의 문서가 반환되지 않는 이유는 무엇입니까?
색인 계획
"winningPlan" : {
"stage" : "FETCH",
"filter" : {
"$and" : [
{
"_id" : {
"$lte" : {
"Part1" : 3
}
}
},
{
"_id" : {
"$gte" : {
"Part1" : 1
}
}
}
]
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_id" : 1
},
"indexName" : "_id_",
"isMultiKey" : false,
"isUnique" : true,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 1,
"direction" : "forward",
"indexBounds" : {
"_id" : [
"[{ Part1: 1.0 }, { Part1: 3.0 }]"
]
}
}
},
덕분에 andresk하지만 불행히도 내 코드가 의존하는 다른 모듈을 사용하고 찾을 수 있습니다
이 스키마 및 쿼리 패턴 (그래서 그것을 변경할 수 없습니다). –