Answers for "how to take random document from firestore android"

0

how to take random document from firestore android

var quotes = firestoreInstance.collection("KEY_COLLECTION");

        var key = quotes.document().id
        Timber.d("key is $key")

        quotes.whereGreaterThan(FieldPath.documentId(), key).limit(1).get()
            .addOnSuccessListener { snapshot ->
                if (snapshot.size() > 0) {
                    snapshot.forEach { doc ->
                        Timber.d("${doc.id} => ${doc.data}")
                    }
                } else {
                    quotes.whereLessThan(FieldPath.documentId(), key).limit(1).get()
                        .addOnSuccessListener { snapshot ->
                            snapshot.forEach { doc ->
                                Timber.d("${doc.id} =>${doc.data}")
                            }
                        }
                }
            }
Posted by: Guest on August-21-2021

Code answers related to "how to take random document from firestore android"

Browse Popular Code Answers by Language