1

I have a question about my database structure. I’m making an app where a user records his debts and people that owe him. My current structure is:

{people: {
    person1: {
        name: John
        total: 177
    },
    person2: {
        name: Peter
        total: 67
    },
},
{transactions: {
    person1: {
        {transaction1: { amount: 100 },
        {transaction2: { amount: 77 }
    },
    person2: {
        {transaction1: { amount: 7 },
        {transaction2: { amount: 20 }
        {transaction3: { amount: 10 },
        {transaction4: { amount: 30 }
    },
},

Every time a transaction is added or deleted, I update that person's total using ref.transaction().

So, each addition or removal use 2 remote calls.

My question: Am I doing it right?

Ry-
  • 218,210
  • 55
  • 464
  • 476
Ahmad Al Haddad
  • 1,124
  • 10
  • 10
  • If your code works for your use-cases, you are doing it right. If your code doesn't work: post the [minimum code that reproduces the problem](http://stackoverflow.com/help/mcve). If you'd like to explore the possibilities of validating a multi-location update with server-side security rules, see http://stackoverflow.com/questions/37954217/is-the-way-the-firebase-database-quickstart-handles-counts-secure/37956590#37956590 – Frank van Puffelen Aug 15 '16 at 02:45
  • @FrankvanPuffelen I'm asking this just to be cautious not to fall under "Things you shouldn't do in your Firebase database". I don't have any security concerns because I've already configured the rules. – Ahmad Al Haddad Aug 15 '16 at 04:52
  • @AhmedAlHaddad: wouldn't it be better to calculate the total on the client side? – KarolDepka Jan 28 '17 at 23:08
  • @KarolDepka I guess it would. However, I have to change the way I'm fetching data. Because the total is used on a main list, and I only request the transactions once you click on one of the people. – Ahmad Al Haddad Jan 29 '17 at 04:27

0 Answers0