我需要比较mongo db数据库上的两个字段,这是对此的查询
db.characters.find({$expr:{$eq:["$currentLv", "$maxLv"]}})
我该如何在mongo db驱动程序上查询golang(mgo)
答案 0 :(得分:0)
如果您不知道,here is the link,我不会写到如何实例化与mongodb的连接。
您的查询将是这样的:
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
filter := bson.M{
"$expr": bson.M{
"$eq": []string{"$currentLv", "$maxLv"},
},
}
_, _ = db.Database("dbname").Collection("collection").Find(ctx, filter, options.Find())