I'm adding a new document in firestore. After adding a new document when I come back to my activity which is showing those list of documents, my app crashes with the following errors. In my query, I'm ordering the documents with server timestamp.
java.lang.IllegalArgumentException: Invalid query. You are trying to start or end a query using a document for which the field 'additionTime' is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.) at com.google.firebase.firestore.Query.boundFromDocumentSnapshot(com.google.firebase:firebase-firestore@@21.0.0:742) at com.google.firebase.firestore.Query.startAfter(com.google.firebase:firebase-firestore@@21.0.0:632) at com.firebase.ui.firestore.paging.PageKey.getPageQuery(PageKey.java:29) at com.firebase.ui.firestore.paging.FirestoreDataSource.loadAfter(FirestoreDataSource.java:106) at androidx.paging.PageKeyedDataSource.dispatchLoadAfter(PageKeyedDataSource.java:338) at androidx.paging.ContiguousPagedList$3.run(ContiguousPagedList.java:228) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761)
It only happens when I'm adding the first document. My POJO class is here
public class BookLight implements Serializable {
private String bookId;
private String bookName;
private String authors;
private float rating;
private String category;
private String thumbnail;
private BookState bookState;
private String ownerID;
@ServerTimestamp
private Date additionTime;
public BookLight(){
}
//other getters and settes
public Date getAdditionTime() {
return additionTime;
}
public void setAdditionTime(Date additionTime) {
this.additionTime = additionTime;
}
}
Here I'm using FirestorePagingAdapter
for showing those items
private FirestorePagingAdapter<BookLight, BookViewHolder> mAdapter;
private void loadData(){
query= FirebaseFirestore.getInstance()
.collection("Groups")
.document(groupDetails.getGroupID())
.collection("books")
.orderBy("additionTime",Query.Direction.DESCENDING);
PagedList.Config config = new PagedList.Config.Builder()
.setEnablePlaceholders(false)
.setPrefetchDistance(5)
.setPageSize(3)
.build();
FirestorePagingOptions<BookLight> options = new FirestorePagingOptions.Builder<BookLight>()
.setLifecycleOwner(this)
.setQuery(query, config, BookLight.class)
.build();
mAdapter = new FirestorePagingAdapter<BookLight, BookViewHolder>(options) {
@NonNull
@Override
public BookViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new BookViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.book_row_item, parent, false));
}
@Override
protected void onBindViewHolder(@NonNull BookViewHolder bookViewHolder, int position, @NonNull final BookLight book) {
}
@Override
protected void onError(@NonNull Exception e) {
super.onError(e);
mSwipeRefreshLayout.setRefreshing(false);
}
};
recyclerView.setAdapter(mAdapter);
}