Serialize then deserialize mongoose.Model instance Serialize then deserialize mongoose.Model instance mongoose mongoose

Serialize then deserialize mongoose.Model instance


It may be wrong, but you may try using upsert() on the created user object instead of saving it.

If you plan to use it usually, you may end up defining a new static method in your schema, like:

Schema.statics.createOrUpdate = function(object, callback) {    statics.upsert(this, object, callback);};

This way you can pass your user data to M2, and on M2, you can update it easily.


This is a late call but I faced same problem before finding out Model.hydrate method.

http://mongoosejs.com/docs/api.html#model_Model.hydrate

Shortcut for creating a new Document from existing raw data, pre-saved in the DB. The document returned has no paths marked as modified initially.

So on M2 User.hydarate(userObject) can be used instead of new User(userObject) and no need to set isNew to false.