In my NodeJS project, I have a line like this:
const { fieldA, fieldB, fieldC, fieldD, fieldE, fieldF, ...rest } = originalObject;
fieldB, fieldC, fieldD, fieldE & fieldF are never used again in code, but as we know, the way the ES-6 deconstruction works, the rest
object will be a new object without fields A-F. Therefore, later somewhere there is a dB operation, in a way so that fields A-F aren’t upserted.
const updatedItem = await model.findOneAndUpdate({ fieldA }, rest, { upsert: true });
However, I want to conditionally include/ exclude fieldF
in rest
. I know it can be done on the reading side, but how do it in the assignment side?