I want to set two conditions for displaying data. But such error occurs in the browser console.
Function Query.where() called with invalid data. Unsupported field value: undefined
ts:
How to fix it?
this.itemsCollection = this.afs.collection<Message>('messages', ref => {
let query: firebase.default.firestore.CollectionReference | firebase.default.firestore.Query = ref;
query = query.where('receiverId', '==', this.receiverId);
query = query.where('senderId', '==', this._cs.senderId);
return query;
});
this.items = this.itemsCollection.valueChanges();
Your code looks fine but as the error message text says one of your variables this.receiverId
or this._cs.senderId
has the value undefined
and that causes the error. Just make sure not to have undefined
there by putting some kind of fallback values.
this.itemsCollection = this.afs.collection<Message>('messages', ref => {
let query: firebase.default.firestore.CollectionReference | firebase.default.firestore.Query = ref;
query = query.where('receiverId', '==', this.receiverId || '');
query = query.where('senderId', '==', this._cs.senderId || '');
return query;
});
this.items = this.itemsCollection.valueChanges();