最近我们将MongoDB 2.6(MMAPV1)升级到3.2(MMAPV1),子文档中的升级索引无效。我用查询解释在两个数据库上做了一个小概念验证。
在MongoDB 3.2中,不考虑子文档索引,有人可以建议修复此问题吗?
这是示例mongo文档,
{
"_id" : ObjectId("58bff13e4e6904293cc206b4"),
"Value" : NumberLong(158),
"OVGuid" : NumberLong(0),
"Name" : "User 08/03/2017 03.55.42.782",
"CreateDate" : ISODate("2017-03-08T11:55:42.783Z"),
"RoleLst" : [
{
"_id" : NumberLong(146),
"Name" : "Role1"
},
{
"_id" : NumberLong(108),
"Name" : "Role2"
},
{
"_id" : NumberLong(29),
"Name" : "Role3"
}
]
}
在Mongo DB 2.6中,我在" RoleLst._id"(db.User.createIndex({" RoleLst._id":1}))中插入了近100,000个数据并启用了索引和3.2。
然后我尝试了查询解释
db.User.find({" RoleLst":{" $ elemMatch":{" _id":NumberLong(200)}}})。解释()
这是我从3.2得到的结果
Explain for sub-document query
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "SubDocmentIndexChecking.User",
"indexFilterSet" : false,
"parsedQuery" : {
"RoleLst" : {
"$elemMatch" : {
"_id" : {
"$eq" : NumberLong(200)
}
}
}
},
"winningPlan" : {
"stage" : "COLLSCAN",
"filter" : {
"RoleLst" : {
"$elemMatch" : {
"_id" : {
"$eq" : NumberLong(200)
}
}
}
},
"direction" : "forward"
},
"rejectedPlans" : []
},
"serverInfo" : {
"host" : "******",
"port" : ******,
"version" : "3.2.10",
"gitVersion" : "79d9b3ab5ce20f51c272b4411202710a082d0317"
},
"ok" : 1.0
}
这是我从2.6
获得的结果Explain for sub-document query
{
"cursor" : "BtreeCursor RoleLst._id_1",
"isMultiKey" : true,
"n" : 0,
"nscannedObjects" : 0,
"nscanned" : 0,
"nscannedObjectsAllPlans" : 0,
"nscannedAllPlans" : 0,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
"RoleLst._id" : [
[
NumberLong(200),
NumberLong(200)
]
]
},
"server" : "***********",
"filterSet" : false,
"stats" : {
"type" : "KEEP_MUTATIONS",
"works" : 2,
"yields" : 0,
"unyields" : 0,
"invalidates" : 0,
"advanced" : 0,
"needTime" : 1,
"needFetch" : 0,
"isEOF" : 1,
"children" : [
{
"type" : "FETCH",
"works" : 2,
"yields" : 0,
"unyields" : 0,
"invalidates" : 0,
"advanced" : 0,
"needTime" : 1,
"needFetch" : 0,
"isEOF" : 1,
"alreadyHasObj" : 0,
"forcedFetches" : 0,
"matchTested" : 0,
"children" : [
{
"type" : "IXSCAN",
"works" : 1,
"yields" : 0,
"unyields" : 0,
"invalidates" : 0,
"advanced" : 0,
"needTime" : 1,
"needFetch" : 0,
"isEOF" : 1,
"keyPattern" : "{ RoleLst._id: 1.0 }",
"isMultiKey" : 1,
"boundsVerbose" : "field #0['RoleLst._id']: [200, 200]",
"yieldMovedCursor" : 0,
"dupsTested" : 0,
"dupsDropped" : 0,
"seenInvalidated" : 0,
"matchTested" : 0,
"keysExamined" : 0,
"children" : []
}
]
}
]
}
}