I’m running across something that had me a little troubled but I’m not exactly sure if my worries are merited or not.
Here’s the code:
if (this.order) {
let order = await Order.findOne({ _id: this.order }).populate("products");
order = {
id: order.uniqueNumber,
products: order.products
.filter((p) => p.vendor == String(recipient._id))
.map((p) => p.getDataForEvents()),
};
let data = { ...shared, order };
await Event.create("New Message - Order", recipient.email, data);
My question is: is it alright to overwrite a mongoose document reference in this way? the order, then reassignment on the next line. I wasn’t sure but it bothered me because I know mongoose tracks changes and I’m not sure if this could mess anything up. My co worker seems to think it’s fine, but I wanted to ask here to be sure. any ideas?