I can't order using query method

Hi,

I'm getting an error when trying to order using the query method in Nuxt 2.

{"type":"api_parsing_error","message":"']' expected but 'a' found on line:1 col:27 in query '[[at(document.type, \"book\")][at(my.book.subjects.subject, \"YIQbLBEAACUAbI2q\")]]'\n[[at(document.type, \"book\")][at(my.book.subjects.subject, \"YIQbLBEAACUAbI2q\")]]\n                          ^\n","pos":{"line":1,"column":27,"location":"ordering"}}

The code I'm using:

const books = await $prismic.api.query(
  [
    $prismic.predicates.at('document.type', 'book'),
    $prismic.predicates.at('my.book.subjects.subject', doc.id)
  ],
  {
    orderings: '[my.book.author_last_name asc]'
  }
)

That query works without the params object, just with predicates.
I also tried to use object-type orderings with field and direction keys, and have the same issue.
I'm using the same query call for other custom type and it's working, so something is wrong about this custom type? The only difference is right before I'm doing another call:

const doc = await $prismic.api.getByUID('subject', params.slug)

Thank you in advance.

Hello @cerrutti

Thanks for reaching out to us.

The query looks good to me. Can you send me the repo name in a private message so I can check on my end?

Thanks,
Priyanka

Ok, Priyanka helped me to fix this, "asc" ordering is the default so we don't need to use it.
Thank you!

1 Like

By default, the results will be ordered from lowest to highest, so you don't need to asc order.
I haven't added ASC in my query; a NULL value comes before any non-NULL value.

1 Like