When pushing a new record into a Firebase collection, I want to get the chronological id, a-la MySQL: 0
, 1
, 2
, n - 1
.
Is that possible with Firebase?
Here's the code snippet where I'm inserting a new record:
myCollection.set({
id: id,
foo: "bar"
});
The id
variable should be the number of records - 1
. Is there a built-in solution for that?
What's the best way to do it?
I tried to do:
id = myCollection.numChildren()
But since I don't want to fetch the entire collection in memory (using the once("value", ...)
thingy), myCollection.numChildren
is undefined.
Also, how can we ensure the id is unique?