I've created Firebase project and added some data to Realtime Database? I also created cloud functions by using console. This is my following code
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.addMessage = functions.https.onRequest(async (req, res) => {
const snapshott = await admin.database().ref('/messages').push({"original":"ZXz"});
res.send("assasin")
});
exports.getMessage = functions.https.onRequest(async (req, res) => {
const snapshott = await admin.database().ref('/messages').get();
res.send(snapshott)
});
The addMessage
function works fine but getMessage
function gives an error.
This is the following error
TypeError: admin.database(...).ref(...).get is not a function
at exports.addMessage.functions.https.onRequest (/srv/index.js:15:60)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
So how can I get Realtime Database in Firebase by using cloud function?