相关疑难解决方法(0)

Firestore可以使用一个查询更新符合条件的多个文档吗?

换句话说,我正试图弄清楚在SQL中与Firestore等价的是什么:

UPDATE table SET field = 'foo' WHERE <condition>`
Run Code Online (Sandbox Code Playgroud)

是的,我问的是如何一次更新多个文档,但与链接的问题不同,我特意询问如何一次性完成此操作,而无需在内存中读取任何内容,因为没有必要在您想要的任何内容时执行此操作是在匹配条件的所有文档上设置标志.

db.collection('table')
  .where(...condition...)
  .update({
    field: 'foo',
  });
Run Code Online (Sandbox Code Playgroud)

是我期望的工作,CollectionReference没有.update方法.

交易及成批写入文档中提到的交易和批量写入.交易结束是因为"事务包含任意数量的get()操作,后跟任意数量的写入操作" 批处理写入也不是解决方案,因为它们逐个文档地工作.

有了MongoDB,就可以了

db.table.update(
  { /* where clause */ },
  { $set: { field: 'foo' } }
)
Run Code Online (Sandbox Code Playgroud)

那么,Firestore可以用一个查询更新多个文档,SQL数据库或MongoDB的工作方式,即不需要为每个文档往返客户端吗?如果没有,怎么能有效地完成?

firebase google-cloud-firestore

13
推荐指数
3
解决办法
8341
查看次数

FireStore REST API 调用

我正在使用邮递员从我的 firestore api 获取数据

https://firestore.googleapis.com/v1beta1/projects/myapp-ef511/databases/countries
Run Code Online (Sandbox Code Playgroud)

但我明白了,虽然我的规则是公开的

{
    "error": {
        "code": 401,
        "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
        "status": "UNAUTHENTICATED"
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我计划在未来使用改造。

android google-cloud-firestore

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

在一次读取计数中仅获取来自 Cloud Firestore 的集合 ID

在Cloud Foreshore 的这份文档中提到,“请求一个集合 ID 列表,您需要为读取一个文档付费”。

现在我在我的项目中使用 AngularFire 和 Ionic3。我的要求是仅从具有 where 条件的集合中获取集合 ID。如果我执行以下操作,结果中的读取次数 = 文档数。

let snap = this.afs.collection('path').ref
        .where('field', "==",'data').get();

snap.forEach(x => {
          list.push(x.id);
        });
Run Code Online (Sandbox Code Playgroud)

我无法使用getCollections()我在几个地方找到的方法作为解决方案。

如果您有解决方案,请告诉我。

firebase angularfire ionic-framework google-cloud-firestore

4
推荐指数
2
解决办法
2882
查看次数

Flutter Firebase:检索文档列表,仅限于数组中的 ID?

我正在开发一个 Flutter 应用程序,每个用户都可以创建项目并与其他用户共享项目。我创建了一个“共享”集合,其中每个用户的 ID 都是一个文档,在该文档中,与该用户共享的所有项目 ID 都像这样收集,并使用一个布尔值来表示共享是否已被共享。尚未接受:

股票收藏

接下来,我创建了项目本身的集合,如下所示:

项目集合

现在,我想查询“项目”集合并仅返回给定用户的“共享”列表中的项目。首先,如何获取共享列表中每个文档的ID?其次,是否可以使用子句将该 ID 与列表的内容进行比较.where()

我一直在尝试这样的事情,但没有成功:

  Stream<List<Map<String, dynamic>>> getListOfProjectsForUser({@required List<String> shares}) {
    var ref = _firestore.collection('projects');
    return ref
        .where(shares, arrayContains: ref.id)
        .snapshots()
        .map((QuerySnapshot snapshot) => snapshot.docs.map((DocumentSnapshot doc) => doc.data()).toList());
  }
Run Code Online (Sandbox Code Playgroud)

我也尝试过这个:

Stream<List<Map<String, dynamic>>> getListOfProjectsForUser({@required List<String> shares}) {
  var ref = _firestore.collection('projects');
  return ref
      .where(shares, arrayContains: FieldPath.documentId)
      .snapshots()
      .map((QuerySnapshot snapshot) => snapshot.docs.map((DocumentSnapshot doc) => doc.data()).toList());
}
Run Code Online (Sandbox Code Playgroud)

我想做的事情可能吗?我已经搞砸了两天了,我的头爆炸了。任何帮助将不胜感激。提前致谢。

nosql firebase flutter google-cloud-firestore

4
推荐指数
2
解决办法
9023
查看次数

如何从Firebase Firestore实时更新文档中获取修改后的字段或数据?

我有多个文档。我的问题是我无法获取修改的特定数据,我正在获取完整的文档。

 db.collection("employees").whereEqualTo("OID", OID)
                    .addSnapshotListener(new EventListener<QuerySnapshot>() {
                        @Override
                        public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {

                if (e != null) {
                    Log.w(TAG, "listen:error", e);
                    return;
                }

                for (DocumentChange dc : snapshots.getDocumentChanges()) {
                    switch (dc.getType()) {
                        case ADDED:
                             //Here i am getting full newly added documents
                            break;
                        case MODIFIED:
                           //here i am getting which is modified document,ok fine...,But i want to get only the filed which i modified instance of getting full documents..
                            break;
                        case REMOVED:

                            break;
                    }
                }

            }
        }); …
Run Code Online (Sandbox Code Playgroud)

java android firebase google-cloud-firestore

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