We have received the reply from the Product team:
For performance reasons, we don’t recommend executing queries through stored procedures. You can learn more about the use cases for stored procedures here: https://video2.skills-academy.com/en-us/azure/cosmos-db/stored-procedures-triggers-udfs#benefits-of-using-server-side-programming. Stored procedures are optimized for write-performance, not read performance. We recommend running queries through the SDK.
In this specific case, if you wanted to run this query through a stored procedure, here is a sample workaround:
Original:
fuction (request) {
__.chain()
.sortByDescending(function(item){ return item._ts})
.filter(item => {
return item.userId === request.userId
})
.value();
Workaround:
function(request) {
var inputUserId = request.userId;
__.chain()
.filter(item => item.userId === inputUserId)
.sortByDescending(item => item._ts)
.value();
}
Hope this helps.
Please get back to us for any further questions.
Regards
Navtej S