Question:I have two models
Vendor, I want all
mainVendorfield of deleted
_idto be replaced with the first
vendorsarray is empty, I want
mainVendorto be set to
Say I have
_id, I want my
_idI want my product to be like
What I have now
vendorsarray is empty.
Answer:A bit long query, but you can try with Update with aggregation pipeline.
$condoperator to check whether
vendorsis an empty array, if yes set
null, else take the first value from the
vendorsfield, it does the same concept as
mainVendorfield, the outcome will be different in removing the first item from
If you have better answer, please add a comment about this, thank you!