WixDataQuery sort question

I can’t seem to use a variable for the .ascending() / .descending() property (line 6).
I get an error message “Unsupported sort field ascending” whenever I tried it.

Is this a limitation by design?

1. import wixData from 'wix-data';
2. let sortField = "name";
3. 
4.  wixData.query("Customer")
5.    .gt("age", 20)
6.    .ascending(sortField)
7.    .limit(15)
8.   .find()
9.   .then( (results) => {
10.     console.log(results.items);
11.   } );

#wixdataquery #ascending #descending

No. Your code looks fine. Check your collection. Maybe the “name” field is an array or an object instead of type:text ?

In my actual use case I’m querying the Form/Posts table and the field I want to sort is the ‘viewCount’ (which is a number).

Whenever I use a variable it fails. Whenever I use the actual string value it works. Is this a defect?

No. It’s supposed to work even when you pass a variable.

I’m using variables for .gt(), .ge(), and .limit() without issue. But as soon as I try it with .ascending() or .descending() it bombs. I suppose I could prepare a video to demonstrate and submit it to support. Thoughts?