Why FindRandom() Mongoose For Node.js Method Doesn't Work?
Schema: var random = require('mongoose-random'); var productSchema = new mongoose.Schema(...) productSchema.plugin(random, {path: 'r'}); var products = mongoose.model('sportsStor
Solution 1:
And probably solution could be here - see the comments on npm page mongoose-random example .
// if you have an existing collection, it must first by synced.
// this will add random data for the `path` key for each doc.
Try
productSchema.syncRandom(function (err, result) {
console.log(result.updated);
});
Solution 2:
Try to change the line
productSchema.plugin(random, {path: 'r'});
To
productSchema.plugin(random());
Wasn't tested, but should work.
Post a Comment for "Why FindRandom() Mongoose For Node.js Method Doesn't Work?"