-
Notifications
You must be signed in to change notification settings - Fork 131
orderByChild not working #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If I use the following query the result is in the correct order:
Am I not using the correct method? I just need to load all by createdAt |
What platform are you testing it on or is it both (iOS/Android)? |
I'm only testing on android at the moment. I'm also having the same issue with the following query: Works with Firebase JS API: Doesn't work with Firestack: Firestack doesn't return correct order and when calling again to get next 'page' of posts based on the last item key endAt it ignores this and returns that last items. |
Great. I'll take a look... thanks for reporting! Does it work on iOS as expected? |
Np! I'd love to help troubleshoot this further and looked through the JS/Java to see if I could find anything. Please let me know what you find so I can possibly be a better help in the future haha |
I haven't been testing on iOS yet, but if I do i'll let you know. |
I found it, I think. I haven't been able to test it yet, but I'm pretty certain I know the issue |
Awesome! let me know if you have a patch and I can test it out |
@tegument I just pushed a branch called |
Yes. I know the fix for this. Apologies about the delay. I've been jet lagged from my trip! |
It does not work with iOs either |
@auser I too encountered this issue and after debugging I found that the |
Oh yes. I added a map and for each function on snapshot to retain the order |
@auser I am not sure I understand what you mean. |
@auser I got what you were saying. But the problem is not in the iteration, it's in WritableMap. When new key/values are pushed it does not maintain the insert order. The solution I can think of is to use a JSON Writer to construct the response. |
It's not about iterating. The way forEach and map work is by using the ordered keys in response. The response, if contains keys returns with objects with keys, the native side returns the list of keys as an ordered array. On Sun, Nov 13, 2016 at 5:30 AM -0800, "Chaitanya Bhagvan" notifications@github.com wrote: @auser I got what you were saying. But the problem is not in the iteration, it's in WritableMap. When new key/values are pushed it does not maintain the insert order. The solution I can think of is to use a JSON Writer to construct the response. — |
By the way, this is the same approach as the web library takes to handle ordering. |
@auser If I understand correctly then you are saying the response is an ordered array, but the snapshot.value or snapshot.val() is an object and does not have map or forEach methods on it. |
@auser This happening only on android. iOS works just fine. |
Not sure how it could... also I was talking about the master branch, not npm. Js objects do not respect ordering on keys, so if it is working, it by happenstance. |
Technically how we handle it is through storing the ordered list of keys and mapping through the array of keys in the forEach and map methods on the snapshot |
@auser I'm having this issue on iOS. I believe there is an issue with how data is being returned to JS in general, not just with the
In the data browser, it is ordered as above. If I request it with the web JS library, it comes back correctly in the above order. However, when I request this data via firestack, this order is not maintained. Even if I use the My first thought is that the shuffling might be happening when the data gets transferred from native to JS. |
I should note that I'm using the npm version, not the latest from master |
I experience the same issue on V3 branch. orderByChild takes no effect… also using orderByChild and .endAt() has no effect at all. I have a list of messages with a timestamp, trying to query for messages before a given point at time. works with js sdk, but not with firestack (v3 branch) |
@smkhalsa @florianbepunkt Use the master branch. The one on npm does not have this feature. |
@chaitanya0bhagvan I created a new issue since I'm using v3 branch… maybe orderByChild is not implemented in this branch yet. #174 |
Not sure about the branch (yet), but I just pushed a new |
@auser Thank you. I will wait and see if this is in Michael's branch which I'm using due to the different syntax. If not I will switch and rewrite my firestack calls. You say we have to use the JS function to keep the order. Is there any extra method involved or can we use something like
|
@auser Thanks! It looks like |
@florianbepunkt it's a method on the database ref representation object, so it would happen in the firestack
.ref('foo')
.orderby('bar').
.endAt('foo')
.once('value')
.then(ref => this.setState({items: ref.map(i => i)})); The |
I have items stored in firebase with a 'createdAt' property which is the server TIMESTAMP. The TIMESTAMP value is being set correctly, but when querying using orderByChild('createdAt') the order is not correct.
I have verified that the same query run with the firebase javascript API works as expected:
firestack.database.ref('images').orderByChild('createdAt').once('value', (snapshot)=>{ // snapshot not ordered by correctly });
Firebase javascript API:
firebaseApp.database().ref('images').orderByChild('createdAt').once('value', (snapshot)=>{ // snapshot ordered correctly });
I have an index set in my firebase rules but can't seem to get Firestack to use the orderByChild query
The text was updated successfully, but these errors were encountered: