OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Firebase v9 modular - How do you use onSnapshot to return an observable?

  • Thread starter Thread starter user1012500
  • Start date Start date
U

user1012500

Guest
I'm trying to use Firebase v9 modular version and I'm confused as to how to use onSnapshot. I'm trying to execute a query and listen to the documents.

Following is my code :

Code:
    getUsersBoards(){

    return this.authService.currentUser$.pipe(
      filter((user)=> !!user),
      mergeMap(async (user) => {
        const collectionRef = collection(this.firestore, 'boards');

        const q = query(collectionRef, where("owner", "==", user.uid));

        return onSnapshot(q, (querySnapshot)=>{
          return querySnapshot;
        });

      })
    );
    
  }

I was expecting an Observable<board[]>, but I'm getting a Observable<unsubscribe>

Is there a way so that I can do the following ?

Code:
boards$: Observable<board[]>;

...
this.boards$ = getUsersBoards();

<p>I'm trying to use Firebase v9 modular version and I'm confused as to how to use onSnapshot. I'm trying to execute a query and listen to the documents.</p>
<p>Following is my code :</p>
<pre><code> getUsersBoards(){

return this.authService.currentUser$.pipe(
filter((user)=> !!user),
mergeMap(async (user) => {
const collectionRef = collection(this.firestore, 'boards');

const q = query(collectionRef, where("owner", "==", user.uid));

return onSnapshot(q, (querySnapshot)=>{
return querySnapshot;
});

})
);

}
</code></pre>
<p>I was expecting an <code>Observable<board[]></code>, but I'm getting a <code>Observable<unsubscribe></code></p>
<p>Is there a way so that I can do the following ?</p>
<pre><code>boards$: Observable<board[]>;

...
this.boards$ = getUsersBoards();
</code></pre>
 
Top