Hello mongo people!
I’m trying to use the full text search feature with my Atlas collection. That seems to be working great. I also want the results to be limited to documents where a certain field - that is an array - is empty/has a zero length. I’ve been looking over the docs for the aggregate search pipeline but nothing seems to handle this that I can find.
Previously, I was using the find()
api like this:
collection.find({ tags: { $size: 0 } });
I feel like I should include this filter before the text search of other fields since it would greatly limit was needs… searched. What does that operation look like in an aggregate pipeline?
Right now, I’m text searching like this:
const cursor = collection.aggregate([
{
$search: {
compound: {
must: [
{
text: {
query: 'style',
path: ['title'],
},
},
],
},
},
},
]);
This is getting my a cursor of the result of docs where the title field does contain style, so that’s great! I was thinking this could be a compound operation since I also want to filter out the tags array field to empty ones but I might be mistaken there too.
Any ideas on how to accomplish this query?