【发布时间】:2014-09-20 14:31:51
【问题描述】:
请帮我处理 mongoDB 中的索引。
有一个集合,其中包含 800,000 个文档。 有一个请求运行时间很长。大约 5 秒!
{
"$or":[
{
"performer":"534ba408f9cd0ecb51711673",
"$or":[
{
"performersRole":"534ba30bf9cd0ec151a69522"
},
{
"performersRole":{
"$exists":false
}
}
]
},
{
"performersRole":"534ba30bf9cd0ec151a69522",
"notShowInToDo":{
"$ne":true
}
}
],
"taskTime":{
"$gte":1409774400,
"$lt":1409860799
},
"$and":[
{
"$or":[
{
"department":{
"$in":[
"5356134ef9cd0e4805672a15",
"53561368f9cd0e4b05645f3f",
"53a0357ff9cd0e670537c4b7",
"53a03594f9cd0e6705389449"
]
}
},
{
"department":{
"$exists":false
}
}
]
},
{
"$or":[
{
"salon":"534f7b3bf9cd0e311e77896f"
},
{
"salon":{
"$exists":false
}
}
]
}
],
"isDone":{
"$ne":true
}
}
要添加哪些索引来优化?感谢您的建议!
几乎所有关于这种格式的文档:
{
"_id": "541da66cf535a4a8569dd0ed",
"title": "test task",
"taskTime": NumberLong(1411229292),
"client": "53f876b2f535a4187f9e1264",
"salon": "534f7c3cf9cd0e91206dd948",
"track": "541da66cf535a4a8569dd0ec",
"department": "53a0357ff9cd0e670537c4b7",
"type": "invitePBP",
"performersRole": [
"534ba30bf9cd0ec151a69522"
],
"notShowInToDo": true,
"@createTime": NumberLong(1411229292),
"@updateTime": NumberLong(1411229292)
}
【问题讨论】:
-
您最好提供更多详细信息。例如,你做了哪些索引?哪些字段具有唯一值? ...
-
添加到示例问题文档中
-
除了非常奇怪的结构之外,您可能只是read the docs about indexing。
标签: mongodb mongodb-query