Golang / mgo - 在更新时根据条件设置"$set"

3
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 中?一定有方法可以做到,但我找不到。

1个回答

3
  update["$set"] = bson.M{"lastupdate": nctime}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接