0

I have an observable posts$ where it holds the result of the query. I want to search the posts by keywords in a specific userID.

The query should be read llike this: Search posts where userid = 1 and keywords = (what has been typed in a search field)

This is my code and it doesn't give any results.


this.posts$ = this.afs.collection('posts', ref =>  ref   
                        .where('userid', '==', this.userID)                          
                        .where('keywords', 'array-contains', query.toLowerCase()) 
                        .orderBy('created_at', 'desc')
                        
                        ).valueChanges({idField: 'id'});
  • 1
    Did you create an [index](https://stackoverflow.com/questions/50305328/firestore-whereequalto-orderby-and-limit1-not-working)? – Alex Mamo Nov 18 '22 at 13:30
  • @AlexMamo yes i have already created an index is my syntax correct? – Anonymous Coder Nov 18 '22 at 13:31
  • The code looks fine at first glance. If it doesn't work, check the log output for warnings about a missing index. If there's nothing there either, edit your question to show a screenshot of a document that you expect this query to return. Keep in mind that we have no way of knowing the values of `this.userID` and `query`. – Frank van Puffelen Nov 18 '22 at 14:34

0 Answers0