I have worked on the Go and MongoDb project. In which, I have faced a problem. I have passed a dynamic slice of integeres ([]int) into a query using $in operator. Every thing seems good but when this slice is empty then it return an error "$in needs an array". But i used it as a search parameter and want if i pass blank array then it matched with all.
Note: I have userd MongoDB shell version v5.0.3
Here is my code:
var searchedProfiles []int
searchFilter := bson.M{"customer.id": bson.M{"$in": searchedProfiles}}
newQry := []bson.M{
{"$lookup": bson.M{
"localField": "cid",
"from": "customers",
"foreignField": "_id",
"as": "customer"}},
{"$match": searchFilter},
}
If anybody have any idea please let me know. Thanks!