I read Dan McGrath's answer from this question in which he says that in Firestore there is an equivalent for the following line of code:
myRef.startAt(searchText).endAt(searchText + "\uf8ff");
This line works perfect in Firebase Realtime database but I'm trying to find the equivalent in Cloud Firestore for days. Can anyone help me with that?
Thanks in advance!
Use the startAt() or startAfter() methods to define the start point for a query. The startAt() method includes the start point, while the startAfter() method excludes it. For example, if you use startAt(A) in a query, it returns the entire alphabet. If you use startAfter(A) instead, it returns B-Z .
A DocumentReference refers to a document location in a Firestore database and can be used to write, read, or listen to the location. The document at the referenced location may or may not exist. A DocumentReference can also be used to create a CollectionReference to a subcollection.
Cloud Firestore caches data that your app is actively using, so the app can write, read, listen to, and query data even if the device is offline.
You have a couple of options.
You can add query filters using the .where
keyword. Take a look at Order and Limit Data with Cloud Firestore
If you want to use cursors for paginating data, take a look at Paginate Data with Query Cursors
You need to specify which field you are wanting to search. For example, if you're looking for all documents with a name
containing the searchText
you will need to add an orderBy
parameter.
myRef.orderBy("name").startAt(searchText).endAt(searchText + "\uf8ff");
This assumes that your myRef
is a reference to a collection.
you find the solution, maybe you confuse, just change this " with single quotes (') and it will works perfectly thanks for the other post it helps me too. I leave my code here:
FirestoreRecyclerOptions <Ingreso> newoptions = new FirestoreRecyclerOptions.Builder<Ingreso>()
.setQuery(fStore.collection("DatosEmpresa").orderBy("DepartamentoEmpresaLoweCase").startAt(newText.toLowerCase()).limit(25).endAt(newText.toLowerCase()+'\uf8ff'),Ingreso.class)
.build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With