Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd problem with cursor.count #189

Open
jojobyte opened this issue Mar 18, 2016 · 0 comments
Open

Odd problem with cursor.count #189

jojobyte opened this issue Mar 18, 2016 · 0 comments

Comments

@jojobyte
Copy link

Not sure if this is a mongoskin or mongodb problem, but as I'm using mongoskin it might be helpful for others as I couldn't find a reference to this.

Had a server running Mongo 2.6 and an index was failing, found out we had to upgrade to 3.2 to get the index to work properly. Did the upgrade, and we then had to upgrade the drivers.

We're running these versions now:

    "mongodb": "^2.0.55",
    "mongoskin": "^2.0.3",

After the upgrade, a binding we had that uses cursor.count stopped functioning properly.

The original code:

db.bind('stuff').bind({
    getByAccount: function(acctId, paginate, callback) {
        var cursor = this.find({
                account: ObjectID(acctId)
            })
            .limit(paginate.limit)
            .sort({ _id: -1 })
            .skip(paginate.page - 1 > 0 ? (paginate.page - 1 * paginate.limit) : 0);

        cursor.count(function(countErr, countRes) {
            var opData = {
                page: paginate.page,
                total: Math.ceil(countRes / paginate.limit),
                count: countRes,
                limit: paginate.limit
            };
            cursor.toArray(function(arrErr, arrRes) {
                opData.results = arrRes;
                callback(null, opData);
            });
        });
    }
});

The fix:

        // add false before cursor callback
        cursor.count(false, function(countErr, countRes) {
            // ...
        });

As far as I can tell this should be the default, even after the upgrade, but for some reason this call is coming back with a true value when left undefined for applySkipLimit

My concern is that this is may be the wrong way to override applySkipLimit and might later become deprecated or invalid.

Any thoughts? Is this a MongoDB Driver change or MongoSkin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant