Firestore queries where() . - returning unexpected results

Viewed 40

Objective

User needs to be able to lookup a name of a person based on first name within the database. User will have an input field where once they type 3 letters this will search Firestore objectes where firstname contains the searched value.

My setup

  • Call redux action once I receive new props.
  • Query Firestore with this value if length is greater than 3.
  • Pushed the records into an array and add this as a payload to my reducer
  • This reducers state is mappedToProps.
  • Show results data in the component.

Problem

The returned objects from Firestore do not seem to match the logic of my query. I am doing a match >= comparing the search value to the firstname value. However, when I type Joe I get both "John Doe" and "Patty O'chair".

Redux Action

export const queryBidder = (value) => {
  return async (dispatch, getState, { getFirestore }) => {
    const firestore = getFirestore();
    const normalizeValue = _.capitalize(value);
    let Query = []
    if(value.length >= 3) {
        await firestore.collection("bidders").where('firstname', ">=", normalizeValue).get()
    .then(snapshot => {
      if (snapshot.empty) {
        console.log('No matching bidders.');
        return;
      }  
      snapshot.forEach(doc => {
        console.log("search by", normalizeValue)
        console.log("firstname returned,", doc.data());
        Query.push(doc.data());
      });
      dispatch({ type: actionTypes.QUERYBIDDER, Query: Query });
    })
    .catch(err => {
      console.log('Error getting documents', err);
    });
    } else {
      dispatch({ type: actionTypes.CLEARQUERY });
    }
  }
};

Questions

I have done some reading and it appears Firestore is not meant for this sort of behavior. At a minimum can it do what I am asking for here and I am just doing it wrong?

If not, what are some options I have here? I am expecting to have around 100 people to query regularly by 10 users, should I just return all the data and query on the front-end? I don't really have time to learn how to integrate with elastic search and this also might be a bit too much for such a small application at this time.

0 Answers
Related