在将新数据添加到 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) 当我尝试将 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 ':app@debug/compileClasspath': 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 ':app@debug/compileClasspath': 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)