I've only found ways to create OR update a document. I need to create if not exists but do nothing if it already exists. How to do it in mongoose?
Please note that findOneAndUpdate won't work, because if it fins the document, it updates it! I don't want that.
UPDATE:
I just want to create a variable called order_number
that can be incremented. However, to increment, I must make sure the document exists. However, I cannot update its value in case it exists.
I tried:
let r = await OrderNumber.findOneAndUpdate({ unique: 0 }, { unique: 0, order_number: 0 }, { upsert: true });
It successfully creates when it does not exist, but always updates order_number
to 0
. I don't want this to happen.