Shivam Gupta
Shivam Gupta

Reputation: 1

firebase real time database validating rules

In realtime database I have child bus_id & its nodes are bus_no, bus_id, bus_time and creationDate as a timestamp. Already I have sorting data using orderBychild(timestamp). I have also implement create/add bus_id if bus_id not exists using rule !data.exists && newData.exists().

Now I want To implement that, update child bus_id if it's created 10 minutes before or update child bus_id if it having timestamp 10 minutes before.

And i will updating data by ref.child(bus_id).setValue(busInfo);

So is there query for invalidating above problem by using ternary operator?

Upvotes: 0

Views: 107

Answers (1)

PradyumanDixit
PradyumanDixit

Reputation: 2375

What I can make out from your question is that, you want to update bus_id child if it has been created 10 mins before otherwise update that bus_id which was created 10 mins ago.

I can suggest you two ways to do so, first is by adding a new timestamp with name timeCreated for every bus_id, then you can retrieve their value, and check if it is 10 mins old or not.

This can let you update the bus_id which is 10 minutes older.

Another way is by by altering the Firebase rules according to your need, as @JeremyW said in the comments.

Some useful resources for that will be, this video, which you should skip to the time 22:55.

Firebase docs regarding this. and this stack overflow question.

Upvotes: 1

Related Questions