在 Firestore 中添加数据的方法
Way to Add data in Firestore
我正在创建一个 Java 应用程序,并使用 firestore 作为数据库,我打算在用户单击“加入 Btn”时将数据添加到 Firestore。所有变量都已在模型 class 中定义。现在的问题是当我点击 Join Btn 时,数据没有存储在 Firestore 中。我不确定为什么会这样。
下面显示模型 class 和 addedToJoined 函数。
private String eventName;
private String eventDate;
private String eventVenue;
private String eventDesc;
private String eventDocId;
private void addedToJoined(){
final HashMap<String, Object> joinedMap = new HashMap<>();
joinedMap.put("eventName", event.getEventName());
joinedMap.put("eventDate", event.getEventDate());
joinedMap.put("eventVenue", event.getEventVenue());
joinedMap.put("eventDesc", event.getEventDesc());
final HashMap<String, Object> participant = new HashMap<>();
participant.put("eventName", event.getEventName());
participant.put("participated_users_name", fAuth.getCurrentUser().getDisplayName());
fStore.collection("CurrentUser").document(fAuth.getCurrentUser().getUid())
.collection("MyFavourite").add(joinedMap).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
@Override
public void onComplete(@NonNull @NotNull Task<DocumentReference> task) {
Toast.makeText(EventDetail.this, "Event saved.", Toast.LENGTH_SHORT).show();
finish();
}
});
fStore.collection("EventDetail").document(event.getEventDocId()).collection("event").add(participant).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
@Override
public void onComplete(@NonNull @NotNull Task<DocumentReference> task) {
Toast.makeText(EventDetail.this, "Event added to record.", Toast.LENGTH_SHORT).show();
finish();
}
});
}
尝试在 public documentation in which the whole description of storing data into Firestore has been provided with the help of onSuccess and onFailure listeners and the video 的帮助下实现代码,在 06:36 处使用 onComplete Listener 对其进行了解释,如果问题仍然存在,请分享任何错误您收到的消息。
我正在创建一个 Java 应用程序,并使用 firestore 作为数据库,我打算在用户单击“加入 Btn”时将数据添加到 Firestore。所有变量都已在模型 class 中定义。现在的问题是当我点击 Join Btn 时,数据没有存储在 Firestore 中。我不确定为什么会这样。
下面显示模型 class 和 addedToJoined 函数。
private String eventName;
private String eventDate;
private String eventVenue;
private String eventDesc;
private String eventDocId;
private void addedToJoined(){
final HashMap<String, Object> joinedMap = new HashMap<>();
joinedMap.put("eventName", event.getEventName());
joinedMap.put("eventDate", event.getEventDate());
joinedMap.put("eventVenue", event.getEventVenue());
joinedMap.put("eventDesc", event.getEventDesc());
final HashMap<String, Object> participant = new HashMap<>();
participant.put("eventName", event.getEventName());
participant.put("participated_users_name", fAuth.getCurrentUser().getDisplayName());
fStore.collection("CurrentUser").document(fAuth.getCurrentUser().getUid())
.collection("MyFavourite").add(joinedMap).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
@Override
public void onComplete(@NonNull @NotNull Task<DocumentReference> task) {
Toast.makeText(EventDetail.this, "Event saved.", Toast.LENGTH_SHORT).show();
finish();
}
});
fStore.collection("EventDetail").document(event.getEventDocId()).collection("event").add(participant).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
@Override
public void onComplete(@NonNull @NotNull Task<DocumentReference> task) {
Toast.makeText(EventDetail.this, "Event added to record.", Toast.LENGTH_SHORT).show();
finish();
}
});
}
尝试在 public documentation in which the whole description of storing data into Firestore has been provided with the help of onSuccess and onFailure listeners and the video 的帮助下实现代码,在 06:36 处使用 onComplete Listener 对其进行了解释,如果问题仍然存在,请分享任何错误您收到的消息。