Firebase Database Rest Api: EndAt() Returns Duplicate Result When multiple nodes with same value

OLIVER

I hope you have a good day

I'm using the Firebase Database Rest API to fetch the first top 10 posts ordered by (Views) and When I fetch the first 10 posts, there is no problem Like This:

https://ameen-66522.firebaseio.com/Main/News/Categories/Education/.json?print=pretty&orderBy=%22Views%22&limitToLast=10

{
  "-Mn7-ZxkUPO01ifh2tpEn" : {
    "Text" : "Im 11",
    "Title" : "some title",
    "Views" : 11
  },
  "-Mn7-ZxkUPO01ifh2txpEn" : {
    "Text" : "Im 11 Two",
    "Title" : "some title",
    "Views" : 11
  },
  "-Mn7-ZxkUPO01ifhds2tpEn" : {
    "Text" : "some text",
    "Title" : "some title",
    "Views" : 13
  },
  "-Mn7-ZxkUPO01ifhewtpEn" : {
    "Text" : "some text",
    "Title" : "some title",
    "Views" : 14
  },
  "-Mn7-ZxkUPO01ifhtdxpEn" : {
    "Text" : "some text",
    "Title" : "some title",
    "Views" : 15
  },
  "-Mn7-ZxkUPO01ifhtp11En" : {
    "Text" : "some text",
    "Title" : "some title",
    "Views" : 16
  },
  "-Mn7-ZxkUPO01sdifhtpEn" : {
    "Text" : "some text",
    "Title" : "some title",
    "Views" : 17
  },
  "-Mn7-ZxkUPOd01ifh2tpEn" : {
    "Text" : "some text",
    "Title" : "some title",
    "Views" : 18
  },
  "3342323231" : {
    "Text" : "d",
    "Title" : 24,
    "Views" : 19
  },
  "444444444444" : {
    "Text" : "dd",
    "Title" : "xzx",
    "Views" : 20
  }
}

And when I sort first 10 elements in order of highest Views The last id will be -Mn7-ZxkUPO01ifh2txpEn And when I fetch another 11 elements starting from the LastId and LastValue it will return the result of a duplicate data because there are two elements with the same value of (Views) but it is supposed to not do that because I have passed the LastValue as well as the LastId Like this:

https://ameen-66522.firebaseio.com/Main/News/Categories/Education/.json?print=pretty&orderBy=%22Views%22&limitToLast=11&endAt=11,%22-Mn7-ZxkUPO01ifh2txpEn%22

I expected it would return a duplicate result which is the last element only -Mn7-ZxkUPO01ifh2txpEn I can remove it easily but why does it return other elements that were shown in the first 10 ?

I tried not to make any item contain a duplicate value and the results are correct and there are no duplicate posts So what is the solution to this problem?

Sorry for the long post, and thank you :)

Frank van Puffelen

When you get the final page of results with https://ameen-66522.firebaseio.com/Main/News/Categories/Education/.json?print=pretty&orderBy=%22Views%22&limitToLast=10, the first two nodes in the results are:

"-Mn7-ZxkUPO01ifh2tpEn" : {
  "Text" : "Im 11",
  "Views" : 11
},
"-Mn7-ZxkUPO01ifh2txpEn" : {
  "Text" : "Im 11 Two",
  "Views" : 11
},

In the call in your question you're passing in the -Mn7-ZxkUPO01ifh2txpEn key, which is the second key from the results you already had. So that's then also where Firebase starts/ends the slice of data it returns.

If you want only one overlapping item, use key -Mn7-ZxkUPO01ifh2tpEn: https://ameen-66522.firebaseio.com/Main/News/Categories/Education/.json?print=pretty&orderBy=%22Views%22&limitToLast=11&endAt=11,%22-Mn7-ZxkUPO01ifh2tpEn%22

This will then give you these results:

{
  "-Mn7-ZxkUPO01dxifhtpEn" : {
    "Text" : "some text",
    "Views" : 1
  },
  "-Mn7-ZxkUPO01iddfh2tpEn" : {
    "Text" : "some text",
    "Views" : 2
  },
  "-Mn7-ZxkUPO01idsdfh2tpEn" : {
    "Text" : "some text",
    "Views" : 3
  },
  "-Mn7-ZxkUPO01idsdfhtpEn" : {
    "Text" : "some text",
    "Views" : 4
  },
  "-Mn7-ZxkUPO01idxfh2tpEn" : {
    "Text" : "must 5",
    "Views" : 6
  },
  "-Mn7-ZxkUPO01ifddhtpEn" : {
    "Text" : "some text",
    "Views" : 5
  },
  "-Mn7-ZxkUPO01ifdshtpEn" : {
    "Text" : "must 7",
    "Views" : 7
  },
  "-Mn7-ZxkUPO01ifh21tpEn" : {
    "Text" : "some text",
    "Views" : 8
  },
  "-Mn7-ZxkUPO01ifh2dstpEn" : {
    "Text" : "some text",
    "Views" : 9
  },
  "-Mn7-ZxkUPO01ifh2tpEdsn" : {
    "Text" : "some text",
    "Views" : 10
  },
  "-Mn7-ZxkUPO01ifh2tpEn" : {
    "Text" : "Im 11",
    "Views" : 11
  }
}

I recommend using more readable and recognizable keys in a repro such as this, as it's quite easy to overlook the difference in those two keys in the first snippet.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Get multiple child nodes in Firebase with REST API

Android, Firebase - database only returns single child node as string when trying to retrieve multiple child nodes

Firebase Database Rest Api : How to OrderBy with Unknown nodes

Access Multiple Nodes in Firebase Database

Multiple Nodes , Search Firebase Database

Why Firebase Database REST API returns no-cache header

How to use startAt(double value, String key) and endAt(double value, String key) Firebase RealTime Database in Android

When i run cron for a database function it returns me the same value

Update single value in Firebase Realtime Database using Rest API

firebase database queries and returns value true, but still goes forward if user exists, and register a duplicate entry

How to read same value from nodes with different keys in Firebase real-time database?

Search across multiple nodes in firebase realtime database

Firebase Database in Unity with REST API

DatabaseException when iterating nested Firebase database nodes

Search function returns the same result multiple times

how to add the incremented integer for a duplicate value of a property when 2 nodes have same property value in neo4j?

isPrime returns different result for the same value?

merging multiple attribute nodes with same value

How do I edit the value of a specific node in XML when there are multiple nodes with the same name?

Spring boot rest response gives 1 result on OneToMany when there are multiple objects in database

Firebase Database Listener returns null value

what is the different betwen "equalTo" and "startAt & endAt" in firebase and when i should use "equalTo" or "startAt and endAt"?

Multiple REST API calls in succession returns undefined

JSONArray duplicate same result

how to write to firebase database using rest api?

Firebase Real Time Database - Rest API - Pagination

Firebase Database REST API Increase Number

Save multiple data with same uid to Firebase database

How to Iterate through nodes and skip duplicate nodes with same value- XSLT 1,0