【发布时间】:2021-02-19 19:06:06
【问题描述】:
我有一个名为 people 的集合,这个集合几乎有 100k documents..
虽然我是前端开发人员,但我不知道如何提高搜索性能。
我搜索如下:
const phoneNumbers = [
{ "phone": { "$regex": `1` } },
{ "phone": { "$regex": `2` } },
{ "phone": { "$regex": `3` } },
{ "phone": { "$regex": `4` } },
{ "phone": { "$regex": `5` } },
{ "phone": { "$regex": `xxx` } },
{ "phone": { "$regex": `999` } },
{ "phone": { "$regex": `1000` } },
];
peopleCollection.find({$or: phoneNumbers}).toArray((error, matchedDocs)=> {
// returning matched docs
});
您可以看到我的搜索结构,您对创建 index 有什么建议?
这对创建 index 有帮助吗? 如果是,我如何创建正确的 index ?
【问题讨论】:
标签: javascript node.js regex mongodb mongodb-query