我想从Firestore集合中选择仅由我编写的文章.
这真的很难吗?
每篇文章都有字段"owner_uid".
多数民众赞成:
我只想写相当于"select * from articles where uid<>request.auth.uid"
遵循firestore的官方文档:
{
name: "Frank",
favorites: { food: "Pizza", color: "Blue", subject: "recess" },
age: 12
}
// To update favorite color:
db.collection("users").doc("frank").update({
"favorites.color": "Red"
})
Run Code Online (Sandbox Code Playgroud)
我想使用动态键而不是颜色.
db.collection("users").doc("frank").update({
"favorites[" + KEY + "].color": true
});
Run Code Online (Sandbox Code Playgroud)
这当然是不可能的,并会抛出错误.
我一直试图这样做:
db.collection("users").doc("frank").update({
favorites: {
[key]: {
color": true
}
}
});
Run Code Online (Sandbox Code Playgroud)
它实际上是使用正确的密钥更新,但遗憾的是,它正在覆盖其他密钥(它们正被删除).
说我有这种结构
A (collection): {
a (doc): {
name:'Tim',
B (collection):{
b (doc): {
color:'blue'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在哪里A和B是集合,a而且b是文档.
有没有办法通过一个查询获取根文档中包含的所有内容?
如果我这样查询
db.collection("A").doc("a").get()
Run Code Online (Sandbox Code Playgroud)
我刚刚name:'Tim'上场.我想要的是获得所有B的文件.
我基本上希望我的查询返回
{
user:'Tim',
B (collection):{
b (doc): {
color:'blue'
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否可能或者我真的需要为每个集合进行多次查询:/?
假设我有一个非常深的嵌套树集合代表用户配置文件,我的成本会像地狱一样提高,因为每次加载用户配置文件时我都有一个读取请求的乘数,1 x N其中N是我树的深度:/.
我有一个文档"用户",其中有一个名为"照片"的键.这是保存的字符串数组,即"照片"文档的ID.
我想通过此"照片"字段查询"用户":我希望在"照片"属性中拥有此ID的所有用户.
这可能通过firestore吗?
data-modeling firebase google-cloud-platform google-cloud-firestore
我想弄清楚如何使用 Firebase 侦听器,以便使用 React 挂钩更新来刷新云 Firestore 数据。
最初,我使用带有 componentDidMount 函数的类组件来获取 firestore 数据。
this.props.firebase.db
.collection('users')
// .doc(this.props.firebase.db.collection('users').doc(this.props.firebase.authUser.uid))
.doc(this.props.firebase.db.collection('users').doc(this.props.authUser.uid))
.get()
.then(doc => {
this.setState({ name: doc.data().name });
// loading: false,
});
}
Run Code Online (Sandbox Code Playgroud)
当页面更新时会中断,所以我试图弄清楚如何移动侦听器以响应钩子。
我已经安装了react-firebase-hooks工具 - 尽管我不知道如何阅读说明才能让它工作。
我有一个功能组件如下:
import React, { useState, useEffect } from 'react';
import { useDocument } from 'react-firebase-hooks/firestore';
import {
BrowserRouter as Router,
Route,
Link,
Switch,
useRouteMatch,
} from 'react-router-dom';
import * as ROUTES from '../../constants/Routes';
import { compose } from 'recompose';
import { withFirebase } from …Run Code Online (Sandbox Code Playgroud) javascript firebase reactjs google-cloud-firestore react-hooks
是否可以仅使用一个请求在Firestore中存储多个文档?使用此循环可能但这会导致列表中的每个项目进行一次保存操作.
for (counter in counters) {
val counterDocRef = FirebaseFirestore.getInstance()
.document("users/${auth.currentUser!!.uid}/lists/${listId}/counters/${counter.id}")
val counterData = mapOf(
"name" to counter.name,
"score" to counter.score,
)
counterDocRef.set(counterData)
}
Run Code Online (Sandbox Code Playgroud) 该文件对公司的FireStore批量写入只列出set(),update()并delete()允许的操作.
有没有办法向add()批处理添加操作?我需要使用自动生成的ID创建文档.
在 Firebase Cloud Firestore 中,我在集合中有“user_goals”,目标可能是预定义的目标(master_id:“XXXX”)或自定义目标(没有“master_id”键)
在 JavaScript 中,我需要编写两个函数,一个获取所有预定义目标,另一个获取所有自定义目标。
我有一些解决方法来通过将“master_id”设置为“”空字符串来获得自定义目标,并能够获得如下:
db.collection('user_goals')
.where('challenge_id', '==', '') // workaround works
.get()
Run Code Online (Sandbox Code Playgroud)
这仍然不是正确的方法,我继续将其用于预定义的目标,其中它具有“master_id”,如下所示
db.collection('user_goals')
.where('challenge_id', '<', '') // this workaround
.where('challenge_id', '>', '') // is not working
.get()
Run Code Online (Sandbox Code Playgroud)
由于 Firestore 没有 "!=" 运算符,我需要使用 "<" 和 ">" 运算符,但仍然没有成功。
问题:忽略这些变通方法,通过检查特定字段是否存在来获取文档的首选方法是什么?
我们正在将 GCP 的 Firebase 与 Firestore 一起用于我们正在开发的新移动应用程序。作为这项工作的一部分,我们需要部署许多云功能,这些功能将作为 Firestore 触发器进行一些后端处理。
我们的目的是使用 firebase cli 工具将部署封装在 Firebase 内部。但是,当我们尝试使用“firebase init 函数”调用为函数启动 Firebase 项目时,只有两种语言选项是“Javascript”和“Typescript”,并且唯一可部署的堆栈似乎是 Node.js。
在之前的 GCP 项目中,我们已经部署了基于 Python 的云函数(使用 gcloud cli),理想情况下,我们希望继续将 Python 用于我们的 Firebase 云函数。所以我的问题是:
是否可以部署基于 Python 的 Firebase 云函数?如果不:
我们可以简单地回到使用 gcloud cli 部署基于 Python 的 GCP 云函数,并且仍然让它们作为 Firestore 触发器工作吗?
谢谢
python firebase google-cloud-platform google-cloud-functions google-cloud-firestore
我希望能够在本地运行云函数并针对生产数据的副本进行调试。有没有办法将在线的数据复制到本地firestore模拟器?
firebase-tools google-cloud-functions google-cloud-firestore