I run into the problem of wanting to subtract 2 fields from my mongodb database and return them in a variable.
I am using bson.M to perform the operation in golang without any success.
col2 := db.Collection("products")
pipe2 := []bson.M{
{"$group": bson.M{
"_id": IDUser,
"total": bson.M{"$subtract": {"$actualPrice", "$oldPrice"}},
}},
}
cur2, err := col2.Aggregate(ctx, pipe2)