javascript - Is there any way to identify updated/upserted in mongoose/mongoDB? -


actually want know there way identify updated old record or added new record after using findoneandupdate() upsert: true option in mongoose/mongodb?.

i using

// partial code   var update = {$set:fieldstoset};     var options = {new: true, upsert:true};     var created = yield user.findoneandupdate(fieldsquery, update, options).exec();  // here want check updated old record or create new record 

use built-in timestamps option in schema, can check createat field.

var user = new schema({   ...,   {     timestamps: true, }); 

this automatically add createdat , updatedat fields schema.


applied code

const calltime = new date();  user.findoneandupdate(...)  .then((ret) => {     // created     if (ret.createat.gettime() >= calltime.gettime()) {}      // modified  }); 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -