background:
MongoDB collection count : 3600004条
例如:
{
"_id" : ObjectId("5d3a7c75ffab2c23488e6974"),
"name" : "myxk",
"phone" : NumberLong(465200810),
"age" : 55,
"desc" : "chfunikogecpgyeltmnvtclznjgxkytqlzdvqioetaradlacgidjuomnloxtwfqfmrkypvnibngnudmlreyqprqzcavvjbbhhxyb",
"birth" : ISODate("1992-05-22T16:26:22.119Z"),
"hubbies" : [
{
"sceneName" : "zrja",
"audioType" : "mp3",
"prodId" : NumberLong(93648624)
},
{
"sceneName" : "rcta",
"audioType" : "mp3",
"prodId" : NumberLong(76716913)
},
{
"sceneName" : "rwys",
"audioType" : "mp3",
"prodId" : NumberLong(87650253)
}
]
}
查询db.getCollection('test_collection').find({"hubbies":{$elemMatch:{"prodId":83017829}}}).sort({"_id":-1});
没有多键索引:use time 7.44 sec.(6-7s)
建立多键索引

在包含3600004条数据的MongoDB集合中,针对查询`{"hubbies": {$elemMatch: {"prodId": 83017829}}}`,未使用多键索引时执行时间为7.44秒。创建了多键索引`{"hubbies.prodId": 1, "hubbies.sceneName": 1}`后,查询时间降低到0.001秒,显著提高了查询性能。了解更多关于MongoDB Multikey Indexes的知识,可以参考官方文档。"
89458375,8376024,C语言程序设计:实例解析,"['C语言基础', '程序设计', '输入输出', '数据类型']
最低0.47元/天 解锁文章
1940

被折叠的 条评论
为什么被折叠?



