7

I am developing a web application using NodeJS & SailsJS frameworks. Now I am going to develop searching functionality. There are around 5000 records from which I want to search on one attribute.

I know I can search it using mogodb query. What if I get all the records in javascript at frontend and search from it? What is good way to search? At backend using db query or at fronend using javascript searching?

user3759750
  • 123
  • 3
  • 10

3 Answers3

7

If you search in the frontend then you have to load the entire dataset into the frontend and keep it synchronised for every query. This is not a good idea.

Use database queries - that is what they are designed for, and you only need to transfer the results.

OrangeDog
  • 36,653
  • 12
  • 122
  • 207
2

It's all about your app and users expectations on it. You definitely shouldn't use client-side search if you have:

  • Short-living data which couldn't be cached (like list of users who are online).
  • Huge dataset which a) couldn't be cached or b) wouldn't be cached (most visitors woudn't use search). But the size limit depends on the app.
  • Complex computation intensive search (like full-text search).

In other cases it can work. And searching even millions of data records could run under 100 ms, what is faster than common network delay required to receive a response from server.

Advantages of client search:

  • fast: no network latency.
  • powerful queries: query can use all JS capabilities with engine optimization advantages.

Disadvantages:

  • load full dataset (critical on huge amounts of data).
  • require synchronization strategy: full reload, partial updates, CRDT, etc.
Paul Rumkin
  • 6,737
  • 2
  • 25
  • 35
0

Do it in backend only using db query, which is good practice.It will reduce execution time.

Should not do this kind of check in client side as you have to send the whole database to client and loop through the records several times to fetch the desired records.

Shrabanee
  • 2,706
  • 1
  • 18
  • 30