mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Updated Add a Mongoose Model (markdown)
parent
dc89cfb299
commit
65035ce8be
1 changed files with 6 additions and 3 deletions
|
@ -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)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue