Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

upsert mongoose

// If document doesn't exist, create it. If it exists, overwrite it.

await Model.updateOne(
  { name: 'Jean-Luc Picard' },
  { $set: { age: 59 } },
  { upsert: true } // Make this update into an upsert
);
Source by masteringjs.io #
 
PREVIOUS NEXT
Tagged: #upsert #mongoose
ADD COMMENT
Topic
Name
5+6 =