【发布时间】:2018-08-20 20:12:21
【问题描述】:
【问题讨论】:
标签: android firebase kotlin google-cloud-firestore
【问题讨论】:
标签: android firebase kotlin google-cloud-firestore
当您创建/获取文档参考时,您可以将其保存到另一个文档中。此示例适用于 Node SDK,但它应该让您了解如何在 Android 上实现它。
// Create the references
let myFirstDoc = db.collection('myCollection').doc();
let mySecondDoc = db.collection('otherCollection').doc();
let batch = db.batch();
// Save the two documents to the batch
batch.set(myFirstDoc, {someData: true});
batch.set(mySecondDoc, {firstDocRef: myFirstDoc});
// Commit the batch
return batch.commit()
.then(response => {
console.log('Data saved');
})
.catch(err => {
console.error(err);
});
return db.collection('myCollection').doc('myDocId')
.then(documentSnapshot => {
let newDoc = db.collection('otherCollection').add({otherDoc: documentSnapshot.ref});
})
.then(response => {
console.log('Data saved');
})
.catch(err => {
console.error(err)
})
【讨论】: