Reputation: 894
I am creating an online ticket system where the tickets are pushed and displayed from Firebase. Is there a way to keep track of how many tickets there are?
Upvotes: 1
Views: 4226
Reputation: 894
I actually figured out the answer myself later on.
var ref = new Firebase("https://xxxxxxx/");
var ticketRef = ref.child("tickets");
var count = 0;
ticketRef.on("child_added", function(snapshot) {
var newTicket = snapshot.val();
count++;
});
EDIT Thanks to Frank Van Puffelen, it seems that using firebase's transaction function would be a better course. Sample code
Upvotes: 4