小编Dan*_*evi的帖子

有没有办法从 Firestore 中仅选择某些字段?

我正在解决一个函数的性能问题,该函数需要 15 秒才能响应,该函数向 firebase 请求所有文档,问题是 "ErrorID" "==" "0" 有很多文档,而且它们是非常大的对象,而我只需要两个每个文档的FIELDS (Order and Amount),有什么方法可以只请求满足条件的那两个字段?

就像是 :

firestore.collection("purchases").where("ErrorID", "==", "0").get(Order, Amount); 
Run Code Online (Sandbox Code Playgroud)

我正在谈论的功能:

const totalEarn = async (req, res, next) => {
  const DAY = 86400000;
  const WEEK = 604800016;
  const MONTH = 2629800000;

  try {
    let snap = await firestore.collection("purchases").where("ErrorID", "==", "0").get(); // CONDITION
    let totalToday = 0;
    let totalYesterday = 0;
    let totalLastWeek = 0;
    let totalLastMonth = 0;
    let now = Date.now();
    let Yesterday = now - 86400000;

    await …
Run Code Online (Sandbox Code Playgroud)

javascript node.js firebase google-cloud-platform google-cloud-firestore

9
推荐指数
1
解决办法
7777
查看次数