I am a beginner with Google Firebase and Cloud Functions, and I recently attempted a basic "hello world" program:
- Established a connection to Cloud Firestore [beta], which contains over 100,000 records.
- Retrieved the top record from the database.
Below is the code snippet used:
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
console.log(mydump(functions.config().firebase));
admin.initializeApp(functions.config().firebase);
exports.helloWorld = functions.https.onRequest((request, response) => {
const tokens = [];
const html = [];
var oldItemsQuery = admin.database().ref();
html.push("==============begin========================");
return oldItemsQuery.once('value').then(snapshot => {
console.log("once value, snapshot key:" + snapshot.key
+",val:" +snapshot.val()
+",hasChild/profile:" +snapshot.hasChild("profile")
+",hasChild/everyday:" +snapshot.hasChild("everyday")
+",numChildren:" +snapshot.numChildren()
+",toJSON:" +snapshot.toJSON()
);
html.push("============end===================");
response.send(html.join("<br>\n"));
});
});
Although my code seems simple, the result was not as expected when accessing the URL in my browser here.
The following error message appears in the console:
once value, snapshot key:null,val:null,hasChild/profile:false,hasChild/everyday:false,numChildren:0,toJSON:null
It indicates that there are no records in my database. I have tried different queries, but the outcome remains the same.
Thank you for your assistance. I've been struggling with this issue for three days now.