小编Rag*_*esh的帖子

如何检查firestore中是否已经存在某些数据

在将新数据添加到 Firestore 之前,我想检查数据库中是否存在相同类型的数据。如果已经存在数据意味着我想防止用户在数据库中输入重复数据。在我的情况下,如果已经存在同一时间的预订,它就像预约预订,我想防止用户在同一时间预订。我尝试使用查询功能,但它不能防止重复数据输入。请帮助我

private boolean alreadyBooked(final String boname, final String bodept, final String botime) {
        final int[] flag = {0};
        CollectionReference cref=db.collection("bookingdetails");
        Query q1=cref.whereEqualTo("time",botime).whereEqualTo("dept",bodept);
        q1.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
            @Override
            public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                for (DocumentSnapshot ds : queryDocumentSnapshots) {
                    String rname, rdept, rtime;
                    rname = ds.getString("name");
                    rdept = ds.getString("dept");
                    rtime = ds.getString("time");
                    if (rdept.equals(botime)) {
                        if (rtime.equals(botime)) {
                            flag[0] = 1;
                            return;
                        }
                    }
                }
            }
        });
        if(flag[0]==1){
            return true;
        }
        else {
            return false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

android firebase google-cloud-firestore

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

无法将 Firestore 添加到我的项目

当我尝试将 firestore 添加到我的项目时。它开始向我显示依赖项错误。我尝试更改与同一版本相关的每个 Firebase 的版本。它显示无法下载 .jar 文件。有人帮我解决这个问题.我包括maven url也没有用....enter code here

我不知道如何手动添加这些 jar 文件。有没有办法解决这个问题。这样这些文件会自动下载。提前谢谢

错误:

app/build.gradle    
Unable to resolve dependency for ':app@debug/compileClasspath': Could not download grpc-core.jar (io.grpc:grpc-core:1.8.0)
<a href="openFile:C:/Users/Sarukesi/AndroidStudioProjects/Seminarbook/app/build.gradle">Open File</a><br><a href="Unable to resolve dependency for &#39;:app@debug/compileClasspath&#39;: Could not download grpc-core.jar (io.grpc:grpc-core:1.8.0)">Show Details</a>  
Unable to resolve dependency for ':app@debug/compileClasspath': Could not download okhttp.jar (com.squareup.okhttp:okhttp:2.7.2)
<a href="openFile:C:/Users/Sarukesi/AndroidStudioProjects/Seminarbook/app/build.gradle">Open File</a><br><a href="Unable to resolve dependency for &#39;:app@debug/compileClasspath&#39;: Could not download okhttp.jar (com.squareup.okhttp:okhttp:2.7.2)">Show Details</a>    
Unable to resolve dependency for ':app@debug/compileClasspath': Could not download protobuf-lite.jar (com.google.protobuf:protobuf-lite:3.0.1)
<a …
Run Code Online (Sandbox Code Playgroud)

android firebase google-cloud-firestore

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

标签 统计

android ×2

firebase ×2

google-cloud-firestore ×2