janez89 / mongoose-materialized

mongoose materialized plugin
59 stars 22 forks source link

MongoDB 3.2 Limit / Skip not working #27

Open molywitman opened 8 years ago

molywitman commented 8 years ago

Hi,

moving to mongoDB 3.2.9 got problem with limit https://github.com/florianholzapfel/express-restify-mongoose/issues/

to fix changed -- schema.method('getDescendants', function () { var query = new Query(arguments); var promise = new mongoose.Promise; if (query.callback) promise.addBack(query.callback); var self = this;

    query.condition.path = {
        $regex: (self.path ? '' : '^') + options.separator + self._id.toString()
    };

    query.sort.path = 1;
    query.sort._w = query.sort._w || 1;
        query.sort._w = 1;

    var cursor = self.constructor.find(query.condition, query.fields)
    .sort(query.sort);
    if (query.limit)
        cursor.limit(parseInt(query.limit)); <------------------------------------------- changed
    if (query.skip)
        cursor.skip(query.skip);
    cursor.exec(function (err, data) {
        if (err)
            promise.error(err);
        else
            promise.complete(data);
    });
    return promise;
});
joniba commented 8 years ago

Tried to reproduce this in a test with mongodb 3.2 without success. Although attempting to upgrade mongoose-materialized's mongoose library to the latest version caused most of the tests to fail. The above mentioned fix can be found in this fork. If there is more interest in this issue I can try to provide a reproducible sample.