0
votes

As inputs, I get a search query (should operator) and a filter (about whether or not a post is liked, must/mustNot operators). I start with the following as a foundation to my aggregation pipeline:

{ $search: { compound: {} } }

Then, if a query is given, I add this:

$search.compound.should.push({
    text: {
        query: q,
        path: ["data.displayName"],
        score: {
            boost: {
                value: 5,
            },
        },
    },
    // Plus others
});

Now, every post has a likes array. I would like to only select the posts that include a particular string in their likes, if possible under compound.must/mustNot.

I'd like to avoid loading the data on the computer and filtering the documents locally (I pay for the entire database, I use the entire database!). If array manipulation is impossible in Aggregation Pipelines, what could an alternative be? I'm still pretty confused by the docs, and where operators should be used.

1

1 Answers

0
votes

You are so close. In the way you have structured the query, what you need is compound.filter. You can have must clauses as well. It will exclude documents that don't contain the string. See here

$search.compound.must.push({
    text: {
        query: q,
        path: ["data.likes"],
    },
    // Plus others
});