1db.collection("cities").add({
2 name: "Tokyo",
3 country: "Japan"
4})
5.then(function(docRef) {
6 console.log("Document written with ID: ", docRef.id);
7})
8.catch(function(error) {
9 console.error("Error adding document: ", error);
10});
11
1import * as functions from 'firebase-functions';
2import * as admin from 'firebase-admin';
3admin.initializeApp(functions.config().firebase);
4
5exports.onMsgAdded = functions.database.ref('/users/{uid}/messages/{to_uid}/{msg}').onCreate((snap, context) =>{
6 const data = snap.val();
7 const msgRoot = admin.database().ref('/users/' + context.params.to_uid + '/messages/' + context.params.uid);
8 return msgRoot.set(data);
9});