a
Size: a a a
a
Ð
АТ
АТ
User.findOneAndUpdate({username: "test"}, user, {setDefaultsOnInsert: true, new: true, upsert: true}, function(err, newUser) {
callback(err, newUser);
});a
User.findOneAndUpdate({username: "test"}, user, {setDefaultsOnInsert: true, new: true, upsert: true}, function(err, newUser) {
callback(err, newUser);
});Performing an update on the path '_id' would modify the immutable field '_id'
АТ
Performing an update on the path '_id' would modify the immutable field '_id'
АТ
a
a
M
АТ
a

АТ
a
АТ
АТ
setDefaultsOnInsert: if this and upsert are true, mongoose will apply the defaults specified in the model's schema if a new document is created. This option only works on MongoDB >= 2.4 because it relies on MongoDB's $setOnInsert operator.a
setDefaultsOnInsert: if this and upsert are true, mongoose will apply the defaults specified in the model's schema if a new document is created. This option only works on MongoDB >= 2.4 because it relies on MongoDB's $setOnInsert operator.АТ
a