【问题标题】:Golang / mgo - set "$set" on condition for updateGolang / mgo - 在更新条件下设置“$set”
【发布时间】:2014-09-25 20:46:58
【问题描述】:
update := bson.M{"$push": bson.M{"versions" : Versions{"x", 123}}}

if nctime, _ := time.Parse("2006-01-02 15:04:05", ctime); group.LastUpdate.Before(nctime) {
    // update.$set = bson.M{"lastupdate": nctime}
}

_ = db.Mongo.C("collection").UpdateId(group.Id, update)

如何将 $set 部分添加到现有的 bson.M 中?一定有办法,但我找不到。

【问题讨论】:

    标签: go mgo


    【解决方案1】:
      update["$set"] = bson.M{"lastupdate": nctime}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-01
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      • 2017-11-02
      • 2017-11-23
      • 1970-01-01
      相关资源
      最近更新 更多