Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getMore(function(err, result) {
if(err) {
items = [];
state = 'closed';
return callback(err, null);
}
// Add the items
items = items.concat(result.documents);
// Set the cursor id
cursorId = result.cursorId;
if(typeof cursorId == 'number') cursorId = Long.fromNumber(cursorId);
// If the cursor is done
if(result.cursorId.equals(zeroCursor)) {
return callback(null, items);
}
// Check the cursor id
exhaustGetMore(callback);
});
}
getMore(function(err, result) {
if(err) {
items = [];
state = 'closed';
return callback(err, null);
}
// Add the items
items = items.concat(result.documents);
// Set the cursor id
cursorId = result.cursorId;
if(typeof cursorId == 'number') cursorId = Long.fromNumber(cursorId);
// If the cursor is done
if(result.cursorId.equals(zeroCursor)) {
return callback(null, items);
}
// Check the cursor id
exhaustGetMore(callback);
});
}
// We have a an error document return the error
if(result.documents[0]['$err']
|| result.documents[0]['errmsg']) {
return callback(MongoError.create(result.documents[0]), null);
}
// We have a cursor document
if(result.documents[0].cursor != null
&& typeof result.documents[0].cursor != 'string') {
var id = result.documents[0].cursor.id;
// If we have a namespace change set the new namespace for getmores
if(result.documents[0].cursor.ns) {
self.ns = result.documents[0].cursor.ns;
}
// Promote id to long if needed
cursorState.cursorId = typeof id == 'number' ? Long.fromNumber(id) : id;
cursorState.lastCursorId = cursorState.cursorId;
// If we have a firstBatch set it
if(Array.isArray(result.documents[0].cursor.firstBatch)) {
cursorState.documents = result.documents[0].cursor.firstBatch;//.reverse();
}
// Return after processing command cursor
return callback(null, null);
}
if(Array.isArray(result.documents[0].result)) {
cursorState.documents = result.documents[0].result;
cursorState.cursorId = Long.ZERO;
return callback(null, null);
}
// Check if we have a command cursor
if(Array.isArray(result.documents) && result.documents.length == 1 && !cmd.find) {
if(result.documents[0]['$err']
|| result.documents[0]['errmsg']) {
return callback(MongoError.create(result.documents[0]), null);
}
if(result.documents[0].cursor != null
&& typeof result.documents[0].cursor != 'string') {
var id = result.documents[0].cursor.id;
// If we have a namespace change set the new namespace for getmores
if(result.documents[0].cursor.ns) {
self.ns = result.documents[0].cursor.ns;
}
// Promote id to long if needed
cursorState.cursorId = typeof id == 'number' ? Long.fromNumber(id) : id;
// If we have a firstBatch set it
if(Array.isArray(result.documents[0].cursor.firstBatch)) {
cursorState.documents = result.documents[0].cursor.firstBatch;//.reverse();
}
// Return after processing command cursor
return callback(null, null);
}
if(Array.isArray(result.documents[0].result)) {
cursorState.documents = result.documents[0].result;
cursorState.cursorId = Long.ZERO;
return callback(null, null);
}
}
db.command(command, _options, function(err, result) {
if(err) {
state = 'closed';
return callback(err, null);
}
// Retrieve the cursor id
cursorId = result.cursor.id;
if(typeof cursorId == 'number') cursorId = Long.fromNumber(cursorId);
// Validate cursorId
if(cursorId.equals(zeroCursor)) {
return callback(null, result.cursor.firstBatch);
};
// Add to the items
items = result.cursor.firstBatch;
// Execute the getMore
exhaustGetMore(callback);
});
}
db.command(command, _options, function(err, result) {
if(err) {
state = 'closed';
return callback(err, null);
}
// Retrieve the cursor id
cursorId = result.cursor.id;
if(typeof cursorId == 'number') cursorId = Long.fromNumber(cursorId);
// Get the first batch results
items = result.cursor.firstBatch;
// We have items return the first one
if(items.length > 0) {
callback(null, items.shift());
} else {
state = 'closed';
callback(null, null);
}
});
} else if(items.length > 0) {
return callback(new MongoError("cursor killed or timed out"), null);
}
if(!Array.isArray(r.documents) || r.documents.length == 0)
return callback(new MongoError(f('invalid getMore result returned for cursor id %s', cursorState.cursorId)));
// Raw, return all the extracted documents
if(raw) {
cursorState.documents = r.documents;
cursorState.cursorId = r.cursorId;
return callback(null, r.documents);
}
// Ensure we have a Long valie cursor id
var cursorId = typeof r.documents[0].cursor.id == 'number'
? Long.fromNumber(r.documents[0].cursor.id)
: r.documents[0].cursor.id;
// Set all the values
cursorState.documents = r.documents[0].cursor.nextBatch;
cursorState.cursorId = cursorId;
// Return the result
callback(null, r.documents[0]);
}
state = 'closed';
return callback(err, null);
}
// Get all the items
items = result.cursor.firstBatch;
// Emit all the items in the first batch
while(items.length > 0) {
callback(null, items.shift());
}
// Retrieve the cursor id
cursorId = result.cursor.id;
self.ns = result.cursor.ns;
if(typeof cursorId == 'number') cursorId = Long.fromNumber(cursorId);
// If no cursor we just finish up the current batch of items
if(cursorId.equals(zeroCursor)) {
state = 'closed';
return callback(null, null);
}
// Emit each until no more getMore's
exhaustGetMoreEach(callback);
});
}
items = [];
state = 'closed';
return callback(err, null);
}
// Add the items
items = result.documents;
// Emit all the items in the first batch
while(items.length > 0) {
callback(null, items.shift());
}
// Set the cursor id
cursorId = result.cursorId;
if(typeof cursorId == 'number') cursorId = Long.fromNumber(cursorId);
// If the cursor is done
if(result.cursorId.equals(zeroCursor)) {
state = "closed";
return callback(null, null);
}
// Check the cursor id
exhaustGetMoreEach(callback);
});
}
getMore(function(err, result) {
if(err) {
items = [];
state = 'closed';
return callback(err, null);
}
// Add the items
items = items.concat(result.documents);
// Set the cursor id
cursorId = result.cursorId;
if(typeof cursorId == 'number') cursorId = Long.fromNumber(cursorId);
// If the cursor is done
if(result.cursorId.equals(zeroCursor)) {
return callback(null, items);
}
// Check the cursor id
exhaustGetMore(callback);
});
}