我为数据库触发器创建了Firebase Cloud函数,并成功部署了该函数,但该函数无法检索数据。
exports.newRide = functions.database.ref('/ride/{userid}')
.onCreate((snapshot, context) => {
console.log("THIS IS SNAPSHOT");
console.log(snapshot.val());
console.log("THIS IS userid");
myUID = context.params.userid;
console.log({[myUID] : 1});
console.log("This is[myUID]")
console.log([myUID]);
console.log("This is the wildcardname")
wildCardValue = context.params.wildCardName
console.log(wildCardValue);
return snapshot.val();
);
哪个在控制台日志中返回null
或undefined
。
2020-08-05 16:23:36.276 HKTnewRidedxxxxea8zyc3 null
2020-08-05 16:23:36.276 HKTnewRidedxxxxea8zyc3 THIS IS userid
2020-08-05 16:23:36.276 HKTnewRidedxxxxea8zyc3 null
2020-08-05 16:23:36.276 HKTnewRidedxxxxea8zyc3 { '{userid}': 1 }
2020-08-05 16:23:36.276 HKTnewRidedxxxxea8zyc3 THIS IS SNAPSHOT parent
2020-08-05 16:23:36.276 HKTnewRidedxxxxea8zyc3 This is[myUID]
2020-08-05 16:23:36.276 HKTnewRidedxxxxea8zyc3 [ '{userid}' ]
2020-08-05 16:23:36.276 HKTnewRidedxxxxea8zyc3 This is the wildcardname
2020-08-05 16:23:36.280 HKTnewRidedxxxxea8zyc3 Reference {
2020-08-05 16:23:36.280 HKTnewRidedxxxxea8zyc3 repo:
2020-08-05 16:23:36.280 HKTnewRidedxxxxea8zyc3 Repo {
2020-08-05 16:23:36.280 HKTnewRidedxxxxea8zyc3 repoInfo_:
2020-08-05 16:23:36.280 HKTnewRidedxxxxea8zyc3 RepoInfo {
...
这是我在云功能测试中使用的数据库结构。
{
"ride": {
"uid123": {
"destination": "ChIJJz7FNzUPER8j__MWKHY",
"distance": "21.1 km",
"duration": "18 mins",
"expoPushToken": "ExponentPushToken[Y-YRJKEQU-lngkLAi]",
"latitude": 1.3291467,
"longitude": 103.776495,
"price": 16
}
}
}
这是我的package.json文件。
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "10"
},
"dependencies": {
"expo-server-sdk": "^3.5.1",
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1",
"node-fetch": "^2.6.0"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}