Div*_*lla 2 node.js google-cloud-functions google-cloud-firestore
我想将新集合添加到 firestore 中已存在的文档中。这可能吗?以下是执行此操作的代码,我使用云函数来执行此操作。每当在 firestore 中创建文档时,就必须触发以下云函数
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()
Run Code Online (Sandbox Code Playgroud)
尝试这个 :)
return db.collection('Samyata').doc(ID).collection('Wallet').doc(ID).set(data);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2961 次 |
| 最近记录: |