I have collection of objects which have multiple array fields. Something like:
{
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",
}
How can I optimize query like next one?
{
status: "Active",
$or: [
{"lead_sponsor.name": /company/i},
{"collaborators.name": /company/i},
{"terms": /phrase/i},
{"keywords": /phrase/i},
{"description": /phrase/i},
]
}
Compound indexes cannot have more then one array field.
Will it help if I copy all data from array fields into new field searchArray
and will add compound index that includes only this array? Is it good approach?