Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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 :

    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 ?

boards$: Observable<board[]>;

...
this.boards$ = getUsersBoards();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're getting Observable<unsubscribe> because, according to the Firebase docs, onSnapshot returns "[a]n unsubscribe function that can be called to cancel the snapshot listener."

Try converting the snapshot to an observable first, before returning. For example:

        new Observable(observer => {
          return onSnapshot(reference,
            (snapshot => observer.next(snapshot.data())),
            (error => observer.error(error.message))
          );
        });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!