Trouble with search

we have a search form for our customer collection, which allows users to search over multiple fields. Unfortunately it’s plagued by all kinds of problems.

Some issues are:

  • Paste an email into the search field (filter): results won’t show
  • Results which are not already included in the subscription might not show up
  • New customers may not show up in search for as long as a minute or more.
  • Search is generally slow, weird, buggy (same search, inconsistent results)

Originally we used regex in the subscription but was told it by Atlas we should avoid this because leading wildcard queries won’t use the indexes and this is problem is multiplied for each field queried. So we added the text index but now I think the problem is that the text index may need time to index new entries and also there are slight differences in results which passing the params to the text search for the subscription and when apply those params in regex on the client, and those mismatches result in gaps in the data.

What are most people doing in situations like this?

I use this. Works like a charm.

Hi @maxhodges,

text index in MongoDB is very bad and delivers inconsistent results (in my experience). Instead try to use regex in this format /^word/. This regex will use the normal indices.

Some Notes:

  • Meteor will use polling if the queries are complex, which yields to slower responsiveness. Try to look at your MongoDB Logs. MongoDB logs by default slow queries.
  • Look into Websocket Connection and observe the publish. or use meteor-devtool plugin for chrome
  • If your query using some kind of sort. make sure you are setting the right indices. (See https://docs.mongodb.com/manual/tutorial/sort-results-with-indexes )
  • db.getCollection(‘Collections’).find({field: /K/}).explain() can tell you if the query will use indices or not.
  • smaller document will increase the speed of publishing ( Hint: consider using projections).

Questions:

  • do you use Limit?
  • do you filter on multiple fields at the same time?
  • is the server instance far from meteor instance?

Good luck! :blush: