我希望从我的 Swift 集合中检索所有文档,其中字段“groupId”==“31bc2501-7164-4f22-7b28-9f9005acbcf6”(一个 guid)
如果我使用 firebase 文档 ID,则可以:
IE
CollectionReference reference = db.collection("chats/XIiOrtRiYmLtzz1tzG2u")
Run Code Online (Sandbox Code Playgroud)
但我想通过一个字段来查询它。
我在 Swift 中看到有这样的东西:
var query = db.collection("chats").whereField("groupId", isEqualTo: "31bc2501-7164-4f22-7b28-9f9005acbcf6")
Run Code Online (Sandbox Code Playgroud)
但它返回一个查询对象,我不知道如何“弹出”它来执行查询并返回给我一个集合(大多数在线示例似乎使用不同且过时的语法来执行此操作,并且不要' t 使用 whereField)
有没有办法像我在第一个示例中所做的那样内联查询集合,但使用主键以外的其他字段?也许我在错误地查询集合?
谢谢,感谢您的时间!
当用户登录我的应用程序时,我希望他们能够看到选定半径内的用户数量。我打算开始在我的数据库中存储坐标并遍历每条记录(~50,000),运行 userCoordinates.distance(from: databaseCoordinateValue)。但是,在测试过程中,我发现这个过程需要很长时间,并且不是一个可扩展的解决方案。您对如何在定义的半径内快速查询数据库项目有什么建议吗?
我在用:
数据库结构示例以及数据如何存储
database.collection("users").document((Auth.auth().currentUser?.uid)!).setData([
"available_tags" : ["milk", "honey"]]) { err in
if let err = err {
print("Error adding document: \(err)")
}
}
Run Code Online (Sandbox Code Playgroud) 我目前正在将 Firebase Firestore 用于 Android 项目,但是当手机处于飞行模式时,我在检索数据时遇到了一些问题。这是我的代码:
public void loadThings() {
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection("medidas").whereEqualTo("id_user", mAuth.getCurrentUser().getUid()).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
QuerySnapshot snapshot = task.getResult();
int tam = snapshot.getDocuments().size();
data = new String[tam];
StringBuilder temp;
DocumentSnapshot doc;
for (int i = 0; i < tam; i++) {
temp = new StringBuilder();
doc = snapshot.getDocuments().get(i);
temp.append("Date: ").append(doc.get("fecha")).append(";");
temp.append("Min: ").append(doc.get("min")).append(";");
temp.append("Max: ").append(doc.get("max")).append(";");
temp.append("Avg: ").append(doc.get("avg")).append(";");
data[i] = temp.toString();
}
if(tam==0)
{
noMeasures();
}
}
else
{ …Run Code Online (Sandbox Code Playgroud) 我的代码有问题,我不知道如何以正确的方式解决它。
我正在尝试编写一个过滤器,当用户单击每个过滤器时,它会自动从 Firestore 查询数据。
在我的 Redux Saga 中有这个:
const {type, currency, location} = action.payload;
Run Code Online (Sandbox Code Playgroud)
一切正常,但问题是当我尝试使用动态输入查询数据时:例如:
firebase
.firestore()
.collection("ItemData")
.where("type", "==", type)
.where('currency', '==', currency)
.where('location', '==', location)
Run Code Online (Sandbox Code Playgroud)
当用户单击选项时,type它不显示任何输入currency并且location没有数据,只有空字符串,因此查询返回无响应。除非您单击所有过滤器,否则它将显示正确的响应。
那么我该如何解决这个问题呢?
我正在尝试为基于 Firestore 的应用程序编写安全规则,但我对 Firestore 中对文档/集合的访问权限是否为默认设置感到困惑(这意味着我需要编写规则来明确禁止在以下情况下访问任何文档)应该限制访问)或者是否对文档的访问不是默认设置(这意味着我需要编写规则以在我想要启用访问的情况下专门允许访问)?
从firestore文档中我读到了这个:
在读取或写入任何数据之前,会根据您的安全规则评估来自 Cloud Firestore 移动/网络客户端库的每个数据库请求。如果规则拒绝访问任何指定的文档路径,则整个请求都会失败。
由此看来,默认情况下所有文档都可以访问,但我不确定并想问一下。
任何澄清将不胜感激!
我正在使用 firebase cloud firestore 开发银行应用程序。我已经设置了这样的规则:
// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的数据库结构如下:
/consumers/{consumer_id}/transactions/{transaction_id}
{consumer_id} 将包含该消费者的帐户余额以及其他详细信息,而 {transaction_id} 将包含有关每笔交易的详细信息。
因此,如果任何经过身份验证的用户想要提款,他们可以使用 android 应用程序/Web 应用程序进行提取。问题是,同一用户是否可以在我不知情的情况下使用他们的凭据和 REST 端点访问数据库(例如:更新他们的帐户余额)?如果是这样,我如何防止他们这样做?
firebase firebase-security firebase-authentication google-cloud-firestore
我找不到验证firestore 中列表内容的解决方案。有没有办法解决这个问题?
我不想使用新集合,因为它对如此少量的数据没有意义(并且最终会花费比必要更多的读取成本,并且将数据保存在原始文档下更方便) .
为每个文档存储一些图像细节:
[
{
"filename": "example.png",
"author": "example",
"caption": "...",
},
...
]
Run Code Online (Sandbox Code Playgroud)
或者,为每个文档存储几个标签:
[
"tag text 1",
"tag text 2",
...
]
Run Code Online (Sandbox Code Playgroud)
我如何访问每个项目(或循环?)来验证它们,以便在第一个带有图像的示例中,它可以被验证(例如):
或者,对于标签示例,
或者是否有更好的解决方案来将此类数据存储在文档中而无需创建新集合或子集合?
我正在使用 Firestore 数据库创建聊天模块。以下是我侦听新消息的侦听器代码:
mDb.collection("Users_Collection").document(mAuth.getUid()).collection("Recipients")
.document(psychichObj.getUid()).collection("Messages").orderBy("time").limit(30)
.addSnapshotListener(MetadataChanges.INCLUDE, new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
if (e==null){
for (DocumentChange dc:queryDocumentSnapshots.getDocumentChanges()){
switch (dc.getType()){
case ADDED:
Log.d("chatevents", "onEvent:Added ");
messgaesDataClass msg = dc.getDocument().toObject(messgaesDataClass.class);
messages.add(msg);
chatAdapter.notifyDataSetChanged();
messagesRecycler.smoothScrollToPosition(messages.size());
break;
case REMOVED:
Log.d("chatevents", "onEvent:Removed ");
case MODIFIED:
Log.d("chatevents", "onEvent:Modiefied ");
}
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
当我发送消息时,我想知道如何侦听本地缓存中的 msg 对象或其元数据处于挂起状态但尚未发送到服务器的消息?
我目前有一个 Firestore 文档查询,如下所示:
getDocument(){
this.albumDoc = this.afs.doc<Album>(`albums/abc`);
this.album = this.albumDoc.valueChanges();
}
Run Code Online (Sandbox Code Playgroud)
AngularFire 文档指出,您可以使用“快照”更改获取更多数据。但是,没有一个示例说明您将如何执行此操作。对于集合查询,快照更改使用管道/映射,然后返回“数据”,然后您可以根据需要将其分配给变量。
是否可以对文档查询执行相同的操作?我的文档中有一个 firestore 值,我想抓住它并加以利用。
来自 Firestore,我在如何从 Firebase 实时数据库接收数据方面有些挣扎。我只想要从实时数据库加载的图像的漂亮网格视图。
Error: flutter: The following NoSuchMethodError was thrown building:
flutter: Class 'DataSnapshot' has no instance method '[]'.
flutter: Receiver: Instance of 'DataSnapshot'
Run Code Online (Sandbox Code Playgroud)
我猜它与索引有关。不知道如何在列表中正确映射它。
import 'package:cached_network_image/cached_network_image.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
class Test extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(16.0),
child: new FutureBuilder(
future: FirebaseDatabase.instance
.reference()
.child('messages')
.child('1551276762582')
.orderByChild('messagetype')
.equalTo('1')
.once(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
if (snapshot.data != null) {
return new Column(
children: <Widget>[ …Run Code Online (Sandbox Code Playgroud) firebase firebase-realtime-database flutter google-cloud-firestore flutter-layout