Reputation: 2826
Ho can i write this condition in golang for mongodb:
success_count: { $sum: { $cond: ["$is_success", 1, 0] } }
I a'm trying this but not working:
"$success_count": bson.M{"$sum": bson.M{"$cond": bson.M{"$is_success", 1, 0}}}
Upvotes: 0
Views: 1052
Reputation: 483
You can also use a bson.A, which is just a representation of an Array.
bson.M{"$cond": bson.A{"$is_success", 1, 0}}
Upvotes: 0
Reputation: 18410
Use []interface{}
instead of bson.M
. Here bson.M
is map[string]interface{}
but you need to use slice.
bson.M{"$cond": []interface{}{"$is_success", 1, 0}}
Upvotes: 1