Updated Add a Mongoose Model (markdown)

Scott Erickson 2016-04-22 15:24:36 -07:00
parent dc89cfb299
commit 65035ce8be

@ -30,14 +30,17 @@ SomeModelSchema.plugin(plugins.NamedPlugin)
SomeModelSchema.plugin(plugins.SearchablePlugin, {searchable: ['name', 'description']}) SomeModelSchema.plugin(plugins.SearchablePlugin, {searchable: ['name', 'description']})
# 3. Add editableProperties and jsonSchema. Common logic require on these properties being defined. # 3. Add common static properties.
# * editableProperties: whitelist of properties that may be edited through the collection's standard PUT endpoint # * editableProperties: whitelist of properties that may be edited through
# the collection's standard PUT endpoint
# * jsonSchema: used in POST and PUT to validate data before saving to the db # * jsonSchema: used in POST and PUT to validate data before saving to the db
SomeModelSchema.statics.editableProperties = ['name', 'description', 'userID'] SomeModelSchema.statics.editableProperties = ['name', 'description', 'userID']
SomeModelSchema.statics.jsonSchema = jsonSchema SomeModelSchema.statics.jsonSchema = jsonSchema
# 4. Create the model from the schema and export it. The first argument should be the all-lowercase, dot-separated, singular version of the collection name. Mongoose will pluralize that for the collection name. # 4. Create the model from the schema and export it. The first argument should be
# the all-lowercase, dot-separated, singular version of the collection name. Mongoose
# will pluralize that for the collection name.
module.exports = mongoose.model('some.model', SomeModelSchema) module.exports = mongoose.model('some.model', SomeModelSchema)
``` ```