angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Bug: doc(...).snapshotChanges does not return DocumentChangeAction

Open Bielik20 opened this issue 8 years ago • 10 comments

Version info

Angular: 6.0.3

Firebase: 5.1.0

AngularFire: 5.0.0-rc.11

Other: Windows 10, browser (chrome)

How to reproduce these conditions

Subscribe to any DOCUMENT with "snapshotChanges". Eg:

this.afs.collection('myCollection').doc('myDocId')
  .snapshotChanges()
  .pipe(tap(res => console.log(res))
  .subscribe()

Debug output

image

Expected behavior

According to documentation snapshotChanges should return Observable<DocumentChangeAction<T>>.

Actual behavior

What it does return is Observable<Action<DocumentSnapshot<T>>>. type field is always "value" even if I delete record and payload does not seem to contain actual data (I was not able to find it).

Remarks

snapshotChanges works well on collections returning Observable<DocumentChangeAction<T>[]>. Problem occurs only when using it on document.

Bielik20 avatar Jul 03 '18 13:07 Bielik20

same issue on ubuntu

this.db.collection('polls').doc('id').snapshotChanges().subscribe(poll => {})

poll.payload is not a DocumentChange, so you can't call .doc property to retrieve le document

Noext avatar Jul 26 '18 17:07 Noext

@Bielik20 @Noext We are changing doc.snapshotChanges() to return a Observable<DocumentSnapshot<T>> in the next release. The type is useless on it because it is always a value update regardless of the type of change.

davideast avatar Aug 17 '18 17:08 davideast

How can I know which change occurred (added, modified, removed) if the type field is always equal to "value"?

Thanks.

CheckMater avatar Sep 02 '18 02:09 CheckMater

Hi @davideast thanks for all the hard work on this great project, love the way it auto-syncs data. Favor: could one of the contributors update the docs on the doc.snapshotChanges() method? I'm using @angular/fire 5.0.0 and this change is in there, but I have next to no idea how to use this method now.

THANKS!

AnthonyGilliam avatar Sep 22 '18 06:09 AnthonyGilliam

The problem persists to the present date. I just met it.

rubenCortes avatar May 10 '19 16:05 rubenCortes

@davideast what release were you referencing? I couldn't find anything finished or a pull request and the unusable type causes quite dirty code down the line.

Malspherus avatar May 17 '19 14:05 Malspherus

Still having this issue to this day

mcarriere avatar Jun 01 '20 23:06 mcarriere

Having same issue as author, the type on Action type is always returning value no matter what. Maybe we must use snapshotChanges() on a collection-document chain instead?

KingDarBoja avatar Jun 04 '20 17:06 KingDarBoja

I have same issue, is imposible to know what type of changes was performed over one specific document using the snapshotChanges, someone know some workaround to resolve this issue?

sur97c avatar Jun 09 '20 20:06 sur97c

closing in favor of #2108

jamesdaniels avatar Nov 18 '20 17:11 jamesdaniels