Skip to content

Commit

Permalink
Merge pull request #4255 from pyramation/master
Browse files Browse the repository at this point in the history
lean() for migrating from stream() to cursor()
  • Loading branch information
vkarpov15 authored Jun 22, 2016
2 parents d2e1091 + d992759 commit 1b4e7aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/querycursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ function _next(ctx, callback) {

var opts = ctx.query._mongooseOptions;
if (!opts.populate) {
return _create(ctx, doc, null, callback);
return opts.lean === true ?
callback(null, doc) :
_create(ctx, doc, null, callback);
}

var pop = helpers.preparePopulationOptionsMQ(ctx.query,
Expand Down
24 changes: 24 additions & 0 deletions test/query.cursor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,28 @@ describe('QueryCursor', function() {
}).catch(done);
});
});

describe('#lean()', function() {
it('lean', function(done) {
var cursor = Model.find().sort({ name: 1 }).lean().cursor();

var expectedNames = ['Axl', 'Slash'];
var cur = 0;
cursor.on('data', function(doc) {
assert.equal(doc.name, expectedNames[cur++]);
assert.strictEqual(false, doc instanceof mongoose.Document);
});

cursor.on('error', function(error) {
done(error);
});

cursor.on('end', function() {
assert.equal(cur, 2);
done();
});

});
});

});

0 comments on commit 1b4e7aa

Please sign in to comment.