【问题标题】:Mongo DB query on Mongo DB driver for Golang关于 Golang 的 Mongodb 驱动程序的 Mongodb 查询
【发布时间】:2021-02-09 07:38:11
【问题描述】:

我需要比较我的 mongo db 数据库上的两个字段,这就是那个查询

db.characters.find({$expr:{$eq:["$currentLv", "$maxLv"]}})

如何在 mongo db driver for golang (mgo) 上进行这样的查询

【问题讨论】:

    标签: mongodb go mgo


    【解决方案1】:

    我不会写如何实例化与 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())
    

    【讨论】:

      猜你喜欢
      • 2012-03-04
      • 2020-02-02
      • 2023-01-27
      • 1970-01-01
      • 2018-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多