Meteor-Community-Packages / meteor-publication-collector

Test a Meteor publication by collecting its output.
https://atmospherejs.com/johanbrook/publication-collector
MIT License
33 stars 20 forks source link

Error when using findOne() in publication #1

Closed Kymer closed 8 years ago

Kymer commented 8 years ago

When using a findOne() query like so:

Meteor.publish('event', (id) => {
    return Events.findOne({_id: id})
})

I get an error when I try to call collect() on a publication collector:

Error: Object [object Object] has no method '_publishCursor'
    at packages/johanbrook:publication-collector/publication-collector.js:33:44

I realize findOne() doesn't return a cursor, but a document. For now I can use a regular find() query in the publication as a temporary workaround. Any suggestions on how to fix this issue?

johanbrook commented 8 years ago

Is it even allowed to return a non-cursor (when not calling this.ready()) in a subscription?

Kymer commented 8 years ago

Hmm good point. The Meteor docs do kind of state it should be either of 2 things:

  1. A cursor
  2. An array of cursors (of different collections)

Publish functions can return a Collection.Cursor, in which case Meteor will publish that cursor’s documents to each subscribed client. You can also return an array of Collection.Cursors, in which case Meteor will publish all of the cursors.

It does not explicitly say it is forbidden, but perhaps it's best to avoid returning the result of a findOne() query then. Consider the issue closed :)

johanbrook commented 8 years ago

:) Yeah, findOne is returning a document (plain object), so I think it's kinda forbidden. Thanks anyway!