不返回结果的 firestore

firestore where is not returning results

我有这样的代码,虽然我可以清楚地看到其中一条记录有时间戳,但它返回 null,我将其作为查询提供。

const admin = require("firebase-admin")
const firestore = admin.firestore()
exports.getMatchByTimestamp = functions.https.onRequest(async (request, response) => {
  cors(request, response, () => {});
  const querySnapshot = await firestore
    .collection('matches')
    .where('timestamp', '==', request.query.timestamp)
    .get();
  let data = null;
  querySnapshot.forEach((doc) => {
    data = doc.data();
  });
  response.send(data);
});

另一方面,如果我只是删除 where 子句,那么它 returns 我正确地是最后一个文档。

exports.getMatchByTimestamp = functions.https.onRequest(async (request, response) => {
  cors(request, response, () => {});
  const querySnapshot = await firestore
    .collection('matches')
    //.where('timestamp', '==', request.query.timestamp)
    .get();
  let data = null;
  querySnapshot.forEach((doc) => {
    data = doc.data();
  });
  response.send(data);
});

Url 我正在尝试访问 'http://localhost:5001/xxxx-xxxxx/us-central1/getMatchByTimestamp?timestamp=1587482125'

这是数据库截图

我最初的猜测是你的 request.query.timestamp 被解释为一个字符串,所以你最终比较了一个字符串和一个数字。如果是这样的话 parseInt(request.query.timestamp, 10) 应该可以解决问题。