Search code examples
gomgo

Golang / mgo - set "$set" on condition for update


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.


Solution

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