Structuring Firebase Firestore for E-commerce Filter Feature

As the name says, I want to achieve filter functionality using the E-Commerce application, completely built on Firebase Firestore.

The filter may be too complicated, for example: - A list of products (e.g. phones) with

- price range between 10k - 20k
- Brands among Samsung, Motorola and Apple
- OS should be Marshmallow, Nougat or Oreo
- RAM should be 3GB, 4GB or 6GB

Since complex queries are not possible directly, it is clear that I need to restructure my database. Please help me with the restructuring, or if you have any other suggestions, I would love to hear.

At the moment I did

FirebaseFirestore.getInstance()
    .collection("products")
    .whereGreaterThanOrEqualTo("price", 10000)
    .whereLessThanOrEqualTo("price", 20000)
    .whereEqualTo("brand", "Samsung")
    .whereEqualTo("brand", "Motorola")
    .whereEqualTo("brand", "Apple")
    .whereEqualTo("OS", "Marshmallow")
    .whereEqualTo("OS", "Nougat")
    .whereEqualTo("OS", "Oreo")
    .whereGreaterThanOrEqualTo("RAM", 3)

Obviously, this will not work, because Firestore supports Logical AND , it does not support Logical OR, and does not combine. So, what could be a restructured way of modeling data to achieve this?

0

Source: https://habr.com/ru/post/1687764/


All Articles