mongoose-simple-random
Author: Larry Price
Website: larry-price.com
Email: larry.price.dev@gmail.com
Description
Simple and easy-to-use NodeJS Mongoose Schema plugin to find random documents.
Usage
var random = ;var s =message: String;s;Test = mongoose;// Find a single random documentTest;// Find "limit" random documents (defaults to array of 1)Test;// Parameters match parameters for "find"var filter = genre: $in: 'adventure' 'point-and-click' ;var fields = name: 1 description: 0 ;var options = skip: 10 limit: 10 populate: 'mySubDoc' ;Test;
Tests
$ npm test
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style.
Add unit tests for any new or changed functionality. Lint and test your code.
Release History
- 0.1.0 Initial release
- 0.2.0 API change - findRandom always returns array, findOneRandom returns single item
- 0.2.1 README update
- 0.3.0 API change - flip-flopping on "count", use "limit" to tell findByRandom how many elements to return
- 0.4.0 Update dependencies and use a new random algorithm
- 0.4.1 Fix hang on 0 results and clean up callback syntax.