0

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"
                            })
                        }
                    }
                }
            }
        }
    }
}
Nick is tired
  • 6,860
  • 20
  • 39
  • 51
Pranay kumar
  • 1,983
  • 4
  • 22
  • 51
  • Does this answer your question? [Is data returned from Mongoose immutable?](https://stackoverflow.com/questions/13350185/is-data-returned-from-mongoose-immutable) – xurei Sep 14 '20 at 13:09
  • Does this helps: https://stackoverflow.com/questions/61955931/mongoose-save-not-saving-changes – vishnu Sep 14 '20 at 13:16

0 Answers0