Hello Mongo Fam, need a solution to this, facing a blocker
I’m using Golang. In my mongo collection, I have the “_id” which is object id key and an “priority” key which is an integer value. I’m applying the find query and sorting the data with {priority, -1}, {_id, 1} like shown below.
sortingOptionsBson := bson.D{{"priority", -1},{"_id", 1}}
My code would look something like this
// limit and offset values are passed from the arguments of the function where this code resides
// the problem lies with SetSort()
sortingOptionsBson := bson.D{{"priority", -1},{"_id", 1}}
opts := options.Find().SetSort(sortingOptionsBson).SetLimit(o_limit).SetSkip(o_skip)
cur, err = coll.Find(ctx, filter, opts)
Sometimes, the sort would be done based on “_id” first and then “priority” which should not be done.
I want to avoid this misordering and always want the priority sorting to happen first and _id sorting to happen second. What is the issue here and how can it be solved?