1

I like the Firebase version 9 modules but I don't like doc. It should be document. This would match collection, which isn't col.

This code doesn't run:

import { doc, collection, deleteDoc } from '@angular/fire/firestore';

this.querySnapshot.forEach((doc) => {
  deleteDoc(doc(this.firestore, 'users', doc.id));
});

I have to change it to

import { doc, collection, deleteDoc } from '@angular/fire/firestore';

this.querySnapshot.forEach((docElement) => {
  deleteDoc(doc(this.firestore, 'users', docElement.id));
});

I'd rather change it to

import { document, collection, deleteDocument } from '@angular/fire/firestore';

this.querySnapshot.forEach((doc) => {
  deleteDocument(document(this.firestore, 'users', doc.id));
});

I have two questions. First, how do I make this request to the Firebase team? Second, can I make an alias for the doc module? I tried this but it didn't work.

import { doc, collection, deleteDoc } from '@angular/fire/firestore';

export class AppComponent {

  document: Function = doc;

  this.querySnapshot.forEach((doc) => {
    deleteDoc(document(this.firestore, 'users', doc.id));
  });
}

That didn't work. :-)

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
Thomas David Kehoe
  • 10,040
  • 14
  • 61
  • 100
  • You can file a request on [GitHub](https://github.com/angular/angularfire) (and also the underlying api [here](https://github.com/firebase/firebase-js-sdk)), but I am 100% certain they would not make this change since it would be a breaking change for everyone who has been consuming this API for the past 5 years. There would be very little advantage to breaking the API since it's very easy to customize the imports or make a wrapper API to your liking. It would also bring the API out of parity with other platforms that use doc. – Doug Stevenson Sep 13 '22 at 14:58

1 Answers1

1

You can use set an alias when importing:

import { doc as fireDoc } from '@angular/fire/firestore';

this.querySnapshot.forEach((doc) => {
  // use fireDoc() here 
  deleteDoc(fireDoc(this.firestore, 'users', doc.id));
});
Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
  • I'd avoid "document" as an alias though to avoid confusion with [document](https://developer.mozilla.org/en-US/docs/Web/API/Document) API. – Dharmaraj Sep 13 '22 at 14:48
  • Works perfectly! That's what I wanted. I imagine that the Firebase team chose `doc` instead of `document` for the reason you said. – Thomas David Kehoe Sep 14 '22 at 15:46