如何使用Javascript在Cloud Firestore中创建集合? [英] How to create collection in Cloud Firestore from Javascript?
本文介绍了如何使用Javascript在Cloud Firestore中创建集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户在我的角度应用程序中创建帐户时,我的应用程序使用电子邮件和密码创建用户帐户(使用Firebase API).但我也想创建一个新集合来保存更多数据,例如姓名,姓氏...
When user creates account in my angular app, my app creates user account (using Firebase API) with email and password. But also I want to create new collection to hold more data like name, surname...
每个集合的名称将具有uid.
但是我不知道该如何强迫?
db.createCollection('abcXdefX')
不存在.
我不知道该怎么办.请帮助.
Each collection's name will have uid.
But I don't know how to force it?
db.createCollection('abcXdefX')
doesn't exist.
I've no idea what to do. Please, help.
推荐答案
您不能创建空集合,而必须在内部创建文档. 数据模型
function writeUserData(userId, name, email, imageUrl) {
firebase.database().ref('users/' + userId).set({
username: name,
email: email,
profile_picture : imageUrl
});
}
您可以通过这种方式获取用户ID
You can get user id in this way
var userId = firebase.auth().currentUser.uid;
对于Cloud Firestore
For cloud firestore
db.doc(userId + '/data').set({
name: name,
email: email
});
这篇关于如何使用Javascript在Cloud Firestore中创建集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文