Created
February 7, 2020 14:40
-
-
Save dr-dimitru/5f9e98330c6043e27a0a28b1f1ec2373 to your computer and use it in GitHub Desktop.
Efficient cursor count in Meteor.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { rawCount } from './raw-count.js'; | |
rawCount(Meteor.users); | |
rawCount(Meteor.users, {'profile.active': true}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Future from 'fibers/future'; | |
const rawCount = (collection, query = {}) => { | |
const fut = new Future(); | |
collection.rawCollection().count(query, (error, count) => { | |
if (error) { | |
fut.return(0); | |
} else { | |
fut.return(count); | |
} | |
}); | |
return fut.wait(); | |
}; | |
export { rawCount }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment