How to list all available content
Problem
Not able to get all the content in a collection or from multiple collections at once.
Possible solution
await queryCollection('blog') // Returns all the content from the blog collection
await queryCollection('') // Returns all the content spread over the different collections
Alternatives
Tried grabbing it from ssrContext but without succes
Additional context
With V2 it was possible to do something like
await queryContent().find()
My question woul'd be similar. How do i list all documents to create a full navigation?
@biroplane @Rednas83 You can do a few things like that:
const { data: navigation } = await useAsyncData('navigation', () => {
return Promise.all([
queryCollectionNavigation('docs'),
queryCollectionNavigation('blog')
])
}, {
transform: data => data.flat()
})
const { data: files } = useLazyAsyncData('search', () => {
return Promise.all([
queryCollectionSearchSections('docs'),
queryCollectionSearchSections('blog')
])
}, {
server: false,
transform: data => data.flat()
})
Just tried queryCollectionNavigation but that only seems to work with the page collection type on the type level. Should it not also work for the data collection type?
Also tried queryCollectionSearchSections which seems to work on the type level but returns a server error on the runtime level when called from app.js
How can this server error be avoided? Does it only work on plugin/nitro level?
When called directly from app.js it still errors but with more clear errors. Server
ℹ Error: no such column: "path" - should this be a string literal in single-quotes?
⁃ at Database.prepare (D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/methods/wrappers.js:5:21)
1 ┃ 'use strict';
2 ┃ const { cppdb } = require('../util');
3 ┃
4 ┃ exports.prepare = function prepare(sql) {
❯ 5 ┃ return this[cppdb].prepare(sql, this, false);
6 ┃ };
7 ┃
8 ┃ exports.exec = function exec(sql) {
9 ┃ this[cppdb].exec(sql);
10 ┃ return this;
11 ┃ };
⁃ at Object.prepare (D:/Projecten/organizer/node_modules/.pnpm/[email protected][email protected]/node_modules/db0/dist/connectors/better-sqlite3.mjs:28:52)
⁃ at Object.all (D:/Projecten/organizer/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nuxt/content/dist/runtime/internal/database.server.js:20:17)
⁃ at Object.handler (D:/Projecten/organizer/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nuxt/content/dist/runtime/api/query.post.js:13:36)
⁃ at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
⁃ (async file:///D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:2009:19)
⁃ at async Object.callAsync (D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/unctx/dist/index.mjs:72:16)
⁃ at async toNodeHandle (D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:2301:7)
⁃ at async b (D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/node-mock-http/dist/index.mjs:1:6808)
⁃ at async O (D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/node-mock-http/dist/index.mjs:1:7091)
[CAUSE]
SqliteError {
message: 'no such column: "path" - should this be a string literal in
single-quotes?',
stack: 'no such column: "path" - should this be a string literal in single-quotes?\n' +
'at Database.prepare (D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/methods/wrappers.js:5:21)\n' +
'at Object.prepare (D:/Projecten/organizer/node_modules/.pnpm/[email protected][email protected]/node_modules/db0/dist/connectors/better-sqlite3.mjs:28:52)\n' +
'at Object.all (D:/Projecten/organizer/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nuxt/content/dist/runtime/internal/database.server.js:20:17)\n' +
'at Object.handler (D:/Projecten/organizer/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nuxt/content/dist/runtime/api/query.post.js:13:36)\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n' +
'at async file:///D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:2009:19)\n' +
'at async Object.callAsync (D:/Projecten/organizer/node_modules/.pnpm/unctx@2'... 411 more characters,
code: 'SQLITE_ERROR',
}
app-sections RefImpl {
dep:
Dep {
computed: undefined,
version: 0,
activeLink: undefined,
subs: undefined,
map: undefined,
key: undefined,
sc: 0,
subsHead: undefined },
__v_isRef: true,
__v_isShallow: true,
_rawValue: undefined,
_value: undefined }
client
browser.mjs:48 ssr:error [request error] [unhandled] [POST] http://localhost/__nuxt_content/features/query?v=v3.3.0--hHKrm71H8C5oYH5p7ELob3ikrfSXLiMHgQPSYJY9K5g&t=1743763192527
[31mℹ Error: no such column: "path" - should this be a string literal in single-quotes?[39m
⁃ at Database.prepare [33m(D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/methods/wrappers.js:5:21)[39m
[2m 1[22m [2m┃[22m [32m'use strict'[0m;
[2m 2[22m [2m┃[22m [31mconst[0m { cppdb } [34m=[0m [35mrequire[0m([32m'../util'[0m);
[2m 3[22m [2m┃[22m
[2m 4[22m [2m┃[22m exports[34m.[0m[35mprepare[0m [34m=[0m [31mfunction[0m [35mprepare[0m(sql) {
[41m❯ 5 ┃ return this[cppdb].prepare(sql, this, false);[49m
[2m 6[22m [2m┃[22m };
[2m 7[22m [2m┃[22m
[2m 8[22m [2m┃[22m exports[34m.[0m[35mexec[0m [34m=[0m [31mfunction[0m [35mexec[0m(sql) {
[2m 9[22m [2m┃[22m [31mthis[0m[cppdb][34m.[0m[35mexec[0m(sql);
[2m10[22m [2m┃[22m [31mreturn[0m [31mthis[0m;
[2m11[22m [2m┃[22m };
⁃ at Object.prepare [33m(D:/Projecten/organizer/node_modules/.pnpm/[email protected][email protected]/node_modules/db0/dist/connectors/better-sqlite3.mjs:28:52)[39m
⁃ at Object.all [33m(D:/Projecten/organizer/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nuxt/content/dist/runtime/internal/database.server.js:20:17)[39m
⁃ at Object.handler [33m(D:/Projecten/organizer/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nuxt/content/dist/runtime/api/query.post.js:13:36)[39m
[2m ⁃ at [3mprocess.processTicksAndRejections[23m ([3mnode:internal/process/task_queues:105:5[23m)[22m
⁃ [33m(async file:///D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:2009:19)[39m
⁃ at async Object.callAsync [33m(D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/unctx/dist/index.mjs:72:16)[39m
⁃ at async toNodeHandle [33m(D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:2301:7)[39m
⁃ at async b [33m(D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/node-mock-http/dist/index.mjs:1:6808)[39m
⁃ at async O [33m(D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/node-mock-http/dist/index.mjs:1:7091)[39m
[31m[CAUSE][39m
[36mSqliteError[39m [33m{[39m
[34mmessage[39m: [32m'no such column: "path" - should this be a string literal in
single-quotes?'[39m,
[34mstack[39m: [32m'no such column: "path" - should this be a string literal in single-quotes?\n' +
'at Database.prepare (D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/methods/wrappers.js:5:21)\n' +
'at Object.prepare (D:/Projecten/organizer/node_modules/.pnpm/[email protected][email protected]/node_modules/db0/dist/connectors/better-sqlite3.mjs:28:52)\n' +
'at Object.all (D:/Projecten/organizer/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nuxt/content/dist/runtime/internal/database.server.js:20:17)\n' +
'at Object.handler (D:/Projecten/organizer/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nuxt/content/dist/runtime/api/query.post.js:13:36)\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n' +
'at async file:///D:/Projecten/organizer/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs:2009:19)\n' +
'at async Object.callAsync (D:/Projecten/organizer/node_modules/.pnpm/unctx@2'... 411 more characters[39m,
[34mcode[39m: [32m'SQLITE_ERROR'[39m,
[33m}[39m
at <anonymous> (D:\Projecten\organizer\node_modules\.pnpm\[email protected]_@[email protected]_@[email protected][email protected][email protected]_better-_7rgjhnu7fmqusdoyo5k4ssjwuu\node_modules\nuxt\dist\core\runtime\nitro\plugins\dev-server-logs.js)
at Object.log (D:\Projecten\organizer\node_modules\.pnpm\[email protected]_@[email protected]_@[email protected][email protected][email protected]_better-_7rgjhnu7fmqusdoyo5k4ssjwuu\node_modules\nuxt\dist\core\runtime\nitro\plugins\dev-server-logs.js)
at defaultHandler (D:\Projecten\organizer\node_modules\.pnpm\[email protected][email protected]\node_modules\nitropack\dist\runtime\internal\error\dev.mjs)
at async defaultNitroErrorHandler (D:\Projecten\organizer\node_modules\.pnpm\[email protected][email protected]\node_modules\nitropack\dist\runtime\internal\error\dev.mjs)
at async errorHandler (D:\Projecten\organizer\node_modules\.pnpm\[email protected][email protected]\node_modules\nitropack\dist\runtime\internal\error\dev.mjs)
log @ browser.mjs:48
_log @ core.mjs:483
resolveLog @ core.mjs:451
_logFn @ core.mjs:479
(anonymous) @ core.mjs:408
(anonymous) @ dev-server-logs.js:28
(anonymous) @ index.mjs:48
(anonymous) @ index.mjs:48
dev:ssr-logs
serialTaskCaller @ index.mjs:46
callHookWith @ index.mjs:198
callHook @ index.mjs:187
(anonymous) @ dev-server-logs.js:36
executeAsync @ index.mjs:110
(anonymous) @ dev-server-logs.js:36
(anonymous) @ nuxt.js:139
fn @ nuxt.js:216
runWithContext @ runtime-core.esm-bundler.js:3996
callWithNuxt @ nuxt.js:222
(anonymous) @ nuxt.js:38
run @ reactivity.esm-bundler.js:77
runWithContext @ nuxt.js:38
applyPlugin @ nuxt.js:139
executePlugin @ nuxt.js:158
applyPlugins @ nuxt.js:189
await in applyPlugins
initApp @ entry.js:57
(anonymous) @ entry.js:72
browser.mjs:48 ssr app-sections RefImpl {dep: Dep, __v_isRef: true, __v_isShallow: true, _rawValue: undefined, _value: undefined}
at <anonymous> (D:\Projecten\organizer\node_modules\.pnpm\[email protected]_@[email protected]_@[email protected][email protected][email protected]_better-_7rgjhnu7fmqusdoyo5k4ssjwuu\node_modules\nuxt\dist\core\runtime\nitro\plugins\dev-server-logs.js)
at Object.log (D:\Projecten\organizer\node_modules\.pnpm\[email protected]_@[email protected]_@[email protected][email protected][email protected]_better-_7rgjhnu7fmqusdoyo5k4ssjwuu\node_modules\nuxt\dist\core\runtime\nitro\plugins\dev-server-logs.js)
at setup (D:\Projecten\organizer\app.vue)
browser.mjs:48 ssr:warn Content does not exist for 'openx(features)'
at <anonymous> (D:\Projecten\organizer\node_modules\.pnpm\[email protected]_@[email protected]_@[email protected][email protected][email protected]_better-_7rgjhnu7fmqusdoyo5k4ssjwuu\node_modules\nuxt\dist\core\runtime\nitro\plugins\dev-server-logs.js)
at Object.log (D:\Projecten\organizer\node_modules\.pnpm\[email protected]_@[email protected]_@[email protected][email protected][email protected]_better-_7rgjhnu7fmqusdoyo5k4ssjwuu\node_modules\nuxt\dist\core\runtime\nitro\plugins\dev-server-logs.js)
at openx (D:\Projecten\organizer\composables\useOpenx.ts)
at async openy (D:\Projecten\organizer\composables\useOpeny.ts)
at async setup (D:\Projecten\organizer\pages\features.vue)
log @ browser.mjs:48
_log @ core.mjs:483
resolveLog @ core.mjs:451
_logFn @ core.mjs:479
(anonymous) @ core.mjs:408
(anonymous) @ dev-server-logs.js:28
(anonymous) @ index.mjs:48
(anonymous) @ index.mjs:48
dev:ssr-logs
serialTaskCaller @ index.mjs:46
callHookWith @ index.mjs:198
callHook @ index.mjs:187
(anonymous) @ dev-server-logs.js:36
executeAsync @ index.mjs:110
(anonymous) @ dev-server-logs.js:36
(anonymous) @ nuxt.js:139
fn @ nuxt.js:216
runWithContext @ runtime-core.esm-bundler.js:3996
callWithNuxt @ nuxt.js:222
(anonymous) @ nuxt.js:38
run @ reactivity.esm-bundler.js:77
runWithContext @ nuxt.js:38
applyPlugin @ nuxt.js:139
executePlugin @ nuxt.js:158
applyPlugins @ nuxt.js:189
await in applyPlugins
initApp @ entry.js:57
(anonymous) @ entry.js:72
runtime-core.esm-bundler.js:7013 <Suspense> is an experimental feature and its API will likely change.
app.vue:5 app-sections RefImpl {dep: Dep, __v_isRef: true, __v_isShallow: true, _rawValue: undefined, _value: undefined}dep: Dep {computed: undefined, version: 0, activeLink: undefined, subs: undefined, map: undefined, …}__v_isRef: true__v_isShallow: true_rawValue: undefined_value: undefinedvalue: (...)[[Prototype]]: Object
useOpenx.ts:48 Content does not exist for 'openx(features)'
openx @ useOpenx.ts:48
await in openx
openy @ useOpeny.ts:2
(anonymous) @ features.vue:11
withAsyncContext @ runtime-core.esm-bundler.js:3377
setup @ features.vue:11
callWithErrorHandling @ runtime-core.esm-bundler.js:199
setupStatefulComponent @ runtime-core.esm-bundler.js:7907
setupComponent @ runtime-core.esm-bundler.js:7868
mountComponent @ runtime-core.esm-bundler.js:5216
hydrateNode @ runtime-core.esm-bundler.js:1800
hydrateSubTree @ runtime-core.esm-bundler.js:5292
componentUpdateFn @ runtime-core.esm-bundler.js:5310
run @ reactivity.esm-bundler.js:225
setupRenderEffect @ runtime-core.esm-bundler.js:5454
mountComponent @ runtime-core.esm-bundler.js:5229
hydrateNode @ runtime-core.esm-bundler.js:1800
hydrateSuspense @ runtime-core.esm-bundler.js:7264
hydrateNode @ runtime-core.esm-bundler.js:1836
hydrateSubTree @ runtime-core.esm-bundler.js:5292
componentUpdateFn @ runtime-core.esm-bundler.js:5310
run @ reactivity.esm-bundler.js:225
setupRenderEffect @ runtime-core.esm-bundler.js:5454
mountComponent @ runtime-core.esm-bundler.js:5229
hydrateNode @ runtime-core.esm-bundler.js:1800
hydrateSubTree @ runtime-core.esm-bundler.js:5292
componentUpdateFn @ runtime-core.esm-bundler.js:5310
run @ reactivity.esm-bundler.js:225
setupRenderEffect @ runtime-core.esm-bundler.js:5454
mountComponent @ runtime-core.esm-bundler.js:5229
hydrateNode @ runtime-core.esm-bundler.js:1800
hydrateChildren @ runtime-core.esm-bundler.js:1991
hydrateElement @ runtime-core.esm-bundler.js:1880
hydrateNode @ runtime-core.esm-bundler.js:1781
hydrateChildren @ runtime-core.esm-bundler.js:1991
hydrateFragment @ runtime-core.esm-bundler.js:2034
hydrateNode @ runtime-core.esm-bundler.js:1766
hydrateChildren @ runtime-core.esm-bundler.js:1991
hydrateFragment @ runtime-core.esm-bundler.js:2034
hydrateNode @ runtime-core.esm-bundler.js:1766
hydrateChildren @ runtime-core.esm-bundler.js:1991
hydrateFragment @ runtime-core.esm-bundler.js:2034
hydrateNode @ runtime-core.esm-bundler.js:1766
hydrateSubTree @ runtime-core.esm-bundler.js:5292
componentUpdateFn @ runtime-core.esm-bundler.js:5310
run @ reactivity.esm-bundler.js:225
setupRenderEffect @ runtime-core.esm-bundler.js:5454
mountComponent @ runtime-core.esm-bundler.js:5229
hydrateNode @ runtime-core.esm-bundler.js:1800
hydrateSubTree @ runtime-core.esm-bundler.js:5292
componentUpdateFn @ runtime-core.esm-bundler.js:5310
run @ reactivity.esm-bundler.js:225
setupRenderEffect @ runtime-core.esm-bundler.js:5454
mountComponent @ runtime-core.esm-bundler.js:5229
hydrateNode @ runtime-core.esm-bundler.js:1800
hydrateChildren @ runtime-core.esm-bundler.js:1991
hydrateFragment @ runtime-core.esm-bundler.js:2034
hydrateNode @ runtime-core.esm-bundler.js:1766
hydrateSubTree @ runtime-core.esm-bundler.js:5292
componentUpdateFn @ runtime-core.esm-bundler.js:5310
run @ reactivity.esm-bundler.js:225
setupRenderEffect @ runtime-core.esm-bundler.js:5454
mountComponent @ runtime-core.esm-bundler.js:5229
hydrateNode @ runtime-core.esm-bundler.js:1800
hydrateChildren @ runtime-core.esm-bundler.js:1991
hydrateFragment @ runtime-core.esm-bundler.js:2034
hydrateNode @ runtime-core.esm-bundler.js:1766
hydrateSubTree @ runtime-core.esm-bundler.js:5292
componentUpdateFn @ runtime-core.esm-bundler.js:5310
run @ reactivity.esm-bundler.js:225
setupRenderEffect @ runtime-core.esm-bundler.js:5454
mountComponent @ runtime-core.esm-bundler.js:5229
hydrateNode @ runtime-core.esm-bundler.js:1800
hydrateSubTree @ runtime-core.esm-bundler.js:5292
componentUpdateFn @ runtime-core.esm-bundler.js:5310
run @ reactivity.esm-bundler.js:225
setupRenderEffect @ runtime-core.esm-bundler.js:5454
mountComponent @ runtime-core.esm-bundler.js:5229
hydrateNode @ runtime-core.esm-bundler.js:1800
hydrateSubTree @ runtime-core.esm-bundler.js:5292
componentUpdateFn @ runtime-core.esm-bundler.js:5310
run @ reactivity.esm-bundler.js:225
setupRenderEffect @ runtime-core.esm-bundler.js:5454
(anonymous) @ runtime-core.esm-bundler.js:7201
Promise.then
registerDep @ runtime-core.esm-bundler.js:7187
mountComponent @ runtime-core.esm-bundler.js:5223
hydrateNode @ runtime-core.esm-bundler.js:1800
hydrateSuspense @ runtime-core.esm-bundler.js:7264
hydrateNode @ runtime-core.esm-bundler.js:1836
hydrateSubTree @ runtime-core.esm-bundler.js:5292
componentUpdateFn @ runtime-core.esm-bundler.js:5310
run @ reactivity.esm-bundler.js:225
setupRenderEffect @ runtime-core.esm-bundler.js:5454
mountComponent @ runtime-core.esm-bundler.js:5229
hydrateNode @ runtime-core.esm-bundler.js:1800
hydrate @ runtime-core.esm-bundler.js:1674
mount @ runtime-core.esm-bundler.js:3939
app.mount @ runtime-dom.esm-bundler.js:1786
initApp @ entry.js:64
await in initApp
(anonymous) @ entry.js:72
websocket.js:4 [Content] WS connect to ws://localhost:4000/ws
websocket.js:4 [Content] WS connected!
devtools.client.js:49 ✨ Nuxt DevTools Press Shift + Alt + D to open DevTools
@Rednas83 By design, navigation works only for page collections. Generating navigation requires some files to be defined in the schema, which are already defined in the page collection.
I guess that makes sense, but is there also a way to list all the data collections defined inside the schema?
If not, can you please consider adding support for it?
Perhaps something like
await queryCollectionData('data') // returns all data from **content/data/*.md**
await queryCollectionData() // returns all data from the root **content/*.md**
Any thoughts?
@biroplane @Rednas83 You can do a few things like that:
const { data: navigation } = await useAsyncData('navigation', () => { return Promise.all([ queryCollectionNavigation('docs'), queryCollectionNavigation('blog') ]) }, { transform: data => data.flat() })
const { data: files } = useLazyAsyncData('search', () => { return Promise.all([ queryCollectionSearchSections('docs'), queryCollectionSearchSections('blog') ]) }, { server: false, transform: data => data.flat() })
This works on the client. But how to do this on the server level? Tried https://content.nuxt.com/docs/utils/query-collection-navigation#server-usage but I am not sure what the event argument is