I have a collection with a unique index comprising fields x, y, and z, plus a full text index on another field t.
{ key: {x:1, y:1, z:1}, unique: true }
{ key: {t:"text"}, unique:false }
When querying the full text index, I will always specify x and y (but not z), as follows:
{
x:1,
y:2,
$text: { $search: "Foo" }
}
Sometimes specific combinations of x and y:
{
$or: [ {x:1,y:2}, {x:2,y:3} ]
$text: { $search: "Foo" },
}
My question is whether it’s beneficial to add x and y to the text index in addition to the unique index, or whether MongoDB can perform index intersection effectively in this case?
To clarify, should my indexes look like this?
{ key: {x:1, y:1, z:1}, unique: true }
{ key: {x:1, y:1, t:"text"}, unique:false }