Querying a Single Document

Querying a single document

Get a single document, providing it's relativePath as the argument.

  • relativePath is the portion of the path relative to the collection's path.

In this example, the post collection has a path of content/posts and your document can be found at content/posts/voteForPedro.md giving relativePath: "voteForPedro.md". If your item was at content/posts/nested-folder/voteForPedro.md you'd specify: relativePath: "nested-folder/voteForPedro.md".

Our collections for the above schema are named "post" and "author", so we can query for each using the post & author

Examples

Query on author only.

Query on post and author.

Query post on author.

Common fields

In a collection, there are a few fields that are common to all documents. These are: id, _values and _sys. The id field is a unique identifier for the document. The _values field is used internally in edit mode and is not for external use. The _sys field contains meta information about the document.

The _sys field is an object with the following fields:

filename
String!

The name of the file without the extension


basename
String!

The name of the file with the extension


path
String!

The full path of the file relative to the project root


breadcrumbs
[String!]!

An array of the parent folders of the file


relativeโ€‹Path
String!

The path of the file relative to the collection path


extension
String!

The extension of the file


template
String!

The template of the document (or the name of the collection if not using templates)


collection
Collection!

Information about the collection

Example with a nested folder

Example without a nested folder

Last Edited: August 15, 2024