问题描述
我想在sampleData集合中添加多个文档吗?另外,sampleData上有一个serverTimeStamp属性,我该如何添加它.
I want to add multiple documents in the sampleData collection?Also, there is a serverTimeStamp property on the sampleData, how can I add this as well.
sampleData看起来像:
sampleData looks like:
名称:字符串
serverTimeStamp:serverTimeStamp
serverTimeStamp: serverTimeStamp
标签:数组[]
exports.newUserSignup = functions.auth.user().onCreate((user) => {
const p1 = admin.firestore().collection('users').doc(user.uid).collection('score').add({
gems: 0,
})
const p2 = admin.firestore().collection('users').doc(user.uid).collection('sampleData').add({
...
});
return Promise.all([p1, p2]);
})
推荐答案
到添加文档,您可以使用.doc().set(...),也可以使用.add(...)(完全等效).
To add a document you may use .doc().set(...) or as in your case .add(...), which are completely equivalent.
如果要添加多个文档,则可能需要考虑批量写入.因为您将能够作为一个批处理执行多个写操作,而这些批处理包含set(),update()或delete()操作的任意组合.可以通过此文档.
If you are looking to add multiple documents, you may want to consider batch writes. As you would be able to execute multiple write operations as a single batch that contains any combination of set(), update(), or delete() operations. More information can be found through this documentation.
这篇关于在云功能中添加多个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!