I have a Student struct which looks like this.
type Student struct {
Name string `json:"name" bson:"name"`
Marks int `json:"marks" bson:"marks"`
Subjects []string `json:"subjects" bson:"subjects"`
}
I am using opts.Sort
to Sort the result. More on that
opts.Sort = bson.D{
{Key: "marks", Value: -1},
}
I also want to sort the results by Subjects
, in a way that, if for any Student, if the subject Math
exist, it should be sorted on top (descending order), before sorting it by marks
I tried doing this
opts.Sort = bson.D{
{Key: "subjects", Value: bson.M{"$in": "math"}},
{Key: "marks", Value: -1},
}
I know this doesn't seem right because I am not passing 1 or -1 but I don't know how can I modify it to make it work. What am I missing here?.