How to remove all items from a collection stored in mongodb using GO lang?
In the mongo console, I can use:
db.mycollection.remove({})
where empty brackets {} mean the entire document template.
There are methods in GO lang (I use "gopkg.in/mgo.v2" and "gopkg.in/mgo.v2/bson"):
sess.DB("mydb").C("mycollection").Remove(...)
or
sess.DB("mydb").C("mycollection").RemoveAll(...)
but for both of them you need a parameter that implements the selector. For example, the selector may be a bson card
bson.M{"id": id}
but I want to delete all the elements, not the individual ones.
source
share