我在 mongodb 中有一个示例文档(而且我还是 mongodb 的新手)
{
"ID": 0,
"Facet1":"Value1",
"Facet2":[
{
"Facet2Obj1":{
"Obj1Facet1":"Value11",
"Obj2Facet1":"Value21",
"Obj3Facet1":"Value31"
}
},
{
"Facet2Obj2":{
"Obj1Facet2":"Value12",
"Obj2Facet2":"Value22",
"Obj3Facet2":"Value32"
}
},
{
"Facet2Obj3":{
"Obj1Facet3":"Value13",
"Obj2Facet3":"Value23",
"Obj3Facet3":"Value33"
}
}
],
"Facet3":"Value3"
"Facet4":{
"Facet4Obj1":{
"Obj1Facet1":"Value4111"
}
}
}
Mapreduce 有点复杂,它提供以下输出(对于 30,000 个文档):
{
"_id" : "Facet1",
"value" : [
{
"value" : "Value1",
"count" : 30000,
"ID" : [
0,
1,
.
.
.
]
}
]
}
{
"_id" : "ID",
"value" : [
{
"value" : 0,
"count" : 1,
"ID" : [
0
]
},
{
"value" : 1,
"count" : 1,
"ID" : [
1
]
},
.
.
.
]
}
{
"_id" : "Facet2",
"value" : [
{
"value" : "Facet2Obj1",
"count" : 30000,
"ID" : [
0,
1,
.
.
.
]
},
{
"value" : "Facet2Obj2",
"count" : 30000,
"ID" : [
0,
1,
.
.
.
]
},
{
"value" : "Facet2Obj3",
"count" : 30000,
"ID" : [
0,
1,
.
.
.
]
}
]
}
{
"_id" : "Facet3",
"value" : [
{
"value" : "Value3",
"count" : 30000,
"ID" : [
0,
1,
2,
.
.
.
]
}
]
}
{
"_id" : "Facet4",
"value" : [
{
"value" : "Facet4Obj1",
"count" : 30000,
"ID" : [
0,
1,
2,
.
.
.
]
}
]
}
我将使用格式(具有不同 ID)的 30,000 个文档插入到 mongodb 中,然后我做了一个 map-reduce,但速度很慢。使用 30,000 个文档大约需要 30 分钟,但随后我将带有构面的索引放入它变得更快一点,就像需要 350 秒一样,但使用 50,000 个文档又需要大约 30 分钟。db.collection.getIndexes()
当我使用mongodb检查索引时,将返回此输出:
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "database.collection",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"ID" : 1,
"Facet1" : 1,
"Facet2" : 1,
"Facet3" : 1,
"Facet4" : 1
},
"ns" : "database.collection",
"name" : "ID_1_Facet1_1_Facet2_1_Facet3_1_Facet4_1"
}
我对map-reduce仍然不够快的索引做错了什么吗,因为索引必须在战略上放置,否则性能输出将相反
非常感谢您的回答,并在此先感谢