Which Is More Better Firebase Using Query Or Using Normal Reference
I noticed there are 2 types to retrieve a user data. Which one is better?
firebaseDatabase = FirebaseDatabase.getInstance();
usersDbRef = firebaseDatabase.getReference().child("Users");
//Using Query
Query userQuery = usersDbRef.orderByChild("uid").equalTo(userUid);
//Using Normal
DatabaseReference dbRefUser = usersDbRef.child(userUid);
//And then get user name and etc...
Answer
When you are using the following line of code:
usersDbRef = firebaseDatabase.getReference().child("Users");
You are getting all users that exist within Users
node without any limitations.
If you are using a query, you can add limitations and ordering to your items. For example, let's say you have a node that contains 1000 items. For sure you won't use a simple reference because getting 1000 items at once, will be a waste of bandwidth and resources, since no users are interested in 1000 items. What you can do instead is to add a call to limit(50)
and display only 50 items. So a query is needed to filter results and according to the use-case of your app, you can use one or the other in your project.
When using:
DatabaseReference dbRefUser = usersDbRef.child(userUid);
You tell Firebase that you are interested only in a single user object. So in this case, these is no need for a query, a simple reference will do the job.
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View