Reputation: 13
Hy I am new to android and fire store I am trying to get data from a collection by last entry first
if some have any advice on how am I supose to do that it will be very helpful
mFireStore.collection(Constans.BOARDS)
//.whereArrayContains(Constans.ASSIGNED_TO, getCurrentUid())
.get()
.addOnSuccessListener {
document ->
Log.e("getBoardsList",document.documents.toString()+"inside addOnSuccessListener")
Log.e("getBoardsList","inside addOnSuccessListener")
Constans.BOARDS_CHATS_LIST = ArrayList()
for (i in document.documents){
val board = i.toObject(Board::class.java)!!
for (j in board.assinedTo) {
if (getCurrentUid() == j) {
board.documentId = i.id
Log.e("documentId", "${i.id}")
Constans.BOARDS_CHATS_LIST.add(board)
}
}
}
Log.e("getBoardsList","${Constans.BOARDS_CHATS_LIST.size.toString()}")
//activity.hideProgressDialog()
}.addOnFailureListener {
e ->
//activity.hideProgressDialog()
Log.e("getBoardsList","Error while creating the board"+"inside addOnFailureListener",e)
}
}
Upvotes: 0
Views: 29
Reputation: 317392
Firestore doesn't maintain a time-based ordering of any documents. If you want to know what the "last" document is, you'll have to put some sort of timestamp in a field in each document, then order the query by that field. Otherwise, what you're trying to do is impossible.
Upvotes: 1