Hi I want to fetch data from firebase database using firebase cloud function http trigger. Is it possible using functions.database.ref?
你好,我想使用firebase cloud函数http触发器从firebase数据库中获取数据。是否可以使用function .database.ref?
var functions = require('firebase-functions');
var cors = require("cors");
var express = require('express');
var http = require('http');
const app = express()
//~ app.use(cors({ origin: true }))
app.get("/", (request, response) => {
response.send("Hello from Express on Firebase with CORS!")
})
app.get("/:id", (request, response) => {
functions.database.ref('/Users/'+request.params.id)
})
exports.httpFunction = functions.https.onRequest(app);
thanks
谢谢
1 个解决方案
#1
2
You can use Firebase Admin SDK to make database manipulations inside Cloud Functions.
您可以使用Firebase管理SDK在云函数中进行数据库操作。
Rather than using
而不是使用
functions.database.ref()
You can use
您可以使用
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// inside your triggered function
admin.database().ref('path/to/your/ref').on('value').then((snapshot) => { ... })
#1
2
You can use Firebase Admin SDK to make database manipulations inside Cloud Functions.
您可以使用Firebase管理SDK在云函数中进行数据库操作。
Rather than using
而不是使用
functions.database.ref()
You can use
您可以使用
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// inside your triggered function
admin.database().ref('path/to/your/ref').on('value').then((snapshot) => { ... })