UPDATE ON MONGODB USING $ PUSH

0

The $ push operator in mongoDB accepts only numeric value to change when I try to do sub = 1 , for example, it does not work. In the first example I can update normally (static), in the second not.

db.my_collection.updateOne({"_id":3, "p_act": 2},{$push:{"p_act.$.subact.**3**.annotations":{"an_description":"bla bla bla","an_date":new Date()}}})


sub = 3

db.my_collection.updateOne({"_id":3, "p_act": 2},{$push:{"p_act.$.subact.**sub**.annotations":{"an_description":"bla bla bla","an_date":new Date()}}})

What am I doing wrong? Is there any other way to do it?

    
asked by anonymous 20.02.2018 / 15:09

0 answers