Make find(1) and find({_id: 1}) return the same thing.

This commit is contained in:
Nick Martin
2012-12-14 19:50:32 -08:00
parent 2d9e8a8fd6
commit 33fa24e912
2 changed files with 10 additions and 2 deletions

View File

@@ -70,9 +70,9 @@ LocalCollection.Cursor = function (collection, selector, options) {
} else {
this.selector_f = LocalCollection._compileSelector(selector);
this.sort_f = options.sort ? LocalCollection._compileSort(options.sort) : null;
this.skip = options.skip;
this.limit = options.limit;
}
this.skip = options.skip;
this.limit = options.limit;
// db_objects is a list of the objects that match the cursor. (It's always a
// list, never an object: LocalCollection.Cursor is always ordered.)
@@ -260,6 +260,12 @@ LocalCollection.Cursor.prototype._getRawObjects = function (ordered) {
// fast path for single ID value
if (self.selector_id) {
// If you have non-zero skip and ask for a single id, you get
// nothing. This is so it matches the behavior of the '{_id: foo}'
// path.
if (self.skip)
return results;
if (_.has(self.collection.docs, self.selector_id)) {
var selectedDoc = self.collection.docs[self.selector_id];
if (ordered)

View File

@@ -124,6 +124,8 @@ Tinytest.add("minimongo - basics", function (test) {
test.equal(c.find("abc").count(), 0);
test.equal(c.find(undefined).count(), 0);
test.equal(c.find().count(), 3);
test.equal(c.find(1, {skip: 1}).count(), 0);
test.equal(c.find({_id: 1}, {skip: 1}).count(), 0);
// Regression test for #455.
c.insert({foo: {bar: 'baz'}});