I'm trying to retrieve the last inserted document using FindOne as suggested elsewhere:
collection.FindOne(ctx, bson.M{"$natural": -1})
Get last inserted element from mongodb in GoLang
Here is my example:
var lastrecord bson.M
if err = collection.FindOne(ctx, bson.M{"$natural": -1}).Decode(&lastrecord); err != nil {
log.Fatal(err)
}
fmt.Println(lastrecord)
Unfortunately I get the following error:
(BadValue) unknown top level operator: $natural
I'd prefer to use FindOne if possible.