I have a document in MongoDB of the form:
{"_id" : 1, "value" : { "listOfNumbers" : [2,3,4]}}
I can’t seem to figure out, how to insert a new number into the “listOfNumbers”. I found:
db.collection.update({_id:1}, {listOfNumbers : 8})
This only works if the above document would be of the form (a document without a sub document):
{"_id" : 1, "listOfNumbers" : [2,3,4]}
I tried playing around with all sorts of combinations, but none worked as expected.
Would anybody know the solution to this problem?
You should use the following syntax :
It will push the value 8 in your array listOfNumbers