Skip to content

feat(firestore): options to include document ID on valueChanges() #2113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

mjastrzebowski
Copy link
Contributor

Checklist

Description

Continuation of #1976 - added idField option for document.valuChanges() to include the document ID on the emitted data payload. Updated documentation for this one and added some missing changes from the previous PR.

Code sample

documentRef.valueChanges({ idField: 'customID' }).subscribe()
// emits [ { customID: 'MrfFpRBfWLTd7LqiTt9u', ...data }, ... ]

@jamesdaniels jamesdaniels added this to the 5.3.0 milestone Jun 23, 2019
Copy link
Member

@jamesdaniels jamesdaniels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Will merge once ready to cut 5.3

@leolara
Copy link

leolara commented Nov 20, 2019

This is very important feature, thank you

@leolara
Copy link

leolara commented Nov 20, 2019

I think this does not work if you call it on a collection instead of a document

@leolara
Copy link

leolara commented Nov 20, 2019

This is what I had to do to make it work on a collection. Perhaps there is better way, but this is my first week with rxjs:

readAll(): Observable<Listing[]> {
        return this.afs.collection<Listing>(COLLECTION_NAME).snapshotChanges().pipe(
            map((payloads) => {
                return payloads.map(({payload}) => {
                    return {
                        // tslint:disable-next-line:ban-types
                        ...payload.doc.data() as Object,
                        ...{id: payload.doc.id}
                    } as Listing;
                });
            })
        );
    }

@EdricChan03
Copy link
Contributor

LGTM, thanks! Will merge once ready to cut 5.3

Are there any updates to this PR? It's been a while since release 5.3.

@jamesdaniels
Copy link
Member

Whoops, meant to get this into 5.3 but working on 6 ate up all my time. Will get this into 6.1.

@kyleabens
Copy link

Can this be added to 6.0.4?

@jamesdaniels
Copy link
Member

New API so had to wait for a minor, will aim to get this in today for rc.1.

@jamesdaniels jamesdaniels merged commit 09ed22a into angular:master Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants