mongoose-reference-count
This mongoose plugin allows to keep track of number of references to a particular object in certain collection.
Usage
var refCount = ;var mongoose = ; // define our schemavar Schema = name: String address: String dateOfBirth: Date;// adding plugin to schemaSchema;var Person = mongoose; var newGuy = name: 'Azamat' address: 'Sesame street' dateOfBirth: 9111;newGuy;
Now let's make some queries to Person
with Schema
schema
Person;
This plugin does two things:
- adds hits attribute to schema
- adds post middleware for
findOne()
method on requested model
The following will be printed
_id: someID name: 'Azamat' address: 'Sesame street' dateOfBirth: 'Jan-1-1991' hits: 1
TODO
- add reference count when object is retrieved with find() method along with other objects.