Reputation: 347
I am looking for a way to build a collection of categories and sub categories for a market place in Cloud Firestore, I wan to create an Categories and inside every category Map each category with key value pairs, basically a tree stucture. Something similar to down below
Category 1 ----- > Array
0 map
Field ----> String -----> Value
Field----->String------> Value
1 map
Field ----> String -----> Value
Field----->String------> Value
var results = [
'Category 1' = [
{field: string , field: string, field: int}
{field: string , field: string, field: int}
{field: string , field: string, field: int}
'Category x'= [
{field: string , field: string, field: int}
{field: string , field: string, field: int}
]
]
];
This is not a code, this is just the type of structure I am looking for to create in cloud firestore, I am also attaching an image as how to structure will look on cloud firestore.
Upvotes: 0
Views: 1430
Reputation: 854
var result = {
"result": {
"category1": [
{
"field1": "string",
"field2": "string",
"field3": 10
},
{
"field1": "string",
"field2": "string",
"field3": 10
},
{
"field1": "string",
"field2": "string",
"field3": 10
},
{
"category2": [
{
"field1": "string",
"field2": "string",
"field3": 10
},
{
"field1": "string",
"field2": "string",
"field3": 10
}
]
}
]
}
};
//save to firestore
Firestore.instance.collection(id).document().setData(result);
Upvotes: 1