最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firebase function to return Json - Stack Overflow

programmeradmin3浏览0评论

It is a simple requirement - how do I return the entire json from a firebase database.

My function is as such [index.js]

const functions = require('firebase-functions');

const admin = require('firebase-admin');
var serviceAccount = require('./xxMyKeyxx.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: ''
});


exports.myQuery = functions.https.onRequest((req, res) => {
  // Grab the text parameter.
  const original = req.query.text;


  return admin.database().ref('/myFbDatabase').once.xxx
  I lost it from here. 

what is the syntax to return the Json that is sitting in my FB database /myFbDatabase ? });

It is a simple requirement - how do I return the entire json from a firebase database.

My function is as such [index.js]

const functions = require('firebase-functions');

const admin = require('firebase-admin');
var serviceAccount = require('./xxMyKeyxx.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: 'https://xxmyProjectxx.firebaseio.'
});


exports.myQuery = functions.https.onRequest((req, res) => {
  // Grab the text parameter.
  const original = req.query.text;


  return admin.database().ref('/myFbDatabase').once.xxx
  I lost it from here. 

what is the syntax to return the Json that is sitting in my FB database /myFbDatabase ? });

Share Improve this question edited Feb 24, 2018 at 18:32 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges asked Feb 24, 2018 at 18:18 ChzDzChzDz 1911 gold badge1 silver badge11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

Subscribing to the 'value' event will give you the entire database

exports.myQuery = functions.https.onRequest((req, res) => {
   // Grab the text parameter.
   const original = req.query.text;

   admin
     .database()
     .ref('/myFbDatabase')
     .once('value', 
       snap =>  res.json(snap.val()),
       err => res.json(err)
     )
})
发布评论

评论列表(0)

  1. 暂无评论