suppose I have the following struct
type Test struct {
Title string `bson:"title" json:"title"`
Update Update `bson:"update" json:"update"`
}
type Update struct {
Changes []string `bson:"change" json:"change"`
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"`
}
And suppose I want to sort my results in the Query by "update.updatedAt"
cs.Find(bson.M{title: "some title"}).Sort("-update.updatedAt").Limit(10).All(&results)
This query does not work as expected. I can't seem to find any documentation about how to sort a Query by a subdocument field. Intuitively, I was certain that my example would work. For reference, "-updatedAt" works just fine, but for reasons that aren't necessary to explain, I have to keep Update as a subdocument of Test.
Every example and Stack Overflow question I have seen so far involves the sorting and reordering of subdocuments, or arrays. In this case I don't care about the order of my subdocuments, and I'm not sorting by anything inside of an array. I merely want to sort my the documents by the date of a subdocument.
Is there a way to do this with the Go Mgo Query library?