Can I get the nth item of a firebase “query”?

前端 未结 2 1384
闹比i
闹比i 2020-12-19 11:19

Firebase has some very basic query functionality with orderBy*, limitTo*, startAt(), etc. Is there a way to tell Firebase you want the

2条回答
  •  悲&欢浪女
    2020-12-19 12:05

    Note that in conjunction with @frank-van-puffelen 's answer, you can also use the shallow argument to the top-level query.

    I don't know how this is translated to the JavaScript firebase API, but with curl, this would be something like:

    curl 'https://your-site.firebaseio.com/questions.json?shallow=true'
    

    which returns something like:

    {
      "-Ju2tGTo6htY2e4mbuPO": true,
      "-Ju3AWjZnhnUw_OfGyk4": true,
      "-JughjjzbFOxjevE2ykY": true,
      "-Jw3cciI6ZpoK1ejfK58": true,
      "-Jw4NhcgJ9DnenBVphyq": true,
      "-JwE5ojQ5ZjkvTzVK9E2": true,
      "-JwE7Qbpf9r1YN8Qaoss": true,
      "-JwFIQ3pGMCI0E3xzPIz": true,
    }
    

    Then, once you've gotten your shallow list of items, you can query them one at a time in any order you want by accessing the key directly:

    curl 'https://your-site.firebaseio.com/questions/-Ju2tGTo6htY2e4mbuPO.json'
    

提交回复
热议问题