我在一個集合中運行一個MongoDB 3.1服務器,裏面大概有160萬個文檔。文檔看起來是這樣的:MongoDB在一個龐大的數據集上返回空結果
{
"_id": { "$oid" : "123456789" },
"lastChange": "2015-02-09 13:22:27",
"startDate": "2015-02-09",
"receiptNumber" : 296,
"itemReceiptPositions": [
{
"itemId": 900064,
"listPrice": 8.99
}
]
}
我已經創建的「itemReceiptPositions.itemId」和「receiptNumber」索引:
{
"v" : 1,
"key" : {
"receiptNumber" : 1
},
"name" : "receiptNumber_1",
"ns" : "someDatabase.someCollection"
},
{
"v" : 1,
"key" : {
"itemReceiptPositions.itemId" : 1
},
"name" : "itemReceiptPositions.itemId_1",
"ns" : "someDatabase.someCollection"
}
當我搜索通過itemReceiptPositions.itemId鍵這個特定的文件, MongoDB找不到文檔:
> db.someCollection.find({ "itemReceiptPositions.itemId" : 900064 }).count()
0
但是,每當我搜索關鍵字「receiptNumber」,文檔被發現!即使查詢
> db.someCollection.find({ "itemReceiptPositions.itemId" : { "$gt" : 0 }}).count()
返回零結果。怎麼會這樣?
這裏是.explain()兩個查詢的輸出:
> db.someCollection.find({ "itemReceiptPositions.itemId" : 900064 }).explain()
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "someDatabase.someCollection",
"indexFilterSet" : false,
"parsedQuery" : {
"itemReceiptPositions.itemId" : {
"$eq" : 900064
}
},
"winningPlan" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"itemReceiptPositions.itemId" : 1
},
"indexName" : "itemReceiptPositions.itemId_1",
"isMultiKey" : true,
"direction" : "forward",
"indexBounds" : {
"itemReceiptPositions.itemId" : [
"[900064.0, 900064.0]"
]
}
}
},
"rejectedPlans" : [ ]
},
"serverInfo" : {
"host" : "someHost",
"port" : 1234,
"version" : "3.1.0-pre-",
"gitVersion" : "bbd95ca6a8b538b4cffece0b9d9c3ed811a455a7"
},
"ok" : 1
}
和
> db.someCollection.find({ "receiptNumber" : 296 }).explain()
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "someDatabase.someCollection",
"indexFilterSet" : false,
"parsedQuery" : {
"receiptNumber" : {
"$eq" : 296
}
},
"winningPlan" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"receiptNumber" : 1
},
"indexName" : "receiptNumber_1",
"isMultiKey" : false,
"direction" : "forward",
"indexBounds" : {
"receiptNumber" : [
"[296.0, 296.0]"
]
}
}
},
"rejectedPlans" : [ ]
},
"serverInfo" : {
"host" : "someHost",
"port" : 1234,
"version" : "3.1.0-pre-",
"gitVersion" : "bbd95ca6a8b538b4cffece0b9d9c3ed811a455a7"
},
"ok" : 1
}
你怎麼辦?你確定嗎? – Sammaye 2015-03-02 14:30:35
點符號工作得很好 – lascort 2015-03-02 14:32:50
@ZeMoon:謝謝,但這並沒有解決它:(它仍然沒有找到任何文件 – soner 2015-03-02 14:39:13