英文:
Why can't i get all the document from a collection in my Firestore Database?
问题
尝试从Firestore获取文档时,即使我的集合中有20个文档,我只能获取到8个。使用下面的代码,仅显示了8条日志消息:
mFStore.collection("In")
.orderBy("Time of submit", Query.Direction.ASCENDING)
.whereGreaterThanOrEqualTo("Time of submit", startDateTimeStamp)
.whereLessThanOrEqualTo("Time of submit", endDateTimeStamp)
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
List<DocumentSnapshot> snapshotList = queryDocumentSnapshots.getDocuments();
for (DocumentSnapshot snapshot : snapshotList) {
Timestamp timestamp = (Timestamp) snapshot.getData().get("Time of submit");
Date date = timestamp.toDate();
String day = format.format(date);
String strQty = snapshot.get("Quantity").toString();
Log.d(TAG, day + " ," + strQty);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, e.getMessage());
}
});
使用下面的代码,我尝试删除上述的3个查询条件,但仍然只能获取到15条日志消息:
mFStore.collection("In")
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public onSuccess(QuerySnapshot queryDocumentSnapshots) {
List<DocumentSnapshot> snapshotList = queryDocumentSnapshots.getDocuments();
for (DocumentSnapshot snapshot : snapshotList) {
Timestamp timestamp = (Timestamp) snapshot.getData().get("Time of submit");
Date date = timestamp.toDate();
String day = format.format(date);
String strQty = snapshot.get("Quantity").toString();
Log.d(TAG, day + " ," + strQty);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, e.getMessage());
}
});
这是我的数据库结构的图片:
有人能告诉我是否实际上获取了所有文档,但某种方式没有获取到所有的日志,还是我只获取到了部分文档?
英文:
I was trying to get documents from Firestore with query but even though my collection has 20 documents I can only get 8.
With the code below only 8 log messages was shown:
mFStore.collection("In")
.orderBy("Time of submit", Query.Direction.ASCENDING)
.whereGreaterThanOrEqualTo("Time of submit",startDateTimeStamp)
.whereLessThanOrEqualTo("Time of submit",endDateTimeStamp)
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
List<DocumentSnapshot> snapshotList = queryDocumentSnapshots.getDocuments();
for(DocumentSnapshot snapshot: snapshotList){
Timestamp timestamp = (Timestamp) snapshot.getData().get("Time of submit");
Date date = timestamp.toDate();
String day = format.format(date);
String strQty = snapshot.get("Quantity").toString();
Log.d(TAG ,day + " ," + strQty);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG ,e.getMessage());
}
});
With the code below, I've tried removing all the 3 queries from above but I still was only getting 15 log messages.
mFStore.collection("In")
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
List<DocumentSnapshot> snapshotList = queryDocumentSnapshots.getDocuments();
for(DocumentSnapshot snapshot: snapshotList){
Timestamp timestamp = (Timestamp) snapshot.getData().get("Time of submit");
Date date = timestamp.toDate();
String day = format.format(date);
String strQty = snapshot.get("Quantity").toString();
Log.d(TAG ,day + " ," + strQty);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG ,e.getMessage());
}
});
Here is a picture of my database:
my_database_structure
Can someone tell me if I'm actually getting all the document but somehow not getting all the logs or am I just not getting all my documents?
答案1
得分: 0
我不知道我需要为这些查询添加indexes。在我添加它们之后,我成功获取了所有我想要的文档。
英文:
I didn't know I needed to add indexes for the queries. After I added them, I managed to get all the documents I wanted.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论