Home:ALL Converter>Mongoose aggregation expressions within the query language

Mongoose aggregation expressions within the query language

Ask Time:2018-12-10T21:53:31         Author:Ceddy Muhoza

Json Formatter

Am looking for a way to use aggregation expressions within the query language.

e.g this is my aggregation

Locations.aggregate([
{ "$match": { "name": "development" } },
{
    "$lookup": {
        "from": "users",
        "localField": "followers",
        "foreignField": "_id",
        "as": "followers"
    }
}
])

How can we turn it into a find

like

Locations.find( ...aggregation goes here )

PS: I've researched on $expr but there's nowhere it shows how to add the $lookup or $match into it.

Author:Ceddy Muhoza,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53707140/mongoose-aggregation-expressions-within-the-query-language
yy