Skip to content

Instantly share code, notes, and snippets.

@dr-dimitru
Created February 7, 2020 14:40
Show Gist options
  • Save dr-dimitru/5f9e98330c6043e27a0a28b1f1ec2373 to your computer and use it in GitHub Desktop.
Save dr-dimitru/5f9e98330c6043e27a0a28b1f1ec2373 to your computer and use it in GitHub Desktop.
Efficient cursor count in Meteor.js
import { rawCount } from './raw-count.js';
rawCount(Meteor.users);
rawCount(Meteor.users, {'profile.active': true});
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