我收集了具有多个数组字段的对象。就像是:
{
sponsors: {
lead_sponsor: {
name: "Mark",
type: "Individual"
}
collaborators: [
{name: "Company Ltd.", type: "Company"},
{name: "Industry Company Ltd.", type: "Company"}
]
},
terms: ["Some term", "Some term 2", "Some term 3"],
keywords: ["word1", "word2", "word3", "word4"],
description: "Here might be big text with detailed description",
status: "Active",
}
如何优化下一个查询?
{
status: "Active",
$or: [
{"lead_sponsor.name": /company/i},
{"collaborators.name": /company/i},
{"terms": /phrase/i},
{"keywords": /phrase/i},
{"description": /phrase/i},
]
}
复合索引不能有多个数组字段。如果我将数组字段中的所有数据复制到新字段中searchArray
并添加仅包含此数组的复合索引会有帮助吗?这是好方法吗?