小编zel*_*g74的帖子

获取按文档ID在Firestore中降序排序的数据

我想从documentId降序排序的Firestore数据库中获取数据.我打电话的时候:

firestore.collection("users")
    .orderBy(FieldPath.documentId(), Query.Direction.DESCENDING)
    .get()
    .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {...});
Run Code Online (Sandbox Code Playgroud)

我收到错误:

FAILED_PRECONDITION:查询需要索引.

通过Firebase控制台链接创建自动索引.不幸的是,在这种情况下,自动创建似乎不起作用.当我点击Create Index时,我收到一条消息:

仅__name__不支持索引

对于手动索引创建,doc仅说明了按字段名称索引(不是documentId).有谁知道如何从documentId降序排序的Firestore中获取数据?

我知道我可以在客户端重新排序数据,但是通过id排序是一项非常自然的任务,我必须遗漏一些东西.谢谢.我用:

compile 'com.google.firebase:firebase-firestore:11.6.0'
Run Code Online (Sandbox Code Playgroud)

android firebase google-cloud-firestore

12
推荐指数
1
解决办法
6362
查看次数

如何从控制台获取特定 Firebase 或 Google Cloud 函数的调用计数?

是否可以获得一些概述(在 Google Cloud 控制台或 Firebase 控制台中),我可以在其中查看我的 Firebase(或 Google Cloud)函数运行了多少次?在 GC 控制台中,我只能找到每个函数的“每秒调用次数”图表。另一方面,在 Firebase 控制台中,我只能找到包含所有函数的调用次数的图表。我想知道我的哪些功能消耗了我的配额。谢谢。

firebase google-cloud-console google-cloud-functions firebase-console

6
推荐指数
1
解决办法
685
查看次数

在 Firebase 函数中按 documentId 查询

当我使用 documentId 作为字段路径从 Firebase Firestore 查询数据时,在网页 (javascript) 和 Firebase Function (Node.js) 上运行脚本时,我得到了不同的行为。

这个javascript给了我完美的结果:

firebase.firestore().collection('test')
  .where(firebase.firestore.FieldPath.documentId(), '<=', 'ccc')
  .get()
  .then(snapshots => { /* results are here */ });
Run Code Online (Sandbox Code Playgroud)

相比之下,Firebase Function (Node.js) 中的相同代码:

admin.firestore().collection('test')
  .where(admin.firestore.FieldPath.documentId(), '<=', 'ccc')
  .get()
  .then(snapshots => { /* ... */ });
Run Code Online (Sandbox Code Playgroud)

给我一个错误:

错误:{ 错误:__name__ 上的过滤器必须是 ClientReadableStream._emitStatusIfDone (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:255:19) 处的文档资源名称 ClientReadableStream._receiveStatus (/user_code) /node_modules/firebase-admin/node_modules/grpc/src/client.js:233:8) 在 /user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:705:12 代码:3,元数据:元数据 { _internal_repr: {} } }

我使用我自己的文档 ID,我想通过这些 ID 进行查询。我知道我可以通过查询某个文档的内部字段来解决这个问题,但我的问题是:这种不同行为的原因是什么?非常感谢。

我的 firebase 版本是 3.17.4

编辑:此错误已解决,不会出现在 Firebase 3.18.2 版中。

javascript firebase google-cloud-functions firebase-admin google-cloud-firestore

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

在Cloud Functions for Firebase中运行Firestore批处理

在Firebase的Cloud Functions中,我尝试运行admin.firestore.batch(),但收到错误“ admin.firestore.batch不是函数”,请参阅(完全简化)示例。

exports.getTest = functions.https.onRequest((request, response) => {
  cors(request, response, () => {
    var batch = admin.firestore.batch(); // <--- ERROR HERE
    var docRef = admin.firestore().doc('tariffs/1')
    batch.set(docRef, 'name', 'free');
    return batch.commit();
  }).then(() => {
    response.status(200).send({result: 'success'});
  });
});
Run Code Online (Sandbox Code Playgroud)

我的package.json是

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "dependencies": {
    "cors": "^2.8.1",
    "firebase-admin": "^5.4.2",
    "firebase-functions": "^0.7.1"
  },
  "private": true
} 
Run Code Online (Sandbox Code Playgroud)

是否可以在Cloud Functions中使用firebase.firestore.batch()?

谢谢

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

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