Skip to content

Instantly share code, notes, and snippets.

@bells17
Created July 17, 2015 05:57
Show Gist options
  • Save bells17/64aca65bdd817dc53b93 to your computer and use it in GitHub Desktop.
Save bells17/64aca65bdd817dc53b93 to your computer and use it in GitHub Desktop.
mongooseでSchema定義してないpropertyに値をセットする ref: http://qiita.com/bells17/items/cafe8f0b3e285e9e8ab4
var somethingSchema = new Schema({
field: String
});
var Something = mongoose.model('Something', somethingSchema);
var something = new Something();
something.not_defined_field = 'Not defined field value';
something('not_defined_field'); // -> undefined
something.not_defined_field; // -> undefined
something.set('not_defined_field', 'Not defined field value', { strict: false });
something('not_defined_field'); // -> 'Not defined field value'
something.not_defined_field; // -> undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment