Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save senamit2708/19b0f4bf116df0d992fe4a58dc74e803 to your computer and use it in GitHub Desktop.
Save senamit2708/19b0f4bf116df0d992fe4a58dc74e803 to your computer and use it in GitHub Desktop.
How to check a specific key is present in the documents of the collection
private void loadRecentWords() {
db.collection("TwordColl")
.orderBy("time", Query.Direction.DESCENDING)
.limit(10)
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value,
@Nullable FirebaseFirestoreException e) {
if (e!= null){
Log.w(TAG, "listen failed "+e);
return;
}
if (value.isEmpty()){
mMarkedWorkListLive.setValue(null);
}else {
List<WordModel> wordList = new ArrayList<>();
for (QueryDocumentSnapshot doc : value){
String wo = doc.getString("wo");
String tr = doc.getString("tr");
long languageCheck=0;
// if (!TextUtils.isEmpty(doc.getLong("lan").toString())){
// languageCheck = doc.getLong("lan");
// }
if (doc.get("lan")!= null){
languageCheck = doc.getLong("lan");
Log.i(TAG, "the language is "+languageCheck);
}
Log.i(TAG, "wo is "+wo +" tr is "+tr);
boolean mark = doc.getBoolean("mark");
wordList.add(new WordModel(wo, tr, mark, languageCheck));
}
mRecentWordListLive.setValue(wordList);
}
}
});
}
//this query is used to check if key is available, if yes then get value of this key.
if (doc.get("lan")!= null){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment