Hi, I’m in the process of refactoring a $match to the various parts of a $search.
As an example, this works:
$search: {
index: 'assets',
compound: {
must: [
{
equals: {
path: 'isActive',
value: 3
},
},
{
text: {
path: 'userId',
query: userId
}
},
]
}
}
… while this does not:
$search: {
index: 'assets',
compound: {
must: [
{
equals: {
path: 'isActive',
value: 3
},
},
{
text: {
path: 'userId',
query: userId
}
},
],
mustNot: [
{
equals: {
path: '_id',
value: assetId
},
},
]
}
}
Here, “userId” is a string representation of an ObjectId, but anything involving an actual ObjectId fails when used in the $search, while the $match works:
$match: {
_id: {
$ne: assetId
}
}
I’m also using a $project:
const project = {
$project: {
_id: 0,
id: '$_id',
userId: 1,
}
}
I’ve tried changing the “_id” around and experimenting, (“$_id”, “id” and so on) but nothing has worked.
Any ideas?