dtl19910708 2014-09-25 20:46
浏览 212
已采纳

Golang / mgo-设置“ $ set”为更新条件

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)

How can I add the $set part to an existing bson.M? There must be a way to do it, but I couldn't find it.

  • 写回答

1条回答 默认 最新

  • dpd20130 2014-09-25 20:58
    关注
      update["$set"] = bson.M{"lastupdate": nctime}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?