我有这样的代码,虽然我可以清楚地看到其中一条记录有时间戳,我提供的是查询,但它的返回是空的。
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。'
我最初的猜测是,你的 request.query.timestamp
被解释为一个字符串,所以你最终比较的是一个字符串和一个数字。如果是这样的话 parseInt(request.query.timestamp, 10)
应该可以做到这一点。