percolatestudio / publish-counts

Meteor package to help you publish the count of a cursor, in real time
https://atmospherejs.com/tmeasday/publish-counts
MIT License
200 stars 46 forks source link

Undefined object exception when using local collections. #61

Closed boxofrox closed 9 years ago

boxofrox commented 9 years ago

In #35, @jjman505 writes:

So I tried the example from @boxofrox, with minor changes here: https://gist.github.com/jjman505/edd91510eeb8b27d9853

I get the following error:

Exception from sub pendingReview id CCtvre3cA73bFozdb TypeError: Cannot read property 'options' of undefined
     at Object.Counts.publish (packages/tmeasday:publish-counts/publish-counts.js:42:1)
     at [object Object]._handler (app/server/publications.js:51:16)
     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1)
     at [object Object]._.extend._runHandler (packages/ddp/livedata_server.js:950:1)
     at [object Object]._.extend._startSubscription (packages/ddp/livedata_server.js:769:1)
     at [object Object]._.extend.protocol_handlers.sub (packages/ddp/livedata_server.js:582:1)
     at packages/ddp/livedata_server.js:546:1

A local collection is defined as new Mongo.Collection(null) (see Meteor Docs).

Apparently local collections don't define a _cursorDescription property on their cursors.

Suggested fix: skip field specifier optimization if _cursorDescription is undefined.

PR to follow after consensus.

CC @tmeasday, @dburles

tmeasday commented 9 years ago

Makes sense to me