I'm using the official mongo driver on golang and trying to aggregate. I want to sort entries based on the multiplication of currency and salary.
import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func main () {
//...
aggregatePipeline := bson.A{}
aggregatePipeline = append(aggregatePipeline, bson.D{{Key: "$addFields", Value: bson.D{{Key: "trueSalary", Value: bson.D{{"$multiply", bson.A{"salary", "currency"}}}}}}})
aggregatePipeline = append(aggregatePipeline, bson.D{{"$sort", bson.D{{"trueSalary", -1}}}})
cursor , _ := myCollection.Aggregate(context.TODO(), aggregatePipeline)
// cursor returns nil.
}
But cursor returns nil.
My mongo entities all have "salary" and "currency" as Integer.