MongoDB
 SQL >> Database >  >> NoSQL >> MongoDB

Verificare se un upsert MongoDB ha inserito o aggiornato

Sì, puoi verificarlo usando una chiamata sicura o getLastError. Il risultato contiene un campo upserted e un campo updatedExisting.

Se l’upsert ha creato un nuovo documento, upserted contiene il suo _id. Se invece ha aggiornato un documento esistente, updatedExisting sarà true.

In pratica updatedExisting è un booleano che indica se è stato aggiornato un record già presente.