Cloud Functions that add a new collection to the a

2019-04-16 08:11发布

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() 

1条回答
来,给爷笑一个
2楼-- · 2019-04-16 08:41

Try this :)

return db.collection('Samyata').doc(ID).collection('Wallet').doc(ID).set(data);
查看更多
登录 后发表回答