N
Nuxt4mo ago
envizar

nuxt content order by deep value

like
const route = useRoute()
const { data } = await useAsyncData(route.path, () => {
return queryCollection('docs')
.order('props.date', 'DESC')
.all()
})
const route = useRoute()
const { data } = await useAsyncData(route.path, () => {
return queryCollection('docs')
.order('props.date', 'DESC')
.all()
})
but it won't work cuz props.date isn't keyof Collection
4 Replies
kapa.ai
kapa.ai4mo ago
Hi @envizar. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I'm sorry, but the knowledge sources do not provide any information indicating that Nuxt Content's queryCollection supports ordering by deep (nested) values such as props.date using the order method. The documented usage and API examples only show ordering by top-level fields that are direct keys of the collection schema, e.g., order('date', 'DESC') where date is a direct property of the collection item, not a nested property like props.date Query Utils: order. Attempting to use a nested path like 'props.date' will not work because the order method expects a key of the collection, not a deep property. The documentation does not mention any workaround or support for ordering by nested fields. If you need to order by a nested value, you may need to flatten your schema or add a top-level field for sorting purposes. If you require more advanced sorting, you might need to handle it manually after fetching the data. If you need further clarification, you may want to check for updates in the official documentation or open an issue with the Nuxt Content team. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@515829500945367078> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
dwol
dwol4mo ago
What does your collection definition look like?
envizar
envizarOP4mo ago
something like
const schema = z.object({
props: z.object({
date: z.date().optional()
}).optional()
})
const schema = z.object({
props: z.object({
date: z.date().optional()
}).optional()
})
then I use that schema

Did you find this page helpful?