因此,我们在mongo的数组中列出了2000到100,000个项目。我想把它用来使用。
说明显示它正在使用索引并且只扫描1个文档。但运行需要1.5 - 3秒。我假设因为大阵列。是否还有加快速度的速度?我觉得被困在那里。
这是查询
db.monitors.find({userId: "xxxx"})
这是解释
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "xx.monitors",
"indexFilterSet" : false,
"parsedQuery" : {
"userId" : {
"$eq" : "xxx"
}
},
"winningPlan" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"userId" : 1
},
"indexName" : "user",
"isMultiKey" : false,
"direction" : "forward",
"indexBounds" : {
"userId" : [
"[\"xxx\", \"xxx\"]"
]
}
}
},
"rejectedPlans" : []
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 1,
"executionTimeMillis" : 0,
"totalKeysExamined" : 1,
"totalDocsExamined" : 1,
"executionStages" : {
"stage" : "FETCH",
"nReturned" : 1,
"executionTimeMillisEstimate" : 0,
"works" : 2,
"advanced" : 1,
"needTime" : 0,
"needFetch" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"docsExamined" : 1,
"alreadyHasObj" : 0,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 1,
"executionTimeMillisEstimate" : 0,
"works" : 2,
"advanced" : 1,
"needTime" : 0,
"needFetch" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"keyPattern" : {
"userId" : 1
},
"indexName" : "user",
"isMultiKey" : false,
"direction" : "forward",
"indexBounds" : {
"userId" : [
"[\"xxx\", \"xxx\"]"
]
},
"keysExamined" : 1,
"dupsTested" : 0,
"dupsDropped" : 0,
"seenInvalidated" : 0,
"matchTested" : 0
}
},
"allPlansExecution" : []
},
"serverInfo" : {
"host" : "xx",
"port" : 27017,
"version" : "3.0.4",
"gitVersion" : "0481c958daeb2969800511e7475dc66986fa9ed5"
}
}