firebase - admin.ref.on() is not working while once() works perfectly -


i found strange problem documented feature seems not working.

i have working code:

exports.getevents = functions.https.onrequest((req, res) => {  cors(req, res, () => {     admin.database().ref('events').orderbyvalue().once('value', function(snapshot) {          res.status(200).send(snapshot.val());      }).catch(error => {         console.error('error while reading data', error);         res.status(403).send('error: ' + error);     }); 

when change once() on() errors.

what want achieve have server send new json payload when there changes eventssince have app reads events.json directly , can use link provide data (so sdk functions out). doing wrong?

error log:

typeerror: admin.database(...).ref(...).orderbyvalue(...).on(...).catch not function @ cors (/user_code/index.js:24:11) @ cors (/user_code/node_modules/cors/lib/index.js:188:7) @ /user_code/node_modules/cors/lib/index.js:224:17 @ origincallback (/user_code/node_modules/cors/lib/index.js:214:15) @ /user_code/node_modules/cors/lib/index.js:219:13 @ optionscallback (/user_code/node_modules/cors/lib/index.js:199:9) @ corsmiddleware (/user_code/node_modules/cors/lib/index.js:204:7) @ exports.getevents.functions.https.onrequest (/user_code/index.js:19:2) @ cloudfunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:47) @ /var/tmp/worker/worker.js:635:7 

you've tried add .catch end of statement. .on doesn't support function.

see sample code below should fix issue.

admin.database().ref('/somepath')   .orderbyvalue()   .on('child_added', (snapshot, prevchildkey) => {      console.log(snapshot.val()); // json    }, err => {      // error thrown here - not in .catch   }); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -