content icon indicating copy to clipboard operation
content copied to clipboard

Can I sort query results by nth element of an array in a specific key?

Open yacoob opened this issue 4 years ago • 0 comments

I have files with data that looks like this after loading:

{
  "title": "Exia",
  "entries": [
    {
      "date": "2012-10-12T00:00:00.000Z",
      "cover": "photo9.jpg",
    },
    {
      "date": "2013-04-22T00:00:00.000Z",
      "cover": "photo13.jpg",
    },
  ]
  ...
}

Is there any way for me to write a query that would sort the retrieved data nodes by entries[0]? Or entries[entries.length-1]? The naive approach doesn't work, and after some code spelunking I'm unsure whether the underlying Loki engine is able to handle this.

In my case, each data node as above has at least one or more objects in entries, each of them with a date. I need to get 5 newest entries across the entire dataset. Right now I need to query for all the data, collate all of its entries, sort them, grab top 5. Anything more elegant that I can be doing here?

Thanks!

yacoob avatar Jul 24 '21 19:07 yacoob