New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cursor.forEach Documentation Example Does Not Work #528

Closed
meawoppl opened this Issue Dec 7, 2012 · 6 comments

Comments

Projects
None yet
6 participants
@meawoppl
Contributor

meawoppl commented Dec 7, 2012

In the cursor.forEach example the example code does not run as the description suggests it will, in particular:

"When called in a reactive context, forEach registers dependencies on the matching documents."

This particular example uses limit, and hence the console log will report:

"Uncaught Error: cannot observe queries with skip or limit "

Perhaps not technically wrong, but for certain a bit misleading. As an aside, is there a clean workaround for this? I suppose I can make a server-side collection that is a fraction of the larger one then use that on client side . . .

@gschmidt

This comment has been minimized.

Member

gschmidt commented Dec 10, 2012

@meawoppl, this is a bug. I'm surprised it went uncaught for so long :)

forEach (and other cursor accessors) currently call observe() under the hood to implement reactivity, so they currently don't work on cursors that contain skip and limit clauses when called from inside a reactive context. We will fix this.

Subsetting the data on the server as you suggest is a good workaround if it works in your application (if you don't need to drive two different client-side widgets with the same records with different limits.) The leaderboard example does this, for example.

@glasser

This comment has been minimized.

Member

glasser commented Dec 10, 2012

While this doesn't address your point that the documented example Just Doesn't Work, you can also pass the reactive: false option to find to get a non-reactive cursor which will work with limit and skip. This is only useful if you aren't trying to be reactive, though (eg, you're iterating over something in an event handler, as opposed to iterating over it in a template helper).

@cscott

This comment has been minimized.

cscott commented Dec 11, 2012

Any ETA for implementing reactivity on limit: queries? Google seems to indicate that this has been on the radar since April (http://stackoverflow.com/questions/10157454/meteor-cannot-observe-queries-with-skip-or-limit)

@alex-okrushko

This comment has been minimized.

alex-okrushko commented Dec 15, 2012

Is this .limit() a client-side problem only? It's not working on the server side of me as well.

@n1mmy

This comment has been minimized.

Member

n1mmy commented Dec 18, 2012

This is now implemented on devel in c10dd19, and will be in the next release. Thanks for the report!

@meawoppl

This comment has been minimized.

Contributor

meawoppl commented Dec 26, 2012

Woo Good work and thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment