I try to create a MongoDB query filter with the nested operators (OR/AND/...). But lib requires to create a bson.D
and pass bson.E
elements into it. If I need to have OR/AND
inside AND/OR
- I need to put bson.M + bson.D
inside bson.D
like this:
filter := bson.M{"$and": bson.D{{"p", 10}, bson.M{"$or": bson.D{{"s", 30}, {"a", 1}}}}}
.. and of course it doesn't work: cannot use primitive.M literal (type primitive.M) as type primitive.E in slice literal
. Probably the same problem will happen if later I try to use a ... in []
logics inside a bson.D
How do I create such nested queries in Go and official MongoDB driver?