Posts

Showing posts with the label angularfire2

error in retrieving the last document in firebase cloud firestore db

Image
Clash Royale CLAN TAG #URR8PPP error in retrieving the last document in firebase cloud firestore db I'm trying to get the last document from my collection using orderBy method and limit(1) everything is Ok and works as expected , but the problem is when I added a new document to my collection from somewhere else such as firebase console while opening the same page in my app I got the last 2 documents although I specified limit(1) . When I refresh the page everything goes well . how could I solve this problem ? Thanks in advance . -- Here is some of my code : first get my chats ordered descending , then get friend's details from chatUsers collection , finally get the last message document . chat-provider.ts getChats() { return this.afs.collection(`chatUsers/${this.userId}/chats` , ref => ref.orderBy('updatedAt' , 'desc')).valueChanges() } getlastMessage(friendId : string) { return this.afs.collection(`chatUsers/${this.userId}/chats/${friendId}/message...

how to assign the result of snapshot in a variable in firestore angularfire

how to assign the result of snapshot in a variable in firestore angularfire I just want to check if the email exists then I will get the rest of the doc but I can't seem to assign the result in variable. this.db.collection('accounts', ref => ref .where('inviteCode', '==', 'abcd1234') .get() .then(querySnapshot => { const results = ; querySnapshot.forEach(doc => { results.push(doc.data()); }); this.myArray = results; // this is my variable }) .catch(function (error) { console.log('Error getting documents', error); })); I tried using Promise.all(results) but it seems i'm not doing it right. UPDATE: export class FirebaseService { preloginRef: AngularFirestoreCollection<PreLogin>; myArray: ; constructor(private db: AngularFirestore) { this.preloginRef = db.collection(this.dbPath); } codeCheck(inviteCode: string) { this.db.collection('accounts', ref => ref .where(...