0

"firebase": "^9.18.0", "react-native": "0.71.3"

Lets suppose I have this collection: entity

{
    status : 'xy',
    city : {
          name: 'abc',
    }
}

Im trying to achieve this kind of query or some similiar one.

import { app, db, getFirestore, collection, addDoc } from "./firebase-config";
import { getDocs, query, where, orderBy, startAt } from "firebase/firestore";

const entityQuery = query(
        collection(db, 'entity'),
        where("status", "==", "xy"),
        orderBy("city.name"),
        startAt('ab'),
    )

I need to check first of all if the city.name is equal to 'abc' AND status starts with "x"

Of course this query is not correct but im trying only to explain in details my needs. thx in advance.

I need to run this query and perform the first "where" condition AND (all city.name that starts with 'ab')

I searched a lot in stackoverlfow but with no success.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Al2x
  • 1,001
  • 5
  • 26
  • 37

1 Answers1

1

After a lot of googling I finally found this answer from MattT. ty. It worked like a charm.

.orderBy("last_name_upper")
    .where("last_name_upper", ">=", this.searchForm.text.toUpperCase())
    .where("last_name_upper", "<=", this.searchForm.text.toUpperCase() + "\uf8ff")

Firestore database query, ignore case (case insenstive) and like clause

Al2x
  • 1,001
  • 5
  • 26
  • 37