I am trying to remove a record from MongoDB using the following line of Go code:
mg.collection.Remove(bson.M{"id": 1})
this command returns a not found error but the following piece of codes works without issue in the terminal and Robomongo:
db.getCollection('main').remove({"id":1})
What am I doing wrong in Go?
Thanks
It would be helpful to see more of your code but I think I know what you're trying to do. You can call Remove
just on your collection
.
So (err handling removed for brevity):
session
being the session variable:
collection := session.DB("your_db_name").C("main")
err = collection.Remove(bson.M{"id":1})