From 673a285dfc40aa34993ec3342d068b7ac16fbc0d Mon Sep 17 00:00:00 2001 From: Emily Stark Date: Wed, 30 Apr 2014 15:53:59 -0700 Subject: [PATCH] Allow undefined values in Collection.find options check. At some point we might want to just make `Match.Optional` accept explicit undefined values in objects, but that will take a little more thought. --- packages/mongo-livedata/collection.js | 10 +++---- .../mongo-livedata/mongo_livedata_tests.js | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/packages/mongo-livedata/collection.js b/packages/mongo-livedata/collection.js index f7a0626ce3..474d269333 100644 --- a/packages/mongo-livedata/collection.js +++ b/packages/mongo-livedata/collection.js @@ -210,11 +210,11 @@ _.extend(Meteor.Collection.prototype, { return { transform: self._transform }; } else { check(args[1], Match.Optional(Match.ObjectIncluding({ - fields: Match.Optional(Object), - sort: Match.Optional(Match.OneOf(Object, Array)), - limit: Match.Optional(Number), - skip: Match.Optional(Number) - }))); + fields: Match.Optional(Match.OneOf(Object, undefined)), + sort: Match.Optional(Match.OneOf(Object, Array, undefined)), + limit: Match.Optional(Match.OneOf(Number, undefined)), + skip: Match.Optional(Match.OneOf(Number, undefined)) + }))); return _.extend({ transform: self._transform diff --git a/packages/mongo-livedata/mongo_livedata_tests.js b/packages/mongo-livedata/mongo_livedata_tests.js index ff86e576a9..48cc187fc8 100644 --- a/packages/mongo-livedata/mongo_livedata_tests.js +++ b/packages/mongo-livedata/mongo_livedata_tests.js @@ -2925,3 +2925,32 @@ Meteor.isServer && Tinytest.add("mongo-livedata - cursor dedup stop", function ( // would print the error and no longer does. // See https://github.com/meteor/meteor/issues/2070 }); + +testAsyncMulti("mongo-livedata - undefined find options", [ + function (test, expect) { + var self = this; + self.collName = Random.id(); + if (Meteor.isClient) { + Meteor.call("createInsecureCollection", self.collName); + Meteor.subscribe("c-" + self.collName, expect()); + } + }, + function (test, expect) { + var self = this; + self.coll = new Meteor.Collection(self.collName); + self.doc = { foo: 1, bar: 2, _id: "foobar" }; + self.coll.insert(self.doc, expect(function (err, id) { + test.isFalse(err); + })); + }, + function (test, expect) { + var self = this; + var result = self.coll.findOne({ foo: 1 }, { + fields: undefined, + sort: undefined, + limit: undefined, + skip: undefined + }); + test.equal(result, self.doc); + } +]);