使用在Firestore模拟器上运行的Firebase

阅读: 评论:0

使用在Firestore模拟器上运行的Firebase

使用在Firestore模拟器上运行的Firebase

当我在客户端]上使用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小时内删除。

标签:器上   Firestore   Firebase
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23