您好我有一个mongo集合EntityRecords,其中包含State和EntityReferenceId列的索引。 Collection的结构就是这样。
{
"_id" : ObjectId("584a7119a0297fc8becafe40"),
"EntityReferenceId" : BinData(3,"+DVL5D2m6UGgs8p/RHEvfw=="),
"ReferenceId" : 1135517158,
"State" : 3,
"ResolveStrategyForEntireRow" : 0,
"Comments" : null,
"LastUpdatedBy" : null,
"ChangeLog" : null,
"Fields" : [
{
"Name" : "TravelWorkID",
"Value" : 1068501,
"DisplayValue" : "1068501"
}
],
"Changes" : [
{
"FieldName" : "InspectorType",
"DisplaySourceValue" : "O",
"DisplayLocalValue" : "",
"DisplayLastImportedValue" : "",
"SourceValue" : "O",
"LocalValue" : null,
"LastImportedValue" : null,
"Value" : null,
"ResolveStrategy" : 3
}
]
}
我想用EntityReferenceId获取所有记录并将其作为过滤器状态。查询返回138100条记录,但获取所有数据需要6分钟以上(注意报告目的,我需要处理我的C#类中返回的所有记录)。我使用过这个查询。
db.getCollection('EntityRecords').
find({'EntityReferenceId':UUID("F8354BE43DA6E941A0B3CA7F44712F7F" ) ,
$or: [ { State: 3 }, { State: 4 },
{ State: 7 }, { State: 5 }, { State: 6 } ] }).
explain('executionStats') ;
问题在于我的C#代码需要6分钟才能获得所有记录,请帮助我如何使其更快/并行是可能的。
执行统计数据如下。
db.getCollection('EntityRecords').
find({'EntityReferenceId':UUID("F8354BE43DA6E941A0B3CA7F44712F7F" ) ,
$or: [ { State: 3 }, { State: 4 },
{ State: 7 },
{ State: 5 }, { State: 6 } ] }).explain('executionStats')
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "SIR.EntityRecords",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [
{
"$or" : [
{
"State" : {
"$eq" : 3
}
},
{
"State" : {
"$eq" : 4
}
},
{
"State" : {
"$eq" : 7
}
},
{
"State" : {
"$eq" : 5
}
},
{
"State" : {
"$eq" : 6
}
}
]
},
{
"EntityReferenceId" : {
"$eq" : BinData(3,"+DVL5D2m6UGgs8p/RHEvfw==")
}
}
]
},
"winningPlan" : {
"stage" : "KEEP_MUTATIONS",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"$or" : [
{
"State" : {
"$eq" : 3
}
},
{
"State" : {
"$eq" : 4
}
},
{
"State" : {
"$eq" : 7
}
},
{
"State" : {
"$eq" : 5
}
},
{
"State" : {
"$eq" : 6
}
}
]
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"EntityReferenceId" : 1
},
"indexName" : "EntityReferenceId_1",
"isMultiKey" : false,
"direction" : "forward",
"indexBounds" : {
"EntityReferenceId" : [
"[BinData(3, F8354BE43DA6E941A0B3CA7F44712F7F), BinData(3, F8354BE43DA6E941A0B3CA7F44712F7F)]"
]
}
}
}
},
"rejectedPlans" : [
{
"stage" : "KEEP_MUTATIONS",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"EntityReferenceId" : {
"$eq" : BinData(3,"+DVL5D2m6UGgs8p/RHEvfw==")
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"State" : 1
},
"indexName" : "State_1",
"isMultiKey" : false,
"direction" : "forward",
"indexBounds" : {
"State" : [
"[3.0, 3.0]",
"[4.0, 4.0]",
"[5.0, 5.0]",
"[6.0, 6.0]",
"[7.0, 7.0]"
]
}
}
}
}
]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 138100,
"executionTimeMillis" : 192,
"totalKeysExamined" : 138100,
"totalDocsExamined" : 138100,
"executionStages" : {
"stage" : "KEEP_MUTATIONS",
"nReturned" : 138100,
"executionTimeMillisEstimate" : 150,
"works" : 138101,
"advanced" : 138100,
"needTime" : 0,
"needFetch" : 0,
"saveState" : 1080,
"restoreState" : 1080,
"isEOF" : 1,
"invalidates" : 0,
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"$or" : [
{
"State" : {
"$eq" : 3
}
},
{
"State" : {
"$eq" : 4
}
},
{
"State" : {
"$eq" : 7
}
},
{
"State" : {
"$eq" : 5
}
},
{
"State" : {
"$eq" : 6
}
}
]
},
"nReturned" : 138100,
"executionTimeMillisEstimate" : 150,
"works" : 138101,
"advanced" : 138100,
"needTime" : 0,
"needFetch" : 0,
"saveState" : 1080,
"restoreState" : 1080,
"isEOF" : 1,
"invalidates" : 0,
"docsExamined" : 138100,
"alreadyHasObj" : 0,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 138100,
"executionTimeMillisEstimate" : 60,
"works" : 138101,
"advanced" : 138100,
"needTime" : 0,
"needFetch" : 0,
"saveState" : 1080,
"restoreState" : 1080,
"isEOF" : 1,
"invalidates" : 0,
"keyPattern" : {
"EntityReferenceId" : 1
},
"indexName" : "EntityReferenceId_1",
"isMultiKey" : false,
"direction" : "forward",
"indexBounds" : {
"EntityReferenceId" : [
"[BinData(3, F8354BE43DA6E941A0B3CA7F44712F7F), BinData(3, F8354BE43DA6E941A0B3CA7F44712F7F)]"
]
},
"keysExamined" : 138100,
"dupsTested" : 0,
"dupsDropped" : 0,
"seenInvalidated" : 0,
"matchTested" : 0
}
}
}
},
"serverInfo" : {
"host" : "DTA641-045",
"port" : 27017,
"version" : "3.0.4",
"gitVersion" : "0481c958daeb2969800511e7475dc66986fa9ed5"
},
"ok" : 1
}