I have a query like this
aggregate( [
{
$match: {
"user_id": 1,
"shop_id": 1,
"$text": {"$search" : "API"}
}
},
{
$group: {
_id: null,
count: {
$sum: {
$cond: [ { $eq: [ "$deleted_at", null ] }, 1, 0 ]
}
}
}
}
])
and it is not working as expected, it is returning 0 as a count value, but should be almost 6k.
But this query (without search)
aggregate( [
{
$match: {
"user_id": 1,
"shop_id": 1
}
},
{
$group: {
_id: null,
count: {
$sum: {
$cond: [ { $eq: [ "$deleted_at", null ] }, 1, 0 ]
}
}
}
}
])
is working as expected, and also query with the search but without $cond
aggregate( [
{
$match: {
"user_id": 1,
"shop_id": 1,
"$text": {"$search" : "API"},
"deleted_at" : {"$eq" : null}
}
},
{ $group: { _id: null, count: { $sum: 1 } } }
])
is working as expected, but it’s 10 times slower…
Why is the query with search and cond not working?
Thank you in advance