go – How to use array filters of mongodb 3.6 in mgo framework?-ThrowExceptions

Exception or error:

Hi i have a situation where i have to update objects in nested array in mongodb collection using mgo framework of Go. As of now mongodb version 3.6 support this using ArrayFilters as a 3rd parameter in Collection.Update().The mgo Collection.Update() function only supports 2 parameters, one to find and another for update. How can i use arrayfilters in mgo’s Collection.Update()

This is my object look like

  "TPID": "",





and this was my approach in mongo shell(version 3.6)

{"$set" : 
{"QP.$[i].CompulsoryNos.$[j].PerformanceCriteria.$[k].Skills" : 
{"arrayFilters" : [{"i.qpCode" : "ID_1"},{"j.NosCode" : "Code_1"}, 
{"k.Skills" : "skills_1"}]})

is there is any way to implement the same query using mgo?

How to solve:

I modified the mgo version

_ = session.DB("youdbname").C("test4").UpdateUseAf(
    bson.M{"$set": bson.M{"QP.$[i].CompulsoryNos.$[j].PerformanceCriteria.$[k].Skills": "Talented"}},
        {"i.qpCode" : "ID_1"},
        {"j.NosCode" : "Code_1"},
        {"k.Skills" : "skills_1"},

Leave a Reply

Your email address will not be published. Required fields are marked *