Reputation: 21
How to get last 20 records from firebase? I got:
dataset: undefined undefined
My firebase looks like this:
my code
var rootRefData = db.ref().child("users_db/user1/dataset");
rootRefData.once("value", snap => {
var key = snap.key;
var timestamp = snap.val().timestamp;
var log = snap.val().log;
var custom = "";
// create line chart
custom += key + ": " + timestamp + " " + log + "<br />";
console.log(custom);
counter++;
$("#chartsl-container-all").append(custom);
});
Upvotes: 1
Views: 51
Reputation: 80914
Try this:
var rootRefData = db.ref().child("users_db/user1/dataset");
rootRefData.once("value", snap => {
snap.forEach(function (snapshot) {
var key = snapshot.key;
var timestamp = snapshot.val().timestamp;
var log = snapshot.val().log;
var custom = "";
rootRefData
is at node dataset, since you want to get timestamp and log, then you need to iterate inside the randomid using forEach
to be able to get those values and the random id.
Upvotes: 1