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

后端 未结 3 1000
走了就别回头了
走了就别回头了 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 05:06

    you have to use $exists

    Syntax: { field: { $exists: } }

    For more details

    http://docs.mongodb.org/manual/reference/operator/query/exists/

提交回复
热议问题