Hi all,
my question is exactly as the title:
is it possible to remove records where the lookup output field is empty without using unwind
my current code: (golang)
pipeline := mongo.Pipeline{
{
{"$lookup", bson.D{
{"from", "follows"},
{"let", bson.D{
{"followed", "$user._id"}},
},
{"pipeline", bson.A{bson.D{
{"$match", bson.D{
{"$expr", bson.D{
{"$and", bson.A{
bson.D{
{"$eq", bson.A{"$followed", "$$followed"}},
},
bson.D{
{"$eq", bson.A{"$follower", userID}},
},
}},
}},
}},
}}},
{"as", "helper"},
}},
},
{
{"$unwind", bson.D{
{"path", "$helper"},
{"preserveNullAndEmptyArrays", false},
}},
},
{
{"$unset", "helper"},
},
}
this works fine, the lookup output field is helper
first unwind the field, and remove records where that field is empty (how can we do that but without using unwind at the first place)
and then we unset the field because i don’t need it (not related to the question)
ps: if you are interested what is the code for, it’s to get posts from users that i’m following, the helper is only used to get such data that’s why i unset it at the end.