0

We are using Firestore database. In our Car List we have different Brands. Each of the brands has the same attributes with different values. We want to filter the car and one or more attributes. We dont want to download all the data and filter on client side.

We have already tried using the following code:

constructor(
        private afs: AngularFirestore
    )
....


return new Promise<CarModel>((resolve, reject) => {
        var carCollection = this.afs.collection<Car>('Cars', ref =>
        ref
        .where('Driver', '==', 'Man')
        .where('Location', '==', 'Switzerland'));

We would like to have a list with multiple entries and the same attributes driver and location we've filtered.

firestore car sample

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
FoxDev
  • 1
  • 1
  • Firebase Database queries can only order/filter on a single property. In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. For an example of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Jun 10 '19 at 15:21
  • Note that the syntax you use in your code is for [Cloud Firestore](https://firebase.google.com/docs/firestore), not for the [Realtime Database](https://firebase.google.com/docs/database). While both databases are part of Firebase, and both are NoSQL databases, they are complete separate and their APIs are different. You might want to make sure you're in the correct section of the documentation when looking for the API. – Frank van Puffelen Jun 10 '19 at 15:23
  • We saw the answer but we did not expect, that it can become so complicated. The syntax and asynchronous issues are not easy to get it work. Is there any simple solution for this new ionic4 framework? – FoxDev Jun 10 '19 at 15:29
  • The underlying database is the same, no matter what platform you use it on. But you now edited your question to be about Firestore, in which case the duplicate does not apply. What's the problem you're having with the code you shared? – Frank van Puffelen Jun 10 '19 at 15:57
  • You can try [FireSQL](https://github.com/jsayol/FireSQL) or [linq2fire](https://github.com/linq2js/linq2fire) – Art Olshansky Jun 14 '19 at 06:22

0 Answers0