小编Ren*_*nec的帖子

Google Firestore - 如何在一次往返中通过多个ID获取文档?

我想知道是否可以通过往返Firestore的往返(网络呼叫)中的ID列表获取多个文档.

firebase google-cloud-firestore

66
推荐指数
8
解决办法
2万
查看次数

在 Firebase 中对大量数据进行分页和过滤的最佳方法是什么?

我有一个包含 10,000 个文档的大型 Firestore 集合。

我想通过一次分页和过滤 25 个结果来在表格中显示这些文档。

我的想法是,为了限制“读取”(从而降低成本),一次仅请求 25 个文档(使用“限制”方法),并在页面更改时加载接下来的 25 个文档。

但有一个问题。为了显示页数,我必须知道文档的总数,并且我将被迫查询所有文档才能找到该数字。

我可以选择无限滚动,但即使在这种情况下,我也永远不会知道我的过滤器找到的结果总数。

另一种选择是在开始时请求所有文档,然后使用客户端进行分页和过滤。

那么,在这种情况下通过优化性能和成本来显示数据的最佳方式是什么?

谢谢!

pagination large-data firebase google-cloud-platform google-cloud-firestore

15
推荐指数
1
解决办法
3万
查看次数

如何修复节点中的“解析错误:意外令牌 =>”?

我正在使用 firebase 函数进行条带支付集成。此特定功能用于使用条带注册客户。

节点版本 10.15.3 ,

npm 版本 6.9.0 ,

"ecmaVersion": 6 in .eslintrc.json

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

const stripe = require('stripe')(functions.config().stripe.testkey)

exports.createStripeCustomer = functions.auth.user()

          .onCreate(async (user) => {
             const customer = await
             stripe.customers.create({email: user.email});
             await admin.firestore()
               .collection('stripe_customers')
               .doc(user.uid)
               .set({customer_id: customer.id});

           });

Run Code Online (Sandbox Code Playgroud)

代码与 github 示例https://github.com/firebase/functions-samples/blob/master/stripe/functions/index.js上提供的 firebase 平台相同

解析错误:意外的令牌 =>

如果我将 .eslintrc.json 中的 "ecmaVersion": 6 更改为 "ecmaVersion": 8

then error is .onCreate(async (user) => {

                            ^

SyntaxError: Unexpected token (
Run Code Online (Sandbox Code Playgroud)

我想正确部署功能,以便用户可以在 firebase 存储中的条带和日期存储上注册

javascript node.js stripe-payments firebase google-cloud-functions

10
推荐指数
2
解决办法
7626
查看次数

Firebase Firestore增量FieldValue不增量

所以我已经阅读了所有有关在 Firestore 数据库中增加计数器的文档。我有这个代码

const admin = require("firebase-admin");
const db = admin.firestore();
...
db
.collection("settings")
.doc("totalUsers")
.set({
count: firebase.firestore.FieldValue.increment(1),
});
Run Code Online (Sandbox Code Playgroud)

我只是根本不增加计数器。没有错误没有日志什么也没有。在我的 Firestore 中,我有一个集合settings和一个文档totalUsers,其属性count是数字类型且等于 1。

难道我做错了什么?我错过了什么吗?任何帮助表示赞赏!

node.js firebase firebase-admin google-cloud-firestore

10
推荐指数
2
解决办法
4868
查看次数

如何在 AngularFire 7 新 api 中使用“where”?

我将 AngularFire 升级到 7,并且在使用 .where 和 collectionReference 时遇到问题。那么简单..如何正确使用它?

我尝试使用“@angular/fire/firestore”中的“集合”,例如:

const ref = collection(this.firestore, 'collectionName');
Run Code Online (Sandbox Code Playgroud)

但裁判没有说“哪里”之类的。

我知道“@angular/fire/firestore”也有“query”和“where”,但我不知道如何使用它。

如何使用新 API 的“where”在集合中查找文档?

javascript firebase google-cloud-platform angularfire2 google-cloud-firestore

10
推荐指数
3
解决办法
2956
查看次数

类型错误:querySnapshot.forEach 不是函数 - Firebase Cloud Functions

我有一个这样的数据结构:

  • 帖子(收藏)
  • 用户ID(文档)
  • 帖子(收藏)
  • 博士后(文档)

我正在设置一个云函数来根据特定事件更改所有帖子(子集合)文档,为此我使用collectionGroup查询:

我是这样设置的:

exports.changeIsVisibleFieldAfterDay = functions.pubsub
.schedule("every 2 minutes").onRun((context) => {
  const querySnapshot = db.collectionGroup("Posts")
      .where("isVisible", "==", true).get();
  querySnapshot.forEach((doc) => {
    console.log(doc.data());
  });
});
Run Code Online (Sandbox Code Playgroud)

Firebase Log我收到以下错误:

TypeError: querySnapshot.forEach is not a function
Run Code Online (Sandbox Code Playgroud)

网上搜索发现Firebase SDK版本可能有问题,但我的是最新的,我package.json在这里附上文件:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": …
Run Code Online (Sandbox Code Playgroud)

javascript firebase google-cloud-platform google-cloud-functions google-cloud-firestore

9
推荐指数
1
解决办法
7504
查看次数

为 Cloud Functions 指定区域时出现异常“firebase.functions() requires ... no argument ...”

我正在关注 Firebase文档,以便从网页调用位于与us-central1.

更准确地说,在网页中,我做了var functions = firebase.functions('europe-west1');但我收到以下错误并且没有从调用中得到结果:

uncaught exception: functions: Firebase: firebase.functions() takes either no argument or a Firebase App instance. (app/invalid-app-argument).
Run Code Online (Sandbox Code Playgroud)

这是MCV代码:

云功能

const functions = require('firebase-functions');

exports.getName = functions
  .region('europe-west1')
  .https.onCall((data, context) => {
    return { name: 'MyName' };
  });
Run Code Online (Sandbox Code Playgroud)

网页

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="https://www.gstatic.com/firebasejs/5.3.1/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/5.3.1/firebase-functions.js"></script>

</head>

<body>
    <script>
        // Initialize Firebase
        var config = {
            apiKey: "xxxxxxxxxx",
            authDomain: "xxxxxxxxxx",
            databaseURL: "xxxxxxxxxx",
            projectId: "xxxxxxxxxx",
            storageBucket: "xxxxxxxxxx", …
Run Code Online (Sandbox Code Playgroud)

firebase google-cloud-functions

8
推荐指数
1
解决办法
1417
查看次数

集合中所有 ID 的 Firebase Firestore 列表

Google Firebase 似乎很难解决我的问题......从集合中获取文档及其数据没有问题,但是当我尝试简单地获取集合中所有 ID 的列表时,我无法弄清楚呼叫应该是什么样子。我曾尝试搜索信息,但没有成功。

在此处输入图片说明

我在服务组件中声明了一个函数,如下所示:

getCollRegistrationNumbers(): firebase.firestore.CollectionReference {
  return firebase.firestore().collection(`storedItems`);
}
Run Code Online (Sandbox Code Playgroud)

然后在例如我的应用程序的搜索页面中,我从我的组件调用该函数,但无论我尝试什么,它都会返回空。

鉴于上面的服务功能,我应该如何完成下面的代码以仅 git 一个 ID 列表?

this.fireStore.getCollRegistrationNumbers().get()
  .then(snapshot => {....})
Run Code Online (Sandbox Code Playgroud)

javascript firebase google-cloud-firestore

8
推荐指数
1
解决办法
7833
查看次数

如何使用firebase发送唯一的注册链接?

我想构建一个应用程序,用户只需在其中注册“邀请”。已经拥有帐户的用户可以向指定的电子邮件地址发送邀请,然后应用程序会发送一封电子邮件,其中包含指向注册的链接,其中有一个令牌,并且只能使用指定的电子邮件地址。

那么首先,如何从 firebase 发送“自动化”电子邮件,其次,如何为 URL 生成唯一的注册令牌?

javascript firebase google-cloud-functions

8
推荐指数
1
解决办法
4539
查看次数

Firebase 云函数 firestore 数组 union

我无法让数组并集或增量在 firebase 云函数中正常工作。

return docRef.update({

  object: {
    count: admin.firestore.FieldValue.increment(1),
    list: admin.firestore.FieldValue.arrayUnion({
      space_id: newData.date_id,
      user: {
        displayName: "john doe"
      }
    })
  }
Run Code Online (Sandbox Code Playgroud)

当函数运行时,它只是覆盖列表数组中的现有数据,并且计数始终设置为 1,即使它当前存在并且是数字类型。

node.js firebase google-cloud-functions firebase-admin google-cloud-firestore

8
推荐指数
1
解决办法
2万
查看次数