Home > database >  How can I create custom options for every category?
How can I create custom options for every category?

Time:11-03

I have 2 categories in Cloud Firestore and the structure looks like this:

Categories (Collection)
|
--- 6FbwakI8Jh8Pst79kEV8 (Document)
    |
    --- Category Name (String) => "Cars For Sale"
--- nMWCgN7g9hZsMaeJPLRj (Document)
    |
    --- Category Name (String) => "Cars For Rent"

How can I create custom options for every category like the images below:

Image 1: Cars For Sale
Image 2: Cars For Rent

There are different options for every category and I want to know how can I create something like this using Firebase Firestore inside my categories?

The URL if you want to check by yourself.

CodePudding user response:

The simplest solution I can think of is to create two separate collections for each type of operation, like this:

Firestore-root
   |
   --- Cars For Sale (collection)
   |     |
   |     --- //Options in the first screenshot
   |
   --- Cars For Rent (collection)
         |
         --- //Options in the second screenshot

Since a query may always return documents from a single category, then this schema is the simplest one.

CodePudding user response:

Well, I think you can achieve this, using the following scaffolding. Notice the filters contain category ID which maps the filters to the category. So this way you could create n number of filters and n number of categories.

collection document id document data
categories 6FbwakI8Jh8Pst79kEV8 { name: "Cars For Sale" }
nMWCgN7g9hZsMaeJPLRj { name: "Cars For Rent" }
filters nMWCgN7g9hZsMaeJPLRj { name: "Car Make", value: ["V1", "V2", "V3"], category: 6FbwakI8Jh8Pst79kEV8 }
{ name: "Car Model", value: ["X", "Y", "Z"], category: nMWCgN7g9hZsMaeJPLRJ }

Then you can make use of simple get() queries to get data from the collection.

  • Related