Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

527
Views
How to filter (search) data from Firebase - React Native

I would like to filter my search term against all the data from the databse.

I think the logic would be: capitalize both searchterm and data, then compare searchterm with each field from the data. Then setData() to that filtered search.

The const Data is used in a flatlist so my filtered data will be shown here.

Thank you for any assistance.

My code:

const SearchFeed = (searchterm) => {


  const q = query(PostsCollectionRef, orderBy('timestamp', 'desc'));

  onSnapshot(q, querySnapshot => {

    const id = querySnapshot.docs.map(doc =>
      ({
        id: doc.id,
        timestamp: doc.data().timestamp,
        postID: doc.data().PostID,
        title: doc.data().status + " " + doc.data().Type,
        status: doc.data().status,
        location: doc.data().location,
        type: doc.data().Type,
        injured: doc.data().Injured,
        collar: doc.data().Collar,
        color: doc.data().Colour,
        username: doc.data().username[0],
        description: doc.data().Description,
        imagesrc: doc.data().picture
      }))

//need to capitalize searchterm
//need to capitalize filter value
//eg id.filter((capitalize(val) => val.type == capitalize(searchterm)

    const Animal = id.filter((val) => val.type == searchterm)
    setData(Animal)
    console.log(Animal)
  });
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since you have all the posts data on client already, you can use a package like Lunr to add full text search functionality in web app. You can use add() method to add data of all documents fetched and then search() to look for documents instead of using a filter().

Do note that you are fetching all the documents from Posts collection every time so that involves lots of read charges. You can algo try using Algolia (with Firebase Algolia Extension). This indexes all the documents added to Firestore in Algolia and then you can directly query data from Algolia based on the search term.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!