-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Add isEmpty to cursors #1504
Comments
What do you exactly mean by isEmpty method on cursors? What cursors? Do you want to check if element has any children? |
+1 @ankurp - Mitar is talking about the minimongo cursors defined by the Collections API. |
@awatson1978 Thanks for clarifying. Let me take a look at it as it seems something I can add. |
OK, but this is needed to do it performance wise. Current approach (calling count or fetching one document) is simply too much work to just know if collection is empty or not. This is not just a syntactic sugar because it cannot be implemented without support in Meteor. |
@mitar doesn't |
How do you think that the framework would implement "isEmpty" other than as "findOne, no fields"? |
MongoDB has hasNext call. I think this would be best to use it? If it |
For findOne you need both to set fields to none and disable any possibly defined transformation. Additionally, it is also question how reactivity is then applied. You would want that reactivity is triggered only when empty state changes and not necessary when first document changes or when count changes. |
hasNext is not part of the Node driver interface. And I'm reasonably sure that as far as efficiency goes, it's equivalent to findOne. |
Hm, you are right. |
@glasser I can't find the syntax for "no fields" in the meteor documentation or the mongo documentation. Naive attempts like |
@jagill |
@Slava that's what I've been doing, but reactivity will be triggered if findOne finds a different document, right? I think that's an acceptable cost most of the time, tho. |
@jagill right, it can retrigger if it finds a different document, however it is easy to work-around this behavior if you store the previous result of |
@Slava cool, thanks! |
Please provide a
isEmpty
method on cursors. Currently there are two ways to do it: usecount()
or fetch one element and see what you get. ButisEmpty
could probably be much simpler and faster than any of those. Counting exact count just to know if there is any element is not the best either.The text was updated successfully, but these errors were encountered: