Skip to content

v2 -> v3: queryCollection().sort() unexpected order #3062

Open
@chrisjansky

Description

@chrisjansky

Environment

  • Operating System: Darwin
  • Node Version: v23.6.1
  • Nuxt Version: 3.15.4
  • CLI Version: 3.21.1
  • Nitro Version: 2.10.4
  • Package Manager: pnpm@9.14.4
  • Builder: -
  • Runtime Modules: @nuxt/content@3.0.1

Version

v3

Reproduction

I would like to post a reproduction, but I am unable to setup @nuxt/content3 in StackBlitz: getting this error:

Restarting Nuxt due to error: `Error: Could not locate the bindings file. Tried:                                                                                     nuxi:nuxi 18:08:53
 → /home/project/node_modules/better-sqlite3/build/better_sqlite3.node
...

Is there a workaround or a starter template that I am not seeing?

Description

Coming from v2, I am unable to reproduce the same JSON sorting and filtering behaviour.

Before (v2):

queryContent
      .where({ _type: "json", status: { $not: "hidden" } })
      .sort({ status: 1, priority: 1 })
      .find()

Expected result:

- one
  - status: something
  - priority: 1
- two
  - status: something
  - priority: 2
- three
  - status: null
  - priority: 2

Discarded:

- four
  - status: hidden <= // discarded because status = hidden
  - priority: null

After (v3):

queryCollection
      .andWhere((query) => query.where("extension", "=", "json").where("status", "<>", "hidden"))
      .order("status", "ASC")
      .order("priority", "ASC")

Actual result:

- bar
  - status: something
  - priority: 1
- baz
  - status: something
  - priority: 2

Namely item three discarded because status = null, but only status = hidden should be discarded.

Also in v2 it was possible to have a complex sorting query using multiple criteria, i.e. sort items with status first and then sort those based on priority.

I am missing something? 😅

Thanks!

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedv3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions