Simple default data for mongoose models
Simple default data for mongoose models.
mongoose-simple-fixtures takes a
mongoose reference, and a path to the
directory which contains the default data and an err-first
// assuming a mongoose connection and models defined abovevar path = require'path'msf = require'mongoose-simple-fixtures'dir = pathresolve__dirname "./fixtures";msfmongoose dirif err console.log"loading data failed";;
Each filename in the
directory must correspond to the model name in mongoose. For example, if you used the directory
fixtures and it contained two files:
$ ls fixtures/templates.json users.json
mongoose-simple-fixtures would look for two models on the mongoose reference called
users. If those models do not exist, the data loading will fail.
The callback receives a
results array with objects. Each object has a
name property with the name of the model and three numbers
skipped indicating what took place.
mongoose-simple-fixtures will not add duplicate data by attempting to find a record before the insertion. If that document already exists, the
skipped count is incremented, if some odd error happens, the
failed count is incremented, if the document is saved successfully, the
added count is incremeneted.