{"action":"created","issue":{"url":"https://api.github.com/repos/invertase/react-native-firebase/issues/521","repository_url":"https://api.github.com/repos/invertase/react-native-firebase","labels_url":"https://api.github.com/repos/invertase/react-native-firebase/issues/521/labels{/name}","comments_url":"https://api.github.com/repos/invertase/react-native-firebase/issues/521/comments","events_url":"https://api.github.com/repos/invertase/react-native-firebase/issues/521/events","html_url":"https://github.com/invertase/react-native-firebase/issues/521","id":265896032,"number":521,"title":"[Android] orderByChild and limitToLast are not working properly together","user":{"login":"dgruseck","id":3001347,"avatar_url":"https://avatars3.githubusercontent.com/u/3001347?v=4","gravatar_id":"","url":"https://api.github.com/users/dgruseck","html_url":"https://github.com/dgruseck","followers_url":"https://api.github.com/users/dgruseck/followers","following_url":"https://api.github.com/users/dgruseck/following{/other_user}","gists_url":"https://api.github.com/users/dgruseck/gists{/gist_id}","starred_url":"https://api.github.com/users/dgruseck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgruseck/subscriptions","organizations_url":"https://api.github.com/users/dgruseck/orgs","repos_url":"https://api.github.com/users/dgruseck/repos","events_url":"https://api.github.com/users/dgruseck/events{/privacy}","received_events_url":"https://api.github.com/users/dgruseck/received_events","type":"User","site_admin":false},"labels":[{"id":576623451,"url":"https://api.github.com/repos/invertase/react-native-firebase/labels/database","name":"database","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2017-10-16T19:57:58Z","updated_at":"2017-10-23T11:27:58Z","closed_at":null,"author_association":"NONE","body":"### Issue\r\n\r\nIf I try to order by a pushKey and limit the result to 10 I only receive 1 entry.\r\n```javascript\r\nchannelsRef\r\n  .orderByChild('orderKey')\r\n  .limitToLast(10);\r\n```\r\n\r\nThe database looks like this:\r\n```\r\n-pushKey1\r\n     orderKey: \"-pushKey11\"\r\n-pushKey2\r\n     orderKey: \"-pushKey21\"\r\n...\r\n```\r\n\r\nIf I add a endAt(...) everthing works fine or if the orderByChild is a number it also works fine.\r\nThis error only occurs on android.\r\nWith RNFirebase version 2.1.4 it also worked fine.\r\n\r\n### Environment\r\n\r\n<!--- (e.g. iOS, Android, Both) --->\r\n1. Application Target Platform: Android\r\n\r\n<!--- (e.g. macOS Sierra, Windows 10) --->\r\n2. Development Operating System: macOS High Sierra\r\n\r\n<!--- (Xcode or Android Studio version, iOS or Android SDK version - if relevant) --->\r\n3. Build Tools: buildToolsVersion \"25.0.3\"\r\n```\r\ncompile \"com.google.android.gms:play-services-base:11.4.2\"\r\ncompile \"com.google.firebase:firebase-core:11.4.2\"\r\ncompile \"com.google.firebase:firebase-database:11.4.2\"\r\n```\r\n\r\n<!--- (e.g. 0.45.1) --->\r\n4. React Native version: 0.49.1\r\n\r\n<!--- (e.g. 2.1.3) --->\r\n5. RNFirebase Version: 3.0.3\r\n\r\n<!--- (e.g. database, auth, messaging, analytics etc - or N/A if not applicable) --->\r\n6. Firebase Module: database\r\n"},"comment":{"url":"https://api.github.com/repos/invertase/react-native-firebase/issues/comments/338629278","html_url":"https://github.com/invertase/react-native-firebase/issues/521#issuecomment-338629278","issue_url":"https://api.github.com/repos/invertase/react-native-firebase/issues/521","id":338629278,"user":{"login":"chrisbianca","id":10723021,"avatar_url":"https://avatars0.githubusercontent.com/u/10723021?v=4","gravatar_id":"","url":"https://api.github.com/users/chrisbianca","html_url":"https://github.com/chrisbianca","followers_url":"https://api.github.com/users/chrisbianca/followers","following_url":"https://api.github.com/users/chrisbianca/following{/other_user}","gists_url":"https://api.github.com/users/chrisbianca/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisbianca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisbianca/subscriptions","organizations_url":"https://api.github.com/users/chrisbianca/orgs","repos_url":"https://api.github.com/users/chrisbianca/repos","events_url":"https://api.github.com/users/chrisbianca/events{/privacy}","received_events_url":"https://api.github.com/users/chrisbianca/received_events","type":"User","site_admin":false},"created_at":"2017-10-23T11:27:58Z","updated_at":"2017-10-23T11:27:58Z","author_association":"COLLABORATOR","body":"I've just set up some simple test cases for this to try and establish whether it's the native SDK or RNFirebase causing the issue, and I can't actually reproduce this at all. You can check the full code here: https://github.com/invertase/react-native-firebase/commit/a42194a32acc3f8e3a68ac5fe7f6f78cf64a54ce\r\n\r\nMy data is as follows:\r\n```\r\n521: {\r\n      key1: {\r\n        name: 'Item 1',\r\n        number: 1,\r\n        string: 'item1',\r\n      },\r\n      key2: {\r\n        name: 'Item 2',\r\n        number: 2,\r\n        string: 'item2',\r\n      },\r\n      key3: {\r\n        name: 'Item 3',\r\n        number: 3,\r\n        string: 'item3',\r\n      },\r\n    },\r\n```\r\nI have checked the following:\r\n\r\nOrdering on the `number` field:\r\n1) `firebase.database().ref('tests/issues/521').orderByChild('number').limitToLast(2).on('value') - correctly returns: the objects for `key2` and `key3`\r\n2) `firebase.database().ref('tests/issues/521').orderByChild('number').limitToLast(2).once('value') - correctly returns: the objects for `key2` and `key3`\r\n3) Add: `key4: { name: 'Item 4', number: 4, string: 'item4' }` and the `.once` listener gets called a second time with the objects for `key3` and `key4`\r\n\r\nRepeated the same when ordering on the `string` field, which gave the same results.\r\n\r\nI think we might have a few crossed over issues here so let me try and help you all.\r\n\r\n@dgruseck I think I need to see more of your code in order to help understand where you're going wrong.\r\n\r\n@amitbravo Am I right in thinking that you're increasing the pagesize that is sent to the `limitToLast` as you're scrolling down the list?  If that's the case, then your issue is probably because you're not calling `.off()` on the previous listener before adding the new listener.\r\n\r\n@yernandus Again, I'll need to see some more of your code before being able to help you out."}}
{"actor":{"display_login":"chrisbianca"}}