Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mother/mongoose-whitelist
Tiny plugin to simplify whitelisting
https://github.com/mother/mongoose-whitelist
mongoose whitelist whitelisting
Last synced: 19 days ago
JSON representation
Tiny plugin to simplify whitelisting
- Host: GitHub
- URL: https://github.com/mother/mongoose-whitelist
- Owner: mother
- Created: 2016-10-15T03:36:29.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-15T06:50:53.000Z (about 8 years ago)
- Last Synced: 2024-11-17T18:23:26.182Z (about 1 month ago)
- Topics: mongoose, whitelist, whitelisting
- Language: JavaScript
- Homepage:
- Size: 1000 Bytes
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#### Sample Usage
Setup the plugin
````
const mongoose = require('mongoose')
const whitelist = require('mongoose-whitelist')const UserSchema = new mongoose.Schema({
name: {
first: { type: String },
last: { type: String }
},
email: { type: String },
encrypted_password: { type: String }
})UserSchema.plugin(whitelist, {
attributes: ['name', 'email']
})mongoose.model('user', UserSchema)
````Applying the plugin
````
const User = mongoose.model('user')
const user = new User()const payload = {
'name.first': 'John',
'name.last': 'McGee',
email: '[email protected]',
encrypted_password: 'terrible-password'
}// Only set whitelisted properties
// (encrypted_password will not be set)
user.set(User.whitelist(payload))
````#### License
MIT. Copyright (c) 2016 Mother Co.