1

I'm developing a cart and orders screens in a marketplace application using firebase realtime database.

My order Structure:

Firebase order structure

what I want here is retrieving all orders from all users based on its status! and is it a good structure ?

Mohamed ALI
  • 107
  • 12
  • Please post your solution as an answer, instead of an edit to the question. That way people can easily see that the question has been answered, and they can upvote your answer. – Frank van Puffelen Jun 22 '19 at 02:41

1 Answers1

1

I solved this problem by changing the structure of orders:

  1. I remove the node of userId that came next : orders/uid

  2. order structure become orders/order_id/userId

enter image description her

  1. I change order security rules to:

    "Orders":{
      ".read" : true,
        "$id":{
          ".write" : "newData.child('userId').val() === auth.uid",
          ".read" : "root.child('Orders').child($id).child('userId').val() === auth.uid", 
          }     
    }
    

Now I can query what I want by the methods orderByChild() and equalTo()

Mohamed ALI
  • 107
  • 12