Angularfire: Proposal: Optionally return a document ID on `valueChanges()` when reading a single document

Created on 12 Jun 2019  路  6Comments  路  Source: angular/angularfire

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' });

Most helpful comment

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

All 6 comments

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

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

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

@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

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

Should be addressed in 6.1.0-rc.1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adriandurran picture adriandurran  路  3Comments

martinyoussef picture martinyoussef  路  3Comments

fisherds picture fisherds  路  3Comments

jteplitz picture jteplitz  路  3Comments

harrylincoln picture harrylincoln  路  3Comments