向Firestore中已存在的文档添加新集合的Cloud Functions [英] Cloud Functions that add a new collection to the already existing document in firestore
本文介绍了向Firestore中已存在的文档添加新集合的Cloud Functions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将新集合添加到Firestore中已经存在的文档中,这可能吗?以下是执行此操作的代码,我使用了云功能来进行此操作.每当在Firestore中创建文档时,以下云功能都必须触发
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()
推荐答案
尝试一下:)
return db.collection('Samyata').doc(ID).collection('Wallet').doc(ID).set(data);
这篇关于向Firestore中已存在的文档添加新集合的Cloud Functions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文