I tried to add dynamic key-value pair on the javascript object, but I wasn't able to add it. I tried lots of techniques such as dot operator, indexing method but none of them works for me.
Here is code to add dynamic key-value pair using the dot operator:
if (user) {
Subscription.findOne({
subscriptionID
}, (err, subscription) => {
if (subscription) {
subscription['activateDate'] = new Date();
//subscription.activatedate=new Date();
user.subscription.push(subscription);
user.save((err, item) => {
if (item) {
return res.json({
data: item,
message: "Subscription added successfully"
})
}
}
}
}
}
}
}