I get this error in my cloud function
Error: Reference.set failed: First argument contains NaN in property 'server.saving-data.fireblog.history.newid.Id'
at validateFirebaseData (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:1497:15)
at /workspace/node_modules/@firebase/database/dist/index.node.cjs.js:1534:13
at each (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:554:13)
at validateFirebaseData (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:1517:9)
at /workspace/node_modules/@firebase/database/dist/index.node.cjs.js:1534:13
at each (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:554:13)
at validateFirebaseData (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:1517:9)
at validateFirebaseDataArg (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:1475:5)
at Reference.set (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:13928:9)
at /workspace/index.js:44:20
the js code that i have typed is as follows
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
var db = admin.database();
var ref = db.ref("server/saving-data/fireblog");
exports.addHistory = functions.database.ref('issue/{id}').onCreate(async (snapshot, context) => {
const val = snapshot.val();
var lastid;
return admin.database().ref('history').orderByChild("Id").limitToLast(1).on("child_added", function (snapshot) {
snapshot.forEach(function (data) {
lastid = data.val().Id;
});
const timeElapsed = Date.now();
const today = new Date(timeElapsed);
var datetime=today.toUTCString();
var newid = lastid + 1;
var usersRef = ref.child("history");
usersRef.set({
newid: {
Lamp: val.Id,
Reported: datetime,
Completed:"",
Status:"Pending",
AssignedTo:"",
Id:newid
}
});
});
});
This is where i need to add record So i get the last Id in the current case is 2 and increment by 1 making 3 and add a new record with key 3
Rules have been set

