This is the structure of the json object that is inside one of the fields called campaignResponse.
campaignResponse:
{ prop:
{ summary: 't',
retailer: '4',
sent: 't',
queued: 'f',
open: 'f',
spam: 't',
click: 't',
blocked: 'f',
bounce: 'f',
unsub: 'f',
To: 'kartooot@gmail.com',
status: 'clicked',
subject: '',
messageid: '20829150339986762',
From: '',
details: '',
date: '2017-04-03T12:51:38' },
camp2:
{ date: '2017-04-03T12:51:38',
details: '',
From: '',
messageid: '20829150339986762',
subject: '',
status: 'clicked',
To: 'kartooot@gmail.com',
unsub: 'f',
bounce: 'f',
blocked: 'f',
click: 't',
spam: 'f',
open: 't',
queued: 'f',
sent: 't',
retailer: '4',
summary: 'f' },
camp1:
{ date: '2017-04-03T12:51:38',
details: '',
From: '',
messageid: '20829150339986762',
subject: '',
status: 'clicked',
To: 'kartooot@gmail.com',
unsub: 'f',
bounce: 'f',
blocked: 'f',
click: 't',
spam: 't',
open: 'f',
queued: 'f',
sent: 't',
retailer: '4',
summary: 'f' } }
I want to update prop, camp1, camp2. I want to pass it through a variable. So at one moment variable = camp1
. I want to set campaignResponse.variable to obj. But I am getting a Syntax Error saying "Unexpected token . ".
User.findOneAndUpdate({email: res[i].email},{$set: {campaignSummary: temp, campaignResponse.varialble: obj}},{new: true},function(err ,result2){
if(err)
callback(err);
else{
console.log(result2);
callback(err,result2);
}
})
Please help me out here folks. Even suggestion of a better way to do this would be appreciated. Thanks.