N conditions in $or
query:
await db.user.aggregate([
{ $match: {
$or: [ { A_1: "some_value" }, { A_2: "some_value" }, { A_N: "some_value" } ]
} },
])
N concurrent queries
await Promise.all([
await db.user.aggregate([
{ $match: {
A_1: "some_value"
} },
]),
await db.user.aggregate([
{ $match: {
A_2: "some_value"
} },
]),
await db.user.aggregate([
{ $match: {
A_N: "some_value"
} },
])
])
The later strategy has been tested repeatedly to be significantly faster than the first strategy against a collection with 100k documents. In the real use case, there 10s of conditions within each $or
.
Is this expected behavior?
Is there no way to get the one-query strategy to be at least just as fast?