如何使用GO lang删除存储在mongodb中的集合中的所有项目?
在mongo控制台中我可以使用:
db.mycollection.remove({})
Run Code Online (Sandbox Code Playgroud)
其中空括号{}表示所有文档模式.
在GO lang(我使用"gopkg.in/mgo.v2"和"gopkg.in/mgo.v2/bson")有方法:
sess.DB("mydb").C("mycollection").Remove(...)
or
sess.DB("mydb").C("mycollection").RemoveAll(...)
Run Code Online (Sandbox Code Playgroud)
但是它们都需要实现选择器的参数.例如,选择器可以是bson映射
bson.M{"id": id}
Run Code Online (Sandbox Code Playgroud)
但我想删除所有元素,而不是特定元素.