nuxt/content queryCollection not returning results when using .order()
Hey all - I'm using Nuxt Content for the first time and loving it but I've hit an issue with trying to order results from the queryCollection(). Here's my .md file frontmatter:
and i'm trying to query it like so:
Which isn't returning any results. But, if I take away the
date
part:
it does successfully return the content. I do see the following error in the logs for npm run dev
:
but I'm not really sure what to do with it. I've scanned the nuxt/content docs and AFAIK I'm doing this correctly.
Any help is appreciated!2 Replies
Hi @Whitey. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in your question and the knowledge sources available, it appears you're encountering an issue with the
order()
method in Nuxt Content v3. Let's address this problem step by step.
The error message you're seeing suggests that the database cannot find a column named "date". This typically happens when the field you're trying to order by is not properly defined or recognized in your content schema.
Here are a few potential solutions and things to check:
1. Define your collection schema:
Make sure you have properly defined your collection schema in your content.config.ts
file. The date
field should be explicitly defined as a date type. Here's an example:
Define your collection schema to ensure all fields are properly recognized.
2. Check the date format:
Ensure that the date in your frontmatter is in a format that can be parsed as a valid date. The format you're using (2025-01-01
) should be correct, but double-check to make sure there are no typos.
3. Use createdAt
or updatedAt
:
If defining the schema doesn't solve the issue, you could try using the built-in createdAt
or updatedAt
fields for ordering, which are automatically generated by Nuxt Content:
4. Check for typos:
Ensure that the field name in your order()
method exactly matches the field name in your frontmatter and schema definition.
5. Verify collection name:
Make sure that 'posts' is the correct name of your collection as defined in your content.config.ts
file.
If none of these solutions work, you might be encountering a bug in Nuxt Content. In that case, it would be helpful to create a minimal reproduction of the issue and report it as a bug to the Nuxt Content GitHub repository.
Remember, Nuxt Content v3 uses a SQL-based storage system, which is different from previous versions. This change might affect how certain operations, like ordering, are handled.
If you continue to face issues, consider opening a GitHub Discussion or seeking help from the Nuxt community as suggested in the Getting Help guide.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@469974826178707456> Kapa.ai is still learning and improving, please let me know how I did by reacting below.