I am looking for convinient way to check if object already exists in collection. For now the only way that i have found is
type result interface{}
var res re
in the Official Mongo Driver you can get count of documents with specific key using CountDocuments function :
count, err := collection.CountDocuments(context.TODO(), bson.D{{"key", "value"}})
count, err = collection.Find(bson.M{field: value}).Count()
you have to use $exists
Syntax: { field: { $exists: } }
For more details
http://docs.mongodb.org/manual/reference/operator/query/exists/