I have the format of:
{
"_id" : ObjectId("5af44cfbe2e96c58ec402efb"),
"username" : "egealpay2",
"email" : "egealpay2@gmail.com",
"fullName" : "ege",
"pnumber" : "",
"oneSignal" : "d427dcdf-7939-4ada-a035-be74e1e45091",
"friends" : [
{
"email" : "baransrc@gmail.com",
"status" : 2
}
],
"alarms" : [
{
"id" : "2",
"title" : "before",
"location" : "default",
"startTime" : "2018-05-16\t\t\t16:29",
"endTime" : "16:29\t\t\t17 - 05 - 2018",
"remindAt" : "17:29\t\t\t15 - 05 - 2018",
"privacy" : "0",
"userORJoinedAlarm" : "1",
"eventJoiners" : [
{
"email" : "ilkersadya@sabanciuniv.edu",
"status" : 1
},
{
"email" : "ilkercankayasss@sabanciuniv.edu",
"status" : 1
},
{
"email" : "ilkearcankaya@sabanciuniv.edu",
"status" : 1
},
{
"email" : "iaaalkercankaya@sabanciuniv.edu",
"status" : 1
}
],
"comments" : [ ]
}
]
}
i would like to set status: 2
of "email" : "ilkersadya@sabanciuniv.edu", its under
"alarms:" , "eventJoiners" :which has an id of 2 as
"id"`
I have tried using push with $ but couldnt manage to get this working and its been bugging me over 2 hours.
Update i had tried thanks to @Ashish:
dbo.collection("users").findOne( { email: userId } , function(errZer, addedZer) {
dbo.collection("users").findOneAndUpdate( {email: addedID, "alarms.id": eventIDGiv, alarms: { $elemMatch: { id: '2', eventJoiners: { $elemMatch: { email: addedID } } }} },
{ $set: { "alarms.$.eventJoiners.$.status": '2' } , function(err, added) {
got the error
(node:9334) UnhandledPromiseRejectionWarning: MongoError: Too many positional (i.e. '$') elements found in path 'alarms.$.eventJoiners.$.status'