How to update if exists otherwise insert new document?

In Mongoose, you’d use Person.update per the documentation. In order to create a document if it doesn’t already exist, you need to pass { upsert : true } in the options hash as it defaults to false.

i.e.

Person.update( { name : 'Ted' }, { name : 'Ted', age : 50 }, { upsert : true }, callback );

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)