我是一位对Firebase经验很少的设计师,所以如果我问的不是正确的问题,请原谅我。我最近将我的React Native应用程序从一个Firebase帐户迁移到了另一个帐户,现在数据已不再被拉入该应用程序(但是数据正在Firebase中接收)。
该应用实质上是跟踪用户的习惯(从用户输入的信息),并且在个人资料上显示来自Firebase集合的汇总数据中的信息。
但是,应该在视图中加载聚合数据的函数却给我一个错误,提示找不到数据。
这是应该从Firebase中提取数据的功能(据我所知)。
// States
const [timeWindowType, setTimeWindowType] = React.useState<TimeWindowTypes>(
defaultWindowType,
);
const [overview, setOverview] = React.useState<OverviewStatisticsModel>(
OverviewStatisticsFactory.empty(defaultWindowType),
);
const [fetched, setFetched] = React.useState<Boolean>(false);
// Compount / Update
React.useEffect(() => {
if (fetched) return;
loadStats();
});
// Fetch
const loadStats = (type: TimeWindowTypes = TimeWindowTypes.weekly) => {
profileService
.getProfileSnapshot()
.then(({snap, ref}) => {
functions()
.httpsCallable('overviewStats')({
profileId: ref.id,
})
.then(async response => {
const {data} = response;
setOverview(data);
setFetched(true);
})
.catch(err => {
Alert.alert('No data has been found', err.message);
});
})
.catch(error => {});
};
我注意到函数中的.httpsCallable('overviewStats')
,但是在Firebase中看不到引用。可能是原因吗?
如果可以更好地了解问题,我可以共享其他模型“ TimeWindowTypes”和“ OverviewStatisticsModel”。
以下是一些Firebase Firestore数据的图像。
谢谢!
答案 0 :(得分:0)
似乎您在GET中使用了httpsCallable()
,但这是行不通的。如here所阐明的,只能在POST
个调用中使用它。您可以看看这种类似的情况here,以检查如何使用Cloud Functions从Firestore返回数据。
除此之外,httpsCallable()
与API clarifies一起用于Cloud Functions,因此,是的,如果您尝试使用此方法返回数据,则将需要一个。否则,您可以使用标准查询返回您的值。
对于Firestore中的标准查询,我建议您从有关如何运行Cloud Functions以及从Firestore返回数据的开始文档开始。您可以访问它们here和here。