Created
May 16, 2019 05:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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