Skip to content

Proposal: Optionally return a document ID on valueChanges() when reading a single document #2109

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

Closed
nickreynke opened this issue Jun 12, 2019 · 6 comments

Comments

@nickreynke
Copy link

Thanks to #1973 and #1976 (@codediodeio 🔥) the newest version of AngularFire allows to use valueChanges() in a way that it also maps the ID of the document to the document data that is being returned in addition to the document data itself.

const tasks: Observable<Task[]> = this.firestore.collection<Task>('tasks').valueChanges({ idField: 'id' });

This currently only works when working with a collection() call.

It may also be nice to do the same when reading a single doc() like so:

const taskId = 'abcdefg';
const task: Observable<Task> = this.firestore.doc<Task>(`tasks/${taskId}`).valueChanges({ idField: 'id' });
@jamesdaniels
Copy link
Member

I'm amenable to this, any interest in putting together a PR?

@mjastrzebowski
Copy link
Contributor

Sounds like a great opportunity to start contributing :) On my way with the PR

@geogramdotcom
Copy link

We should also include in collectionGroup as well. Currently the documentation reads that idField can be used in valueChanges(), however it code currently expects 0 arguments

@mjastrzebowski
Copy link
Contributor

@geogramdotcom Thanks for the comment, I thought that I checked that case too, but I might miss something. I will update PR if that's right

@jimisdrpc
Copy link

Is the suggestion above available? I mean, how observe a single document? I am struggling to figure out how do it and add an idToken when using observing a collection? I would be grateful if someone can answer my question in https://stackoverflow.com/questions/61355351/angular-and-firestore-firebaseerror-missing-or-insufficient-permissions-how-a

@jamesdaniels
Copy link
Member

Should be addressed in 6.1.0-rc.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants