Я создал функцию 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
}
}
}
Это мой пакет. 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
}