Firebase Firestore – 2 queries Promise All

问题内容:

Im trying to generate a few fake profiles for development, Im using a predefined json dataset and I cant seem to get it to work, I want to create the accounts using a given email and password then use other data in the same json dataset to create user profiles in a collection under their uid. Im trying to user promise all but all that gets created is the authenticated user in firebase but not the populated users collection with the remaining data. my function looks like this so far:

  doSignupFAKEUSERS( users: any ) {

  users.forEach( usr => {

  firebase.default.auth().createUserWithEmailAndPassword( usr.email, usr.password ).then( (result) => {

          const added = this.afs.collection<any>("users").doc(result.uid).set({
              email:usr.email,
              pw: usr.password,
              uid: result.uid,
              age: usr.age,
              displayName: usr.email.substring(0, usr.email.indexOf("@")),
              photoURL: usr.photoURL,
              currentCity: usr.currentCity,               
            })

            return Promise.all([result, added]);    

      });

    })    
}  

and this is my test data

    account: [{ displayName: string, age: number, email: string, photoURL: string, uid: string,  currentCity: string }] = [
    {
        displayName: 'Albert Cruz',
        age: 23,
        email: 'albert.cruz15@example.com',
        photoURL: 'https://randomuser.me/api/portraits/men/95.jpg',
        currentCity: 'Prague',
        uid: ''
    } ,
    {
        displayName: 'Albert Wheeler',
        age: 26,    
        email: 'albert.wheeler22@example.com',
        photoURL: 'https://randomuser.me/api/portraits/men/40.jpg',
        currentCity: 'Prague',    
        uid: ''
    }      

    ];  

问题评论:

原文地址:

https://stackoverflow.com/questions/47756657/firebase-firestore-2-queries-promise-all

Add a Comment