【发布时间】:2017-07-08 20:40:18
【问题描述】:
我正在尝试对我的收藏集进行此查询Audios
var querySlow = {
"palabra": {
$regex: "^" + keywords,
"$options": "i"
},
$or: [{
"_p_pais": {
$in: interested_accents
}
}, {
"languageCodeTatoeba": {
$in: interested_accents_tatoeba
}
}]
}; // takes 20 seconds
这实际上真的很慢,但如果我删除任何$or,它非常非常快,例如:
var queryFast1 = {
"palabra": {
$regex: "^" + keywords,
"$options": "i"
},
$or: [{
"_p_pais": {
$in: interested_accents
}
}]
}; // takes less than 1 second
或者这个
var queryFast2 = {
"palabra": {
$regex: "^" + keywords,
"$options": "i"
},
$or: [{
"languageCodeTatoeba": {
$in: interested_accents_tatoeba
}
}]
}; // takes less than 1 second
这是慢查询的.explain():
我其实不知道如何管理索引,我应该为这个集合创建一个索引吗??
【问题讨论】:
-
你能发布快速查询的
.explain()吗?
标签: mongodb indexing mongodb-query