I have this code to Mongo in Golang
cond := make([]bson.M, 0)
cond = append(condiciones, bson.M{"$match": bson.M{"userId": ID}})
cond = append(condiciones, bson.M{
"$lookup": bson.M{
"from": "invoices",
"localField": "userId",
"foreignField": "userId",
"as": "sales",
}})
cond = append(condiciones, bson.M{"$unwind": "$sales"})
cond = append(condiciones, bson.M{"$skip": skip})
cond = append(condiciones, bson.M{"$limit": 100})
cond = append(condiciones, bson.M{"$sort": bson.M{"dateInvoice": -1}})
cursor, err := collect.Aggregate(context.TODO(), cond)
I'm using Golang and MongoDB
"go.mongodb.org/mongo-driver/bson"
this works fine in union, limit and skipping documents, but the $sort doesn't work.. I have invoices but not ordered by 'dateInvoice'
I'm desperate.. please
What's wrong in my code ?
Regards