How can I get the ID of the record affected from an .update
operation with upsert: true
, independent from whether an update or an insert was performed?
My understanding is that the record ID will be returned when using .insert
, but .update
only returns a true/false.
My code:
Entity.update({
attr1: val1,
attr2: val2
}, {
$setOnInsert: {
attr1: val1,
attr2: val2
}
}, {
upsert: true
});