用于检查Firestore集合.exist()是否始终返回false

时间:2019-04-13 00:12:47

标签: typescript google-cloud-firestore ionic4

我正在尝试通过angularfire auth为用户创建用户个人资料,其中只有1个用户应具有1个用户个人资料。

我使用

将数据插入文档中
this.db.collection(`users/`+this.userId+`/userProfile`).add({
                    age : "",
                    weight: "",
                    height: "",
                    times: 1,
             })

profile.page.ts

user ={};
userId = "";

  constructor( public afAuth: AngularFireAuth,
               public db: AngularFirestore, ) { 
    this.afAuth.authState.subscribe(user=>{
        if(user) {
            this.user = user;
            this.userId = user.uid;
            console.log(this.user);
            console.log(this.userId);

            this.db.collection(`users`, ref => ref.where('users', "==", this.userId)).snapshotChanges().subscribe(res => {
                if (res.length > 0)
                {
                console.log(res);
                console.log(this.db.collection(`users`));
                console.log(ref=> ref.where('users', "==", this.userId));   
                console.log("Match found.");
                }
                else
                {
                console.log(res);
                console.log(this.db.collection(`users`));
                        console.log(ref=>ref.where('users',"==",this.userId));  
                console.log("Does not exist.");
                }
            });

        }
    })

console.log返回

Q {G: Array(0), l: "AIzaSyD9GaS4_mg5r6YxPUJDbh4PVGAJHp3rndU", m: "[DEFAULT]", u: "limitremoval-c46dc.firebaseapp.com", b: Nh, …}
wTWEj4KcDFdaekNYGWtMYUnIAmz2
AngularFirestoreCollection {ref: CollectionReference, query: CollectionReference, afs: AngularFirestore}
ƒ (ref) { return ref.where('users', "==", _this.userId); }
Does not exist.

0 个答案:

没有答案