The downside is that this code path is not optimized at the moment. All the documents will be loaded into memory and sorted first, which can be inefficient if you have a lot of documents. How inefficient depends on the size of the documents and so on, so I can’t give you an exact number. But I would recommend not doing it unless you know that the number of documents (after filtering) is less than 1,000 or 1MB.
Dec 15, 2021, 10:12 AM
So I should stick with the template literal method for performance, in other words?
Dec 15, 2021, 10:13 AM
If possible. Note that the above trick also breaks our ability to optimize slicing. So if you have this:
*[some filter that returns 1 million documents]
| order(select(...)) [0..100]
…then the slow/inefficient ordering will happen on those 1 million documents, even though you’re only extracting 100. With a normal
, we can slice while sorting, which is much faster.