8

I want to query a firestore documents collection and want only retrieve the document ids with angularfire2, to save costs for reading all documents. As far as I understand it, the following code is retrieving all documents too and is causing read ops on all documents, no matter if I use doc.data() or not. Am I right?

db.collection("cities").where("capital", "==", true).onSnapshot(function(querySnapshot) {
  querySnapshot.forEach(function(doc) {
    console.log(doc.id);
  }
});

So in the documentation it is stated:

For queries other than document reads, such as a request for a list of collection IDs, you are billed for one document read.

Is there a way with angularfire2 to query a collection and retrieve only the document IDs?

Or is there an other way than using angularfire2?

Jan
  • 424
  • 5
  • 15
  • I don't believe it's possible in any environment. – Doug Stevenson Apr 17 '18 at 14:33
  • 1
    @DougStevenson Seems like a missing feature. That means, at the moment I have to download all documents although I only need the ids. – Jan Apr 17 '18 at 14:42
  • In the Admin SDKs you can do a projection and only download the fields you need (see https://stackoverflow.com/questions/48488797/get-only-documents-names-in-firestore, although I only mention the REST API there). But it will still be charged as N document reads, since reading a document's ID requires accessing that document. – Frank van Puffelen Apr 17 '18 at 14:57
  • If you have a feature request, please describe your use case here: https://firebase.google.com/support/contact/bugs-features/ – Doug Stevenson Apr 17 '18 at 15:11
  • 1
    @DougStevenson Done. – Jan Apr 17 '18 at 15:19
  • 3
    Thank you, your feedback matters. – Doug Stevenson Apr 17 '18 at 15:39

0 Answers0