Skip to content

Commit ddfe99c

Browse files
committed
NODE-486 .limit return more than limited value
1 parent a63e9a1 commit ddfe99c

File tree

7 files changed

+232
-161
lines changed

7 files changed

+232
-161
lines changed

lib/aggregation_cursor.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ var inherits = require('util').inherits
1818
/**
1919
* @fileOverview The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB
2020
* allowing for iteration over the results returned from the underlying query. It supports
21-
* one by one document iteration, conversion to an array or can be iterated as a Node 0.10.X
21+
* one by one document iteration, conversion to an array or can be iterated as a Node 0.10.X
2222
* or higher stream
23-
*
23+
*
2424
* **AGGREGATIONCURSOR Cannot directly be instantiated**
2525
* @example
2626
* var MongoClient = require('mongodb').MongoClient,
@@ -36,7 +36,7 @@ var inherits = require('util').inherits
3636
* , {a:2, b:2}, {a:3, b:3}
3737
* , {a:4, b:4}], {w:1}, function(err, result) {
3838
* test.equal(null, err);
39-
*
39+
*
4040
* // Show that duplicate records got dropped
4141
* col.aggregation({}, {cursor: {}}).toArray(function(err, items) {
4242
* test.equal(null, err);
@@ -126,7 +126,7 @@ var AggregationCursor = function(bson, ns, cmd, options, topology, topologyOptio
126126
*/
127127

128128
// Inherit from Readable
129-
inherits(AggregationCursor, Readable);
129+
inherits(AggregationCursor, Readable);
130130

131131
// Extend the Cursor
132132
for(var name in CoreCursor.prototype) {
@@ -338,13 +338,13 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
338338
* @method AggregationCursor.prototype.close
339339
* @param {AggregationCursor~resultCallback} [callback] The result callback.
340340
* @return {null}
341-
*/
341+
*/
342342

343343
/**
344344
* Is the cursor closed
345345
* @method AggregationCursor.prototype.isClosed
346346
* @return {boolean}
347-
*/
347+
*/
348348

349349
/**
350350
* Execute the explain for the cursor
@@ -357,13 +357,13 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
357357
* Clone the cursor
358358
* @function AggregationCursor.prototype.clone
359359
* @return {AggregationCursor}
360-
*/
360+
*/
361361

362362
/**
363363
* Resets the cursor
364364
* @function AggregationCursor.prototype.rewind
365365
* @return {AggregationCursor}
366-
*/
366+
*/
367367

368368
/**
369369
* The callback format for the forEach iterator method
@@ -390,4 +390,4 @@ AggregationCursor.INIT = 0;
390390
AggregationCursor.OPEN = 1;
391391
AggregationCursor.CLOSED = 2;
392392

393-
module.exports = AggregationCursor;
393+
module.exports = AggregationCursor;

lib/command_cursor.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ var inherits = require('util').inherits
1717
, CoreReadPreference = require('mongodb-core').ReadPreference;
1818

1919
/**
20-
* @fileOverview The **CommandCursor** class is an internal class that embodies a
21-
* generalized cursor based on a MongoDB command allowing for iteration over the
22-
* results returned. It supports one by one document iteration, conversion to an
20+
* @fileOverview The **CommandCursor** class is an internal class that embodies a
21+
* generalized cursor based on a MongoDB command allowing for iteration over the
22+
* results returned. It supports one by one document iteration, conversion to an
2323
* array or can be iterated as a Node 0.10.X or higher stream
24-
*
24+
*
2525
* **CommandCursor Cannot directly be instantiated**
2626
* @example
2727
* var MongoClient = require('mongodb').MongoClient,
@@ -37,7 +37,7 @@ var inherits = require('util').inherits
3737
* , {a:2, b:2}, {a:3, b:3}
3838
* , {a:4, b:4}], {w:1}, function(err, result) {
3939
* test.equal(null, err);
40-
*
40+
*
4141
* // List the database collections available
4242
* db.listCollections().toArray(function(err, items) {
4343
* test.equal(null, err);
@@ -126,11 +126,11 @@ var CommandCursor = function(bson, ns, cmd, options, topology, topologyOptions)
126126
*/
127127

128128
// Inherit from Readable
129-
inherits(CommandCursor, Readable);
129+
inherits(CommandCursor, Readable);
130130

131131
// Set the methods to inherit from prototype
132132
var methodsToInherit = ['_next', 'next', 'each', 'forEach', 'toArray'
133-
, 'rewind', 'bufferedCount', 'readBufferedDocuments', 'close', 'isClosed'];
133+
, 'rewind', 'bufferedCount', 'readBufferedDocuments', 'close', 'isClosed', 'kill'];
134134

135135
// Only inherit the types we need
136136
for(var i = 0; i < methodsToInherit.length; i++) {
@@ -231,25 +231,25 @@ CommandCursor.prototype.get = CommandCursor.prototype.toArray;
231231
* @method CommandCursor.prototype.close
232232
* @param {CommandCursor~resultCallback} [callback] The result callback.
233233
* @return {null}
234-
*/
234+
*/
235235

236236
/**
237237
* Is the cursor closed
238238
* @method CommandCursor.prototype.isClosed
239239
* @return {boolean}
240-
*/
240+
*/
241241

242242
/**
243243
* Clone the cursor
244244
* @function CommandCursor.prototype.clone
245245
* @return {CommandCursor}
246-
*/
246+
*/
247247

248248
/**
249249
* Resets the cursor
250250
* @function CommandCursor.prototype.rewind
251251
* @return {CommandCursor}
252-
*/
252+
*/
253253

254254
/**
255255
* The callback format for the forEach iterator method
@@ -276,4 +276,4 @@ CommandCursor.INIT = 0;
276276
CommandCursor.OPEN = 1;
277277
CommandCursor.CLOSED = 2;
278278

279-
module.exports = CommandCursor;
279+
module.exports = CommandCursor;

lib/cursor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Cursor.prototype.setCursorOption = function(field, value) {
179179
if(this.s.state == Cursor.CLOSED || this.s.state == Cursor.OPEN || this.isDead()) throw new MongoError("Cursor is closed");
180180
if(fields.indexOf(field) == -1) throw new MongoError(f("option %s not a supported option %s", field, fields));
181181
this.s[field] = value;
182-
if(field == 'numberOfRetries')
182+
if(field == 'numberOfRetries')
183183
this.s.currentNumberOfRetries = value;
184184
return this;
185185
}
@@ -592,6 +592,7 @@ Cursor.prototype.toArray = function(callback) {
592592

593593
// Add doc to items
594594
items.push(doc)
595+
595596
// Get all buffered objects
596597
if(self.bufferedCount() > 0) {
597598
var docs = self.readBufferedDocuments(self.bufferedCount())

lib/gridfs/chunk.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ var Chunk = function(file, mongoObject, writeConcern) {
3232
if(mongoObjectFinal.data == null) {
3333
} else if(typeof mongoObjectFinal.data == "string") {
3434
var buffer = new Buffer(mongoObjectFinal.data.length);
35-
buffer.write(mongoObjectFinal.data, 'binary', 0);
35+
buffer.write(mongoObjectFinal.data, 0, 'binary');
3636
this.data = new Binary(buffer);
3737
} else if(Array.isArray(mongoObjectFinal.data)) {
3838
var buffer = new Buffer(mongoObjectFinal.data.length);
39-
buffer.write(mongoObjectFinal.data.join(''), 'binary', 0);
39+
buffer.write(mongoObjectFinal.data.join(''), 0, 'binary');
4040
this.data = new Binary(buffer);
4141
} else if(mongoObjectFinal.data._bsontype === 'Binary') {
4242
this.data = mongoObjectFinal.data;
4343
} else if(Buffer.isBuffer(mongoObjectFinal.data)) {
4444
} else {
4545
throw Error("Illegal chunk format");
4646
}
47-
47+
4848
// Update position
4949
this.internalPosition = 0;
5050
};
5151

5252
/**
5353
* Writes a data to this object and advance the read/write head.
5454
*
55-
* @param data {string} the data to write
55+
* @param data {string} the data to write
5656
* @param callback {function(*, GridStore)} This will be called after executing
5757
* this method. The first parameter will contain null and the second one
5858
* will contain a reference to this object.
@@ -152,7 +152,7 @@ Chunk.prototype.save = function(options, callback) {
152152
// Merge the options
153153
var writeOptions = {};
154154
for(var name in options) writeOptions[name] = options[name];
155-
for(var name in self.writeConcern) writeOptions[name] = self.writeConcern[name];
155+
for(var name in self.writeConcern) writeOptions[name] = self.writeConcern[name];
156156

157157
// collection.remove({'_id':self.objectId}, self.writeConcern, function(err, result) {
158158
collection.remove({'_id':self.objectId}, writeOptions, function(err, result) {
@@ -179,10 +179,10 @@ Chunk.prototype.save = function(options, callback) {
179179
/**
180180
* Creates a mongoDB object representation of this chunk.
181181
*
182-
* @param callback {function(Object)} This will be called after executing this
182+
* @param callback {function(Object)} This will be called after executing this
183183
* method. The object will be passed to the first parameter and will have
184184
* the structure:
185-
*
185+
*
186186
* <pre><code>
187187
* {
188188
* '_id' : , // {number} id for this chunk
@@ -233,4 +233,4 @@ Object.defineProperty(Chunk.prototype, "position", { enumerable: true
233233
*/
234234
Chunk.DEFAULT_CHUNK_SIZE = 1024 * 255;
235235

236-
module.exports = Chunk;
236+
module.exports = Chunk;

0 commit comments

Comments
 (0)