问题
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...
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.
回答1:
You cannot create empty collection, you have to create document inside. data model
function writeUserData(userId, name, email, imageUrl) {
firebase.database().ref('users/' + userId).set({
username: name,
email: email,
profile_picture : imageUrl
});
}
You can get user id in this way
var userId = firebase.auth().currentUser.uid;
For cloud firestore
db.doc(userId + '/data').set({
name: name,
email: email
});
firebase doc - read&write
来源:https://stackoverflow.com/questions/47871288/how-to-create-collection-in-cloud-firestore-from-javascript