Javascript SortBy parameters

Hi, there!
I’m trying to retrieve data sorted by parameters but there is no document explaining further javascript.
This is what I have now (“watched” is a boolean field):
var option = {
pageSize: “30”,
sortBy : “watched”
I need to sort results by this watched field then by the name of a related object (1:1).
First question is how to sort by a related object’s propriety?
And how is possible to add more than one parameter to the sortBy?
Thanks in advance!
Tiago Schmidt

Hi Tiago,

You cannot sort by related object properties - it is not supported.

The “sortBy” property must be an array:

sortBy: [“watched”]



I do not believe that there is a current method for requesting that data be returned in descending order of a field.

If this is true, please advise if there are any plans for providing such a facility.

If such a facility was available, the request here about finding the maximum value of a column could be easily accomplished by “requesting a query where records were to be sorted in descending order of this column/field” (page size of 1, as in your suggestion to an earlier question of mine).

It can still be done … albeit by first obtaining the total number of matching records … and then using it as an offset while asking for a sort in ascending order.



Here’s how one can request descended sorting order for a field (using the example for the original post):

sortBy: [“watched DESC”]

You’re right that getting the maximum value in a column can be done that way. Moreover, if you set pageSize to 1, you will get only one object back which will have the max value.



Thank you for the quick answer.

It is good to know that this facility already exists.

A quick check of the documentation did not reveal this facility; perhaps the example on this page could be enhanced to show how one could “return all contacts where the value of the “age” property is greater than 21” (sorted from oldest to youngest).

Thanks again.

Hi, Mark!
sortBy doesnt work for me

var dataQuery = {
		condition: "id_user = '"+code+"'",
		sortBy: ["nameProduct DESC"]
var products = Backendless.Persistence.of(Products).find(dataQuery);
for(var i = 0; i <; i++) {
			console.log("Product name = " +; // here i check And see that it doesnt work