Add field not in schema with mongoose
You can add and remove fields in schema using option { strict: false }
option: strict
The strict option, (enabled by default), ensures that values passed to our model constructor that were not specified in our schema do not get saved to the db.
var thingSchema = new Schema({..}, { strict: false });
And also you can do this in update query as well
Model.findOneAndUpdate(
query, //filter
update, //data to update
{ //options
returnNewDocument: true,
new: true,
strict: false
}
)
You can check the documentations here
You can add new fields in schema User using .add
require('mongoose').model('User').schema.add({fullName: String});
Thanks.-