firebase add to document code example
Example 1: firestore set a document
let data = {
name: 'Los Angeles',
state: 'CA',
country: 'USA'
};
let setDoc = db.collection('cities').doc('LA').set(data);
Example 2: firebase functions add to database
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp(functions.config().firebase);
exports.onMsgAdded = functions.database.ref('/users/{uid}/messages/{to_uid}/{msg}').onCreate((snap, context) =>{
const data = snap.val();
const msgRoot = admin.database().ref('/users/' + context.params.to_uid + '/messages/' + context.params.uid);
return msgRoot.set(data);
});
Example 3: document.set() firebasefirestore java