Firebase realtime database suddenly not working?

979 views
Skip to first unread message

Jessica Ross

unread,
Mar 3, 2017, 2:41:41 PM3/3/17
to Firebase Google Group
Hi,

I am new to Firebase Realtime Database.

I have a testbed set up that was working yesterday with AWS Lambda.
I came back today to continue testing and suddenly all of my data 
was overwritten by the attached (just the document path) and no data underneath it.
Additionally, the lambda hangs after 30 seconds because the promise never terminates.

Each time I attempt to try it again, the previous data is overwritten by something like the 
attached.

The code looks something like this like this, with some edits. This code is in turn 
used in an AWS Lambda.

const firebase = require('firebase');

firebase.initializeApp({
    apiKey: process.env.FIREBASE_API_KEY, 
    authDomain: process.env.FIREBASE_AUTH_DOMAIN,
    storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
    databaseURL: process.env.FIREBASE_URI,
});


exports.create = (docType, doc, docId) => {
     return new Promise((resolve, reject) => {
        const firebaseDb = firebase.database();
        const id = docId ? docId : uuidV4();
        const timestamp = moment().utc().format();
        const document = Object.assign({}, doc, { id: id }, { created_at: timestamp }, { updated_at: timestamp });

        // create promises promise1, promise2 that write to two other datastores
        const firebaseSetPromise = firebaseDb.ref().set(`${docType}/${docId}`)
            .set(document);

        Promise.all([promise1, promise2, firebaseSetPromise])
            .then(results => {
                resolve(document);
             })
            .catch(err => {
                reject(err);
            });
       });
   }

The document is definitely there. This function writes to two other data stores that are successfully written to.
Please help? I am very confused.

Thanks,
Jess
what.png

Alex Memering

unread,
Mar 3, 2017, 2:52:29 PM3/3/17
to fireba...@googlegroups.com
So you've defined a root reference with const firebaseDb = firebase.database();.  However it appears that you intend to be using child instead of set when you're creating firebaseSetPromise.  You're unintentionally setting your root to be the path that you're intending to set to the value of the document.  It should be something like:

const firebaseSetPromise = firebaseDb.ref().child(`${docType}/${docId}`).set(document);

The documentation for the Admin SDK of the RTDB is here (this is mainly for other people that come across this thread, since you seem to already have a great handle on this).

Hope that helps,
Alex


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/a13a8a0a-a552-416c-b078-fd7c5e6c8aac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Alex Memering | Software Engineer | meme...@google.com
Reply all
Reply to author
Forward
0 new messages