Code Snippet

Golang mgo sort number inside a string

Posted on

// Get List func (z *DocumentTagService) GetDocumentTags() ([]models.DocumentTag, error) { z.DatabaseService.Connect() var o []models.DocumentTag err := (*z.DatabaseService.Db).C(z.Collection).Find(bson.M{}).Sort(“-$natural”, “-documentReference”).All(&o) return o, err } Result [ { “idDocumentTag”: “5b1390f29ebea41854dcc0dc”, “documenReference”: “MCTU/2018/16”, “company”: “MCTU” }, { “idDocumentTag”: “5b1390f09ebea41854dcc0db”, “documenReference”: “MCTU/2018/15”, “company”: “MCTU” }, { “idDocumentTag”: “5b1390d19ebea41854dcc0da”, “documenReference”: “MCTU/2018/14”, “company”: “MCTU” }, { “idDocumentTag”: “5b1390d09ebea41854dcc0d9”, “documenReference”: “MCTU/2018/13”, “company”: “MCTU” […]