Skip to content

Commit 4652126

Browse files
committed
test: add coverage for agg cursor
1 parent 7d96e6a commit 4652126

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/aggregate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = collection => {
1717
action.params.push({});
1818
}
1919
action.chained.forEach(function(chained) {
20-
action.params[1][name] = chained.params[0];
20+
action.params[1][chained.name] = chained.params[0];
2121
});
2222
return action;
2323
});

test/collection.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ describe('Collection', function() {
6969
assert.equal(res[0].y, 1);
7070
assert.equal(res[1].y, 2);
7171
});
72+
73+
it('cursor', async function() {
74+
const Test = db.collection('Test');
75+
76+
await Test.insertOne({ x: 1 });
77+
await Test.insertOne({ x: 2 });
78+
79+
const cursor = await Test.aggregate([
80+
{ $project: { y: '$x' } },
81+
{ $sort: { y: 1 } }
82+
]).cursor();
83+
84+
let ys = [];
85+
for (let doc = await cursor.next(); doc != null; doc = await cursor.next()) {
86+
ys.push(doc.y);
87+
}
88+
assert.deepEqual(ys, [1, 2]);
89+
});
7290
});
7391

7492
describe('#insertOne()', function() {

0 commit comments

Comments
 (0)