globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 230 forks source link

Sorting of array contents not working #236

Closed arjanvaneersel closed 6 years ago

arjanvaneersel commented 6 years ago

The following query

q := []bson.M{
            bson.M{"$match": bson.M{}},
            bson.M{"$unwind": "$reminder_reports"},
            bson.M{"$sort": bson.M{
                "$reminder_reports": "-1",
            }},
            bson.M{"$group": bson.M{
                "reminder_reports": bson.M{
                    "$push": "$reminder_reports",
                },
            }},
        }

Results in Failed to parse: filter: [ { $match: {} }, { $unwind: "$reminder_reports" }, { $sort: { $reminder_reports: "-1" } }, { $group: { reminder_reports: { $push: "$reminder_reports" } } } ]. 'filter' field must be of BSON type object.

What I'm trying to do is fetch all records and sort the values of the array. Am I doing this in the wrong way? Or is this a bug?

eminano commented 6 years ago

Hi @arjanvaneersel,

Sorry for the delay on getting back to you! Is this still an issue? On a first glance, is it possible that you're missing the $ in front of the "reminder_reports" inside the group filter?

Please let us know so we can either close this issue or look more into it.

Thanks, Esther

eminano commented 6 years ago

Closing this one, please reopen if the issue persists!

Thanks, Esther