I am trying to get all mongo db documents with timestamps less than 10 seconds ago. I am not finding any. I think this is because my time format is not correct. I am not finding them querying mongo db from shell db.mgo.find({timestamp:{$gt: new Date(ISODate().getTime() - 86400)}}) for last 24h.
// FindLast 10min
func FindLast(session *mgo.Session, db, collection string) ([]Syslog, error) {
var results []Syslog
t := time.Now().Add(-10 * time.Second)
c := session.DB(db).C(collection)
err := c.Find(
bson.M{
"timestamp": bson.M{
"$gt": t,
},
}).All(&results)
return results, err
}
If I pick one of document ObjectId("...").getTimestamp() it shows ISODate("2017-08-25T19:14:54Z") which is about 4h ahead of me so it is UTC. But even if I change to UTC in my func it still not finding any documents
t := time.Now().UTC().Add(-time.Duration(10)*time.Minute).Format("2006-01-02 15:04:05")