I'm working in Golang
and mgo
and I would like to delete all the documents in a collection older than a specified date, using _id
value.
So far I've tried to create a dummy objectId using a struct NewObjectIdWithTime
after that I'm trying to delete documents using
collection.Remove(bson.M{"_id": bson.M{"$lt": objectId}})
But I'm not getting any results, any suggestion?
I really don't like answer my self but since the only help I recive from stackoverflow community was a negative rating (without any explain) I post the solution:
The problem is mgo have RemoveAll where delete all the element match the criteria, so my new query is:collection.RemoveAll(bson.M{"_id": bson.M{"$lt": objectId}})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With