Skip to content

Instantly share code, notes, and snippets.

@dvv
Created May 4, 2010 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvv/389545 to your computer and use it in GitHub Desktop.
Save dvv/389545 to your computer and use it in GitHub Desktop.
--- mongodb.js.orig 2010-05-04 18:59:13.000000000 +0400
+++ mongodb.js 2010-05-04 19:23:16.000000000 +0400
@@ -110,19 +110,23 @@
} else if (term.name == "select") {
options.fields = term.parameters;
} else if (term.name == "slice") {
- directives.start = term.parameters[0];
- directives.end = term.parameters[1];
+ // DVV: .start/.end MUST be numbers, or .start + a-number will result in string concat
+ // DVV: better to get rid of slice() at all, as it _may_ introduce inconsistency with range set via Range: header. As deanlandolt stated, .slice() is to mimic JS intrinsic Array.slice() and should be chainable. IOW, it doesn't fit to control server-side conditions
+ directives.start = +term.parameters[0];
+ directives.end = +term.parameters[1] + 1; // DVV: slice high bound is exclusive
}
}
// TODO: add support for alternate comparators, sorting, etc.
});
- if(typeof directives.start === "number" || typeof directives.end === "number"){
+ // DVV: typeof NaN === 'number'
+ if(directives.start >= 0 || directives.end >= 0){
var totalCountPromise = callAsync(collection.count, [search]);
}
if(directives.start){
options.skip = directives.start;
}
- if(directives.end){
+ // DVV: .end == 0 is perfectly valid
+ if(directives.end >= 0){
options.limit = directives.end - (directives.start || 0) + 1;
}
return callAsync(collection.find, [search, options]).then(function(results){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment