Im trying to get all documents fro the last 10 minutes. I thought it wold be convenient to use ObjectId for it. I`m using this code to achieve it.
currentTime := time.Now().UTC()
queryTime := currentTime.Add(-10 * time.Minute)
var oidtime = bson.NewObjectIdWithTime(queryTime)
query := bson.M{"_id": bson.M{"$gt": oidtime}}
err := c.Find(query).All(&result)
But I always have null as an answer.
err := c.Find(bson.M{}).All(&result)
This kind of query works fine though. I have this thing in mongo logs.
command: find { find: "meraki", filter: { _id: { $gt: "\�D� " } }, skip: 0, $db: "devices" } planSummary: IXSCAN {
_id: 1 } keysExamined:0 docsExamined:0 cursorExhausted:1 numYields:0 nreturned:0 reslen:118 locks:{ Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } } } protocol:op_query 0ms
updated: Document example
{ "_id" : ObjectId("5cb464aff3276d5fa21cd31d"), "lldp" : *, "cdp" : null, "id" : "*"}