0

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?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Maybe [this link to the Firebase docs](https://firebase.google.com/docs/reference/security/database/#variables) will point you in the right direction, there is a variable called `now` that provides access to the current server time.... so your database will have to include a "*last_modified_datetime*", and compare that against the server time... and see if the difference is less than 10 minutes. – JeremyW Dec 26 '18 at 20:58
  • thankss for replaying but by using timestamp can we write invalidating rule for create/add record or data if not exist and update data/record if it has timestamp before 10. minnute before..??? & how?? – Shivam Gupta Dec 26 '18 at 21:06
  • Yes, you can. Unfortunately I don't have the time to hand-hold you through the whole development process, you'll have to figure that out yourself.... but yes, this will work. – JeremyW Dec 26 '18 at 21:10
  • sir it has single query like !data.exists() || data.exist()...... like that.. but i am confusing, how to implement it in single using operators like !,&&, || so please can you help me what should i do , it must updated if it's timestamp before 10 min...??? i am wating for your reply... – Shivam Gupta Dec 26 '18 at 21:19
  • 2
    @ShivamGupta: Your description of your code is hard to parse. Please have a look at [how to create a minimal, complete, verifiable example](http://stackoverflow.com/help/mcve). Having an MCVE is by far the best way to increase the chances that somebody can help with concrete coding problems such as yours. – Frank van Puffelen Dec 27 '18 at 05:55
  • @ShivamGupta did my answer help you solve your problem? – PradyumanDixit Dec 28 '18 at 10:22

1 Answers1

1

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.

PradyumanDixit
  • 2,372
  • 2
  • 12
  • 20