10

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?

fredmaggiowski
  • 2,232
  • 3
  • 25
  • 44
Bestbug
  • 475
  • 4
  • 13

1 Answers1

8

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}})

Bestbug
  • 475
  • 4
  • 13