Search code examples
searchmeteorreact-nativelive

Live search React-Native + Meteor


I am wondering what is the best way to make a live search using Meteor and React-Native.

So we should do the search inside a MongoDB collection.

What is the best way? Subscribe everytime the text change? Subscribe once and get all the data and in local filter the data? ...

Thanks!


Solution

  • Depends on the size of the collection to be searched.

    • If it is very large, use a subscription with the search string as a parameter. However, throttle the searches so as to only search every 500ms or so. You typically don't need to search on every single character typed.
    • If the collection is small, just subscribe to the whole thing and run the search on the client.

    A variation of client-side search is that you just publish the field that you're going to search on then when the document is found you subscribe to a publication that gives you the rest of the fields for that one document.