I'm having group of array of element in MongoDB as given below :
{
"_id" : 5,
"quizzes" : [
{
"wk" : 1,
"score" : 10
},
{
"wk" : 2,
"score" : 8
},
{
"wk" : 3,
"score" : 5
}
],
"play" : [
{
"wk" : 2,
"score" : 8
},
{
"wk" : 3,
"score" : 5
}
]
}
I am trying insert new record in array if not present and if record present in that array then update that array record. Below is my MongoDB query.
db.push.update(
{ _id: 5 },
{ $push: { "quizzes": {"wk" : 6.0,"score" : 8.0},"play": {"wk" : 6.0,"score" : 8.0} } }
)
Every time when i execute this query it inserts new record in array but i want if record present then update that array.