火疗店哪里没有结果

问题描述 投票:0回答:1

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

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子句,那么它正确地返回我最后的文档。

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);
});

我试图访问的URLlhttp:/localhost:5001xxxx-xxxxxus-central1getMatchByTimestamp?timestamp=1587482125。'

以下是数据库的截图enter image description here

node.js google-cloud-firestore firebase-admin
1个回答
2
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.