Mongo 2.4.1,带有仲裁器的 2 成员副本集
我有一个我认为是返回不一致结果的非常简单的查询:
objects = db.collection.find({'field.id': my_id, 'field1': None, 'field2': 'value'})
我得到了 77 个对象,但集合中有 248 个对象与该查询匹配。我怀疑查询优化器正在做一些我没想到的事情。集合上的所有索引都不是稀疏的。
在上述查询的 .explain() 中,我得到
{cursor: 'BtreeCursor field.id_1', n: 283, nscanned: 77}
为什么nscanned小于283?
我还应该注意,虽然 77 长度的结果非常一致,但有时完全相同的查询会返回包含 238 个文档的结果。
编辑:完整的 .explain() 包括在下面。我注意到它看了BtreeCursor field.id_1
两遍。这正常吗?
{
"nYields": 0,
"nscannedAllPlans": 1011,
"allPlans": [
{
"cursor": "BtreeCursor field2_1",
"indexBounds": {
"field2": [
["moment", "moment"]
]
},
"nscannedObjects": 78,
"nscanned": 78,
"n": 0
},
{
"cursor": "BtreeCursor field.id_1_field3_1_field2_1_field1_1_created_at_-1",
"indexBounds": {
"field1": [
[null, null]
],
"created_at": [
[
{
"$maxElement": 1
},
{
"$minElement": 1
}
]
],
"field3": [
[
{
"$minElement": 1
},
{
"$maxElement": 1
}
]
],
"field2": [
["moment", "moment"]
],
"field.id": [
["oid-50eba1a2256b4738d0e5254d", "oid-50eba1a2256b4738d0e5254d"]
]
},
"nscannedObjects": 78,
"nscanned": 78,
"n": 78
},
{
"cursor": "BtreeCursor field1_1_field3_1_field4_1_field5_-1_field2_1_created_at_-1",
"indexBounds": {
"field4": [
[
{
"$minElement": 1
},
{
"$maxElement": 1
}
]
],
"field3": [
[
{
"$minElement": 1
},
{
"$maxElement": 1
}
]
],
"field1": [
[null, null]
],
"created_at": [
[
{
"$maxElement": 1
},
{
"$minElement": 1
}
]
],
"field5": [
[
{
"$maxElement": 1
},
{
"$minElement": 1
}
]
],
"field2": [
["moment", "moment"]
]
},
"nscannedObjects": 78,
"nscanned": 78,
"n": 0
},
{
"cursor": "BtreeCursor field1_1_field3_1_field4_1_field2_1_created_at_-1",
"indexBounds": {
"field1": [
[null, null]
],
"created_at": [
[
{
"$maxElement": 1
},
{
"$minElement": 1
}
]
],
"field4": [
[
{
"$minElement": 1
},
{
"$maxElement": 1
}
]
],
"field2": [
["moment", "moment"]
],
"field3": [
[
{
"$minElement": 1
},
{
"$maxElement": 1
}
]
]
},
"nscannedObjects": 78,
"nscanned": 78,
"n": 0
},
{
"cursor": "BtreeCursor field1_-1_created_at_-1",
"indexBounds": {
"field1": [
[null, null]
],
"created_at": [
[
{
"$maxElement": 1
},
{
"$minElement": 1
}
]
]
},
"nscannedObjects": 78,
"nscanned": 78,
"n": 0
},
{
"cursor": "BtreeCursor field.id_1_field3_1_field1_1_created_at_-1",
"indexBounds": {
"field1": [
[null, null]
],
"created_at": [
[
{
"$maxElement": 1
},
{
"$minElement": 1
}
]
],
"field3": [
[
{
"$minElement": 1
},
{
"$maxElement": 1
}
]
],
"field.id": [
["oid-50eba1a2256b4738d0e5254d", "oid-50eba1a2256b4738d0e5254d"]
]
},
"nscannedObjects": 78,
"nscanned": 78,
"n": 78
},
{
"cursor": "BtreeCursor field.id_1_field6_1_field2_1",
"indexBounds": {
"field6": [
[
{
"$minElement": 1
},
{
"$maxElement": 1
}
]
],
"field2": [
["moment", "moment"]
],
"field.id": [
["oid-50eba1a2256b4738d0e5254d", "oid-50eba1a2256b4738d0e5254d"]
]
},
"nscannedObjects": 76,
"nscanned": 77,
"n": 76
},
{
"cursor": "BtreeCursor field.id_1_field7_1",
"indexBounds": {
"field7": [
[
{
"$minElement": 1
},
{
"$maxElement": 1
}
]
],
"field.id": [
["oid-50eba1a2256b4738d0e5254d", "oid-50eba1a2256b4738d0e5254d"]
]
},
"nscannedObjects": 78,
"nscanned": 78,
"n": 71
},
{
"cursor": "BtreeCursor field.id_1",
"indexBounds": {
"field.id": [
["oid-50eba1a2256b4738d0e5254d", "oid-50eba1a2256b4738d0e5254d"]
]
},
"nscannedObjects": 78,
"nscanned": 78,
"n": 77
},
{
"cursor": "BtreeCursor field.id_1",
"indexBounds": {
"field.id": [
["oid-50eba1a2256b4738d0e5254d", "oid-50eba1a2256b4738d0e5254d"]
]
},
"nscannedObjects": 77,
"nscanned": 77,
"n": 72
},
{
"cursor": "BasicCursor",
"indexBounds": {},
"nscannedObjects": 77,
"nscanned": 77,
"n": 0
}
],
"millis": 14,
"nChunkSkips": 0,
"server": "c3:10003",
"n": 283,
"cursor": "BtreeCursor field.id_1",
"oldPlan": {
"cursor": "BtreeCursor field.id_1",
"indexBounds": {
"field.id": [
["oid-50eba1a2256b4738d0e5254d", "oid-50eba1a2256b4738d0e5254d"]
]
}
},
"scanAndOrder": false,
"indexBounds": {
"field.id": [
["oid-50eba1a2256b4738d0e5254d", "oid-50eba1a2256b4738d0e5254d"]
]
},
"nscannedObjectsAllPlans": 1000,
"isMultiKey": false,
"indexOnly": false,
"nscanned": 77,
"nscannedObjects": 77
}