Hi,
I have this problem in query in Firebase. The orderbykey() and orderbychild() doesn't work. How do I query this one?
cheers, thanks in advance.
Code Snippet:
Query mRef = mRootRef.child("Messages").orderByKey().equalTo(mAuth.getCurrentUser().getUid());
Query mRef = mRootRef.child("Messages").orderByChild("commWith").equalTo(mAuth.getCurrentUser().getUid());
i have just re design my JSON at firebase like in the image below, so that i could simply get the unique keys per data
Related
database structure
I'm completely new to realtime database and nosql and want some help.
How do I fetch all the data. from only the keys starting with 2020, from the following database structure?
How do I fetch all the data. from only the keys starting with 2020, from the following database structure?
Firebase doesn't provide a way to filter the records by keys that start with a particular String. The most simple solution I can think of is to change the "year" property in your database to be of type number and not String, otherwise, you'll have a lexicographical order. To solve this, you need to use a query that looks like this:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference calendarRef = rootRef.child("calendar");
Query yearQuery = calendarRef.orderByChild("year").startAt(2000).endAt(2001);
yearQuery.addListenerForSingleValueEvent(/* ... */);
This will return all records where the "year" property holds the value of 2000.
I am working on a android Firebase project. I need help in implementing this sql query in Firebase real-time database.
SELECT * FROM table
WHERE price BETWEEN $min AND $max;
There's good documentation on how to do firebase queries as well as apply them to ranges.
Something like:
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("table");
Query query = ref.orderByChild("price").startAt(min).endAt(max);
Then you add the appropriate listener for what you are trying to do. (e.g. a ValueEventListener or a ChildEventListener via addValueEventListener or addChildEventListener respectively.
You can use the following method
new Firebase("https://examples-sql-queries.firebaseio.com/messages")
.startAt(startTime)
.endAt(endTime)
.once('value', function(snap) {
console.log('messages in range', snap.val());
});
I want to fetch the specific data from the firebase into the android app.
I want to be fetch only that data where ar="Atif Aslam". How I can do that?
This is my database
try the following code:
DatabaseReference mDatabaseReference = FirebaseDatabase.getInstance().getReference("uploads");
Query query
= mDatabaseReference.orderByChild("ar").equalTo("Atif Aslam");
refer examples from firebase official site:https://firebase.google.com/docs/reference/android/com/google/firebase/database/Query
Hope this helps.
Try using firebase.database.Query
Query msgQuery = childRef.orderByChild("ar").equalTo("Atif Aslam");
msgQuery.addChildEventListener(MainActivity.this);
This is the link for image
I want to get the msg from the above data where sender equals to salam..can any body help me out how to write query in firebase database(Android)..I am new to this firebase..
The query will be pretty straightforward, but there are multiple ways you can implement the query listeners depending on your use case. If you only want to read your data once, you can setup the following query.
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
ref.child("messages").orderByChild("sender").equals("salam")
.addListenerForSingleValueEvent(new ValueEventListener({...}));
See https://firebase.google.com/docs/database/android/read-and-write for the startup tutorial and https://firebase.google.com/docs/reference/android/com/google/firebase/database/DatabaseReference for the full documentation.
I have the following structure saved in my database:
What I want is I want the databaseReference to recognise the entire node using only the unique imageUIDh and display the content of all fields like postedAtTime, postedOnDate etc.
Is this possible in Firebase? Is there some alternative to achieve what I want?
Please let me know.
You can use Query
ref = FirebaseDatabase.getInstance().getReference();
ref.orderByChild("imageUIDh").equalTo(imageUIDh).addValueEventListener(valueEventListener);
Hope this helps :)