Provide .exists on cursors
mitar opened this issue · 3 comments
One thing I am missing (from Django) is .exists()
query, which would make an optimized query and tell you if the query matches any document. Doing .count()
instead is very bad because you do not really need/want precise number (and counting a precise number is not very cheap in MongoDB).
Related: meteor/meteor#1504
It would be also good to have observeExists
as a special case for when you just want to observe existence of a document in a reactive way.
Probably this could be just a wrapper around observeChanges
with limit of fields only to _id
. But maybe this could be made more efficiently.
This is where a database like RethinkDB is very good because basically it allow you to subscribe to any query. So for instance if you subscribe to a count()
the database will only inform the subscriber when this number change and we don't have to subscribe to all matching document and count() them ourselves. It works for all reduce operations, as exists
.
I understand that this suggestion is about minimongo but I just wanted to underline this feature of RethinkDB here. So about your suggestion itself, do we really need a observeExists
in the observe
callbacks list? Couldn't we simply rely on the .exists()
reactivity (or maybe you think of the server)?
You are right. Much better than observeExists
it would be if .count()
would be reactive on the server as well. So yes, I am interested in publishing count()
in a reactive way to the client in an efficient way. Or publishing things like .exists()
.
Maybe the question is more: we should have reactive queries on the server as well.