Firestore: Query collection using “where” and only retrieve document IDs

爷,独闯天下 提交于 2021-01-27 04:12:07

问题


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?

来源:https://stackoverflow.com/questions/49880839/firestore-query-collection-using-where-and-only-retrieve-document-ids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!