We host a site with several tenants. So, there is a mongo collection containing information about all customers, for example,
{customerId: 22, category: "category", region: "region", balance: 23434... }
After we learned about the Intersection index, we tried to create several indexes of the same field to support queries with different query criteria with variable fields, such as
{ customerId: 22, category: "1" } { customerId: 22, region: "somewhere" } { customerId: 22, balance: {$gt:0} } { customerId: 22, region: {$in: ["R1", "R2"]},balance: {$gt:0} } ....
But it just turned out that the intersection did not happen, studying "db.collection.explain". Since the fields are limited, we finally made a decision to build a composite index that includes all fields.
{customerId: 1, category: 1, region: 1, balance:1...}
And then it turned out that under all the queries, a "large" composite index is used, since "queryId" is in the query.
{ customerId: 22, category: "1" } { customerId: 22, region: "somewhere" } { customerId: 22, balance: {$gt:0} } { customerId: 22, region: {$in: ["R1", "R2"]},balance: {$gt:0} } ....
Popeye
source share