【发布时间】:2021-02-09 07:38:11
【问题描述】:
我需要比较我的 mongo db 数据库上的两个字段,这就是那个查询
db.characters.find({$expr:{$eq:["$currentLv", "$maxLv"]}})
如何在 mongo db driver for golang (mgo) 上进行这样的查询
【问题讨论】:
我需要比较我的 mongo db 数据库上的两个字段,这就是那个查询
db.characters.find({$expr:{$eq:["$currentLv", "$maxLv"]}})
如何在 mongo db driver for golang (mgo) 上进行这样的查询
【问题讨论】:
我不会写如何实例化与 mongodb 的连接,如果你不知道,here is the link。
您的查询将是这样的:
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())
【讨论】: