mongoose plugin, populate and keep updated references to documents in other collection.
denormalization plugin for mongoose
This plugins helps you create denormalized schemas by copying references from other collection and keeping them up to date.
Just like model.populate except that data is stored in the collection instead of being populated for each query
$ npm install mongoosefiller
// plugin optionsoptions =id: String // (optional default to path._id) path of the id of our reference modelpath: String // (optional default to '') path to property to keep in sync with ref modelpos: String // (optional) pos operator prefix used to update model in collection arrayref : String // reference Model name (collection we are copying data from)dest: String // destination Model name (collection we are copying data to)select: String // (optional default to all) list of space separated field to include or excludesync: String // (optional default to select) list of space separated field to keep in sync after first save.
// examplesvar UserSchema =firstname: type: Stringlastname : type: Stringemail : type: String;var PostSchema =message: type: String;// add user.firstname, user.lastname, user.email path to schema// fill user.* with data from User// update documents every time a change occur in UserPostSchema;friendSchema =date: type: Date;ListSchema =name: type: Stringfriends: friendSchema;// add firstname, lastname path to schema// fill friends with data from User// update friends in List (using positional operator List.friends.$._id)// every time a change occur in UserfriendSchema;
fill event is triggered on the denormalized schema when the the ref doc change and collection is updated
if you define a path attribute, like in the following example, the plugin will create a virtual id accessor
I have done a basic test on one doc