Hi there,
I am new to Mongo and I have a question regarding aggregation. How can I return a document that contains null value in the date field after running a lookup?
Here is my code;
pipeline = [
{"$match": {'_id': user_id}},
{"$lookup": {"from": "merchant", "localField": "merchantsid",
"foreignField": "_id", "as": "merchants"}},
{"$project": {"email" : 1, "name" : 1,"merchants" : 1, "_id" : 0,
"merchants": {"$filter": { "input": "$merchants", "as": "merchant",
"cond": { "$eq": [ "merchant.date", "null"]}}}}},
{"$sort": {"merchants.teid": -1}},
]
return await database.User.aggregate(pipeline).to_list(int(limit))
The above gives me an empty array but the desired result should be something like this;
[
{
"email": "johndoe@email.com",
"name": "John Doe",
"role": "user",
"merchants": [
{
"_id": "913c5df4-581c-4fa5-9ba5-53c2f255d220",
"teid": 906220009,
"merchant_name": "SHOWCASE LTD",
"model": "Gateway",
"package": "1N5",
"date": null,
"created_at": "2023-01-22T21:44:07.789000",
"updated_at": "2023-01-22T21:44:07.789000"
}
]
}
]
Any help is appreciated.
Thanks