How can I store data under/retrieve from a sub-bucket in a Firebase project bucket?

Hey everyone, I hope you are doing good!
I feel really glad to be back here after a very long time :grinning::wave:

I am developing a project in which this time I’ve chosen Firebase as my main database (this is my first time working with firebase). In this project, I mainly have two things I need to store - stores & their orders. So I needed a data structure format that would make it easy for me to retrieve any order data easily.

I’ve come up with a database format idea that looks like this :

Let me explain the whole workflow. When someone posts an Order, the Order ID becomes a sub-bucket key, and the order’s details are that sub-buckets’ items. Ultimately, the order gets stored as a sub-bucket under the main bucket of the store.

Now, since it’s my first time using Firebase, I am kind of confused with creating a new sub-bucket (with items in it) under a main bucket of the Store, and how to retrieve any Order’s (sub-bucket’s) details later. I’ve so far tried many combinations of blocks I could possibly think of, and it doesn’t seem to work out. Can you please guide me?

Thanks a lot for reading! :grinning:

1 Like

One quick and easy way to check you data is to add a List Viewer to your screen and in the code add the following in the screen open or button click

This will give you a list of Orders in your database.

You can then use the Item Click of the List Viewer to show more details about the selected order in labels. Such as


Hope this helps.


Thanks a lot, @muneer! Really appreciate your help. I will surely try this out ASAP.
Just a quick doubt, do I need to initialize any cloud variable or just grab image and add name of the bucket in front of it? Just to know, I have my Firebase connected to my app.


1 Like

Initializing a cloud variable can result in overwriting the contents of the Firebase bucket.

When dealing with Firebase, always use the variables listed at the bottom of the variables drawer. Those do not require initializing and the text part of the variable refers directly to the key in Firebase.


Hi, @muneer!

Thankfully, I found my whole solution :

  • For storing data under a sub-bucket (inside a main bucket), I used this command : (the / was inspired from your given blocks :slightly_smiling_face:)


    Also, for the items in the sub-bucket, I used a create object block which includes all the keys and values of the order details. I can now finally store in the format I desired :grinning:


  • For retrieving data, I used the method you gave : (textbox1 being store id & textbox2 being order id)


This whole thing worked like a charm. Huge thanks to you for helping me out! :grinning::grinning_face_with_smiling_eyes:

Thanks a lot!


Great work.

Just a recommendation. To update the bucket key or sub-key use this block instead of the SAVE block to have consistency in your code.

Of course you will select the variable type as cloud, the bucket sub-key will be in the “name” space and the value of the key in the “to” empty space.