
当我在客户端]上使用firebase.firestore()时,以下功能运行良好,并设法找到了文档:
带有firebase.firestore()
function getUserProfile(email, returnDoc) { var db = firebase.firestore(); var docRef = db.collection("Users").doc(email); ().then(function (doc) { if (ists) { returnDoc(undefined, doc); } else { returnDoc("User not found.", doc); } }).catch(function (error) { returnDoc("Error getting user.", doc); }); };在
index.js
具有相同ail, function (err, userProfile) { if (!err) { $scope.firstName = ("FirstName"); $scope.lastName = ("LastName"); $ail = ("Email"); $scope.$apply(); } else { alert(err); }; });但是当我尝试使用
firebase-admin创建另一个相似的函数时,以下函数找不到
email参数的文档:在db.js中并带有admin.firestore()
const admin = require('firebase-admin'); admin.initializeApp(); let db = admin.firestore(); function getUserData(email, returnDoc) { console.log(`UserData: ${email}`); // email data is correct and exist in database. let docRef = db.collection("Users").doc(email); ().then(function (doc) { console.log(`ists: ${ists}`); // ists: false here. if (ists) { console.log("Document data:", doc.data()); return returnDoc(undefined, doc); } else { return returnDoc("User not found.", doc); }; }).catch(function (error) { return returnDoc("Error getting user.", doc); }); }; UserData = getUserData;在云端功能:
const functions = require('firebase-functions'); const db = require("./middleware/db.js"); UserProfile = Call((data, context) => { var userProfile = undefined; console.log(`ail = ${ail}`); ail, function (err, userDoc) { console.log(` = ${err}`); if (!err) { userProfile = userDoc.data(); return { error: err, returnData: userProfile }; } else { return { error: err, returnData: userProfile }; }; }); });在上述功能中,一切正常,没有错误,除了
始终计算为 false并始终返回"User not found.",为什么?我在第二版代码中做错了什么?谢谢!
NOTE:
我正在运行所有仿真器:firebase emulators:start当我在客户端上使用firebase.firestore()时,以下函数运行良好,并设法找到了该文档:使用firebase.firestore()函数getUserProfile(email,returnDoc){var db = ...
回答如下:关于this post,显然,答案很简单:本地Firestore仿真器没有数据
。基于问题中完全相同的代码,可以使用以下方法轻松证明这一点:本文发布于:2024-05-07 20:29:50,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/1715302995250708.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
| 留言与评论(共有 0 条评论) |