Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weisjohn/mongoose-prime
Prime a mongoose model with default data.
https://github.com/weisjohn/mongoose-prime
Last synced: about 2 months ago
JSON representation
Prime a mongoose model with default data.
- Host: GitHub
- URL: https://github.com/weisjohn/mongoose-prime
- Owner: weisjohn
- Created: 2013-12-20T02:47:13.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-03-17T18:57:32.000Z (almost 9 years ago)
- Last Synced: 2024-11-15T00:33:01.158Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/mongoose-prime
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mongoose-prime
prime a mongoose model with data
### usage
```javascript
// mongoose is connection and `users` is already registered
var mp = require('mongoose-prime')
, users = mongoose.model('users')
, data = require('./data/users')
;mp(users, data, function(err, results) {
Object.keys(results).forEach(function(key) {
console.log(results[key] + " user " + key);
});
});
```### api
#### `mp(model, data, [validate], [callback])`
- `model` - reference to the mongoose model
- `data` - an object or array of objects
- `validate` - optional boolean to disable schema validation (default: `null`)
- `callback` - optional `function(err, results) {}``callback` receives a `results` object of with three numbers: `added`, `failed`, `skipped` and a `records` array, containing the inserted records.
`validate` indicates whether schema validation should occur before inserting. For example, object reference validators which ensure the referenced document exists may prevent data from being loaded (i.e. cylical dependencies). To prevent this, invoke with the value of `false` to temporarily suspend the validators. After loading the data, the schema validation will be set to it's previous value. If no value is specified, `mongoose-prime` will not modify the model's validation settings. (cf. [`#validateBeforeSave`](http://mongoosejs.com/docs/guide.html#validateBeforeSave))
### integration
`mongoose-prime` plays nicely with [`mongoose-deleted`](https://www.npmjs.com/package/mongoose-deleted).