Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
862 views
in Technique[技术] by (71.8m points)

ios - Set a maximum number of children in Firebase

There are some other (older) questions about this, but since they already are a few years old, I am curious if there have been an update about this. I want to animate a lottery, in which users can buy tickets. Everything is going well, but I want to make sure there are never more than a thousand sold tickets. It has to be server side, and these are my rules:

  "Lottery": {
    ".read": "auth != null",
    ".write": "auth != null",
      "counter": {
        ".validate": "newData.isNumber() && newData.val() > 0 && newData.val() <= 1000 && ((!data.exists() && newData.val() === 1) || (newData.val() === data.val()+1))"
      },
        "tickets":{
          "root.child('Lottery/counter/').val() === someValueYouNeedItToEqual"
        }
  }

I do not know what to write at someValueYouNeedItToEqual. I am concerned about the working of this system. My goal is to write the user's UID to the server, and gets accepted if the value (I can search client side for available spots, the value can be a Int between 0 and 1000) is free. It should be rejected when all spots are taken (1000 children in a node). I hope someone can help me out figuring out the needed validation rules. Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...