larryprice / mongoose-simple-random Goto Github PK
View Code? Open in Web Editor NEWSimple and easy-to-use NodeJS Mongoose Schema plugin to pull random documents
License: MIT License
Simple and easy-to-use NodeJS Mongoose Schema plugin to pull random documents
License: MIT License
(node:1824) DeprecationWarning: collection.count is deprecated, and will be removed in a future version. Use collection.countDocuments or collection.estimatedDocumentCount instead
for code:
const items_random = await Item.findRandom({}, {}, {limit: 6}, function(err, docs) { return docs });
Please update. Thanks
I have a collection with 10 documents. This will only select one of the first 9 randomly. Or, 100 documents and it will only select one of the first 99.
var start = Math.max(0, Math.floor((num-limit)*Math.random()));
might be written as
var start = Math.max(0, Math.floor(((num-limit)+1)*Math.random()));
I didn't test.
Given that built in $sample methods work much more efficiently, would you consider unpublishing, or maybe changing mongoose-simple-random to take advantage of such improvements?
how to use async/await??? I use it's warning : callback is not function
Would I be right in thinking that the "find many" function selects the first document randomly but the rest are simply those documents that directly follow it in mongo's sequence?
If so, it might be good to document that clearly. For some applications it would be an undesirable limitation. (For example pulling 5 random playing cards from an unshuffled deck would nearly always return a straight run!)
If I call findRandom with options that return no results, the query hangs indefinitely.
Any sort of pagination for this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.