Check object existence in mongo using gopkg.in/mgo.v2

后端 未结 3 978
走了就别回头了
走了就别回头了 2021-01-12 04:16

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         


        
3条回答
  •  醉梦人生
    2021-01-12 04:52

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

提交回复
热议问题