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