I want to add new collection to a doc that already exists in firestore.Is it possible? The following is the code for doing that, I used cloud fucntions for doing that.Whenever a document is created in firestore then the following cloud function has to trigger
const functions = require('firebase-functions');
const Firestore = require('@google-cloud/firestore');
const firestore = new Firestore();
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.myWallet = functions.firestore
.document('Samyata/{authid}')
.onCreate(event =>{
const ID = event.params.authid
const db = admin.firestore();
var data = {
Bitcoins : '0',
Ether : '0',
deyaCoins : '0'
};
var docRef = db.collection('Samyata').doc(ID);
var updateDoc = docRef.update({
db.collection('Samyata').doc(ID).collection('Wallet').doc(ID).set(data);});
//var updateRef = docRef.update();
});//end of onCreate()
Try this :)