android


Firebase Android unable to query item based on object value - returns all values


I have been working on a Firebase backed Android app and this is what my datatbase looks like
{
"Category" : {
"-KhHnKaR2oS0JKNrAQWr" : {
"CategoryDescription" : "Ne est",
"CategoryName" : "New Test Category",
"CategoryThumbnail" : "/New Test Category/New Test Category-thumb.jpg",
"ThumbnailFileType" : "jpg"
}.......
},
"Images" : {
"-KhHBBI4QloAEBDxcUac" : {
"Category" : "-KhBGZnCQ5xhYVbP0dtd",
"-KhBGZnCQ5xhYVbP0dtd":true,
"CategoryName" : "please",
"FileType" : "jpg",
"FileURL" : "/please/NewAddTest.jpg",
"Name" : "NewAddTest"
},
"-KhI1wWJK8YUApa0Iv9q" : {
"Category" : "-KhHnKaR2oS0JKNrAQWr",
"-KhHnKaR2oS0JKNrAQWr":true,
"CategoryName" : "New Test Category",
"FileType" : "jpg",
"FileURL" : "/New Test Category/Test Mem.jpg",
"Name" : "Test Mem"
}.....
}
}
And I was able to get categories by referring the key 'Category' and initially I had Cateogry and Images embedded i.e,
"-Kh8YUXwK0sg3OyoTyAU" : {
"CategoryDescription" : "The legendary evergreen Vadivelu",
"CategoryName" : "Vadivelu",
"CategoryThumbnail" : "/Vadivelu/v2.png",
"Images":{"-KhH5nJjaji2OtOPVeQF" : {
"Category" : "-KhBGZnCQ5xhYVbP0dtd",
"-KhBGZnCQ5xhYVbP0dtd":true,
"FileType" : "jpg",
"FileURL" : "/please/New jpg",
"Name" : "New "
}}
}
It worked out well but in the Firebase docs I read that it is safer to keep data normalized and flattened so then I came up with the latest one at the top. When I try to query like below it returns all objects rather than the desired ones,
FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference imageRef = database.getReference("Images");
imageRef.keepSynced(true);
try {
imageRef.child("Images").
orderByChild("Images/Category").equalTo(category.memeCategoryID);
imageRef.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Returns all objects.
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
Also I tried to do this,
imageRef.child(category.CategoryID).equalTo(true);
What I intend to do here is implement by multiple - single relationship and fetch all Images tagged to a category, any help is appreciated. I have seen so many threads and the official Firebase documentation is really confusing and does not help me a bit.
When you call orderBy..., equalTo or one of the other methods, Firebase returns a new Query object. So you'll need to capture that query in a new variable:
Query query = imageRef
.child("Images")
.orderByChild("Images/Category")
.equalTo(category.memeCategoryID);
query.addListenerForSingleValueEvent(new ValueEventListener() {

Related Links

Cordova App - unfortunately [app name] has stopped
Change status bar font color on Android
Android AVD not launching
Successfully receive gcm notification but when i click on notification status it opens the activity without any msg
RecyclerView prevents NestedScrollView from minimizing ToolBar
Android Studio Error parsing XML: not well-formed (invalid token) when creating sliding menu
Why is setMargins not working with my RelativeLayout?
Wordpress 4.2.4 Twenty fourteen menu button changing
Let the user change font size
webView.onPause() does not stop audio of a internal video playing
Android 4.1.1 ssl exception while accessing Nasa webservice
Circular View with Button Press Effect
is there a limit on querying the parse installation class?
What is difference between Android and Android Rom?
Android Project Not Create
Android: When i click on my game setting how to deal with it

Categories

HOME
windows
asp.net-web-api
scikit-learn
cobalt
c++11
github-for-windows
pagination
google-spreadsheet
yahoo-finance
socket.io
gembox-spreadsheet
zip
missing-data
mvc5
g++
openpyxl
plist
line
datastage
plink
selectize.js
cumulocity
mathprog
android-7.0-nougat
git-extensions
digital-signature
visual-glitch
dataflow-diagram
joptionpane
resourcebundle
windows-server-2003
maze
surveymonkey
fable-f#
shared
bringtofront
subclass
errbot
magento-1.8
jmockit
openerp-7
lint
recurrent-neural-network
loading
cin
unordered-map
signals-slots
mcustomscrollbar
visa
skylink
congestion-control
importerror
httr
opencmis
phpdbg
mongotemplate
azure-cli
colorbar
sundials
libjpeg
offline.js
javafx-css
reporting-services-2012
actor-platform
eigenvector
upx
nio2
jbase
gocql
ess
ons-api
cgi-bin
snackbar
matlab-deployment
node-serialport
uvc
cryptographichashfunction
at-job
browserify-shim
easyrtc
cocos3d
machine-instruction
angular-carousel
functional-java
android-usb
mt4j
scrypt
inputmismatchexception
mbunit
mongohq
process-explorer
pclzip
swfobject
wimax
joomla3.1
redis-py
uimanageddocument
cakephp-1.2
azman
jsr286
role
saxparseexception
u2netdk
jqote
strsep
appledoc
timertask
django-piston
google-wave
asynchronous-wcf-call
pbcopy
great-circle

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App