feat: adds meta descriptions to docs

This commit is contained in:
Jessica Boezwinkle
2021-02-03 16:55:22 -05:00
parent 3bd0de0a0b
commit da61feb73b
52 changed files with 1350 additions and 1129 deletions

View File

@@ -2,14 +2,22 @@
title: Querying your Documents
label: Overview
order: 10
desc: Payload is a headless CMS and application framework.
desc: Payload provides a querying language through all APIs, allowing you to filter or search through documents within a Collection.
keywords: query, documents, overview, documentation, Content Management System, cms, headless, javascript, node, react, express
---
Payload provides an extremely granular querying language through all APIs. Each API takes the same syntax and fully supports all options.
<Banner>
<strong>Here, "querying" relates to filtering or searching through documents within a Collection.</strong> You can build queries to pass to Find operations as well as to <a href="/docs/access-control/overview">restrict which documents certain users can access</a> via access control functions.
<strong>
Here, "querying" relates to filtering or searching through documents within
a Collection.
</strong>{" "}
You can build queries to pass to Find operations as well as to{" "}
<a href="/docs/access-control/overview">
restrict which documents certain users can access
</a>{" "}
via access control functions.
</Banner>
### Simple queries
@@ -18,55 +26,54 @@ For example, say you have a collection as follows:
```js
const Post = {
slug: 'posts',
slug: "posts",
fields: [
{
name: 'color',
type: 'select',
options: [
'mint',
'dark-gray',
'white',
],
name: "color",
type: "select",
options: ["mint", "dark-gray", "white"],
},
{
name: 'featured',
type: 'checkbox',
}
]
}
name: "featured",
type: "checkbox",
},
],
};
```
You may eventually have a lot of documents within this Collection. If you wanted to find only documents with `color` equal to `mint`, you could write a query as follows:
```js
const query = {
color: { // property name to filter on
equals: 'mint', // operator to use and value to compare against
color: {
// property name to filter on
equals: "mint", // operator to use and value to compare against
},
}
};
```
The above example demonstrates a simple query but you can get much more complex.
### Operators
| Operator | Description |
| -------------------- | ------------ |
| `equals` | The value must be exactly equal. |
| `not_equals` | The query will return all documents where the value is not equal. |
| `greater_than` | For numeric or date-based fields. |
| `greater_than_equal` | For numeric or date-based fields. |
| `less_than` | For numeric or date-based fields. |
| `less_than_equal` | For numeric or date-based fields. |
| `like` | The value must partially match. |
| `in` | The value must be found within the provided comma-delimited list of values. |
| `not_in` | The value must NOT be within the provided comma-delimited list of values. |
| Operator | Description |
| -------------------- | ----------------------------------------------------------------------------------------- |
| `equals` | The value must be exactly equal. |
| `not_equals` | The query will return all documents where the value is not equal. |
| `greater_than` | For numeric or date-based fields. |
| `greater_than_equal` | For numeric or date-based fields. |
| `less_than` | For numeric or date-based fields. |
| `less_than_equal` | For numeric or date-based fields. |
| `like` | The value must partially match. |
| `in` | The value must be found within the provided comma-delimited list of values. |
| `not_in` | The value must NOT be within the provided comma-delimited list of values. |
| `exists` | Only return documents where the value either exists (`true`) or does not exist (`false`). |
<Banner type="success">
<strong>Tip</strong>:<br/>
If you know your users will be querying on certain fields a lot, you can add <strong>index: true</strong> to a field's config which will speed up searches using that field immensely.
<strong>Tip</strong>:<br />
If you know your users will be querying on certain fields a lot, you can add <strong>
index: true
</strong> to a field's config which will speed up searches using that field immensely.
</Banner>
### And / Or Logic
@@ -75,28 +82,30 @@ In addition to defining simple queries, you can join multiple queries together u
```js
const query = {
or: [ // array of OR conditions
or: [
// array of OR conditions
{
color: {
equals: 'mint',
equals: "mint",
},
},
{
and: [ // nested array of AND conditions
and: [
// nested array of AND conditions
{
color: {
equals: 'white',
}
equals: "white",
},
},
{
featured: {
equals: false,
}
}
]
}
]
}
},
},
],
},
],
};
```
Written in plain English, if the above query were passed to a `find` operation, it would translate to finding posts where either the `color` is `mint` OR the `color` is `white` AND `featured` is set to false.
@@ -131,24 +140,29 @@ This one isn't too bad, but more complex queries get unavoidably more difficult
**For example, using fetch:**
```js
import qs from 'qs';
import qs from "qs";
const query = {
color: {
equals: 'mint',
equals: "mint",
},
// This query could be much more complex
// and QS would handle it beautifully
}
};
const getPosts = async () => {
const stringifiedQuery = qs.stringify({
where: query // ensure that `qs` adds the `where` property, too!
}, { addQueryPrefix: true });
const stringifiedQuery = qs.stringify(
{
where: query, // ensure that `qs` adds the `where` property, too!
},
{ addQueryPrefix: true }
);
const response = await fetch(`http://localhost:3000/api/posts${stringifiedQuery}`);
const response = await fetch(
`http://localhost:3000/api/posts${stringifiedQuery}`
);
// Continue to handle the response below...
}
};
```
### Local API Queries
@@ -158,19 +172,18 @@ The Local API's `find` operation accepts an object exactly how you write it. For
```js
const getPosts = async () => {
const posts = await payload.find({
collection: 'posts',
collection: "posts",
where: {
color: {
equals: 'mint',
equals: "mint",
},
},
});
return posts;
}
};
```
## Sort
Payload `find` queries support a `sort` parameter through all APIs. Pass the `name` of a top-level field to sort by that field in ascending order. Prefix the name of the field with a minus symbol ("-") to sort in descending order.
@@ -179,6 +192,7 @@ Payload `find` queries support a `sort` parameter through all APIs. Pass the `na
**`https://localhost:3000/api/posts?sort=-createdAt`**
**GraphQL example:**
```
query {
Posts(sort: "-createdAt") {
@@ -194,10 +208,10 @@ query {
```js
const getPosts = async () => {
const posts = await payload.find({
collection: 'posts',
sort: '-createdAt',
collection: "posts",
sort: "-createdAt",
});
return posts;
}
};
```

View File

@@ -2,7 +2,7 @@
title: Pagination
label: Pagination
order: 20
desc: Payload is a headless CMS and application framework.
desc: Payload queries are equipped with automatic pagination so you create paginated lists of documents within your app.
keywords: query, documents, pagination, documentation, Content Management System, cms, headless, javascript, node, react, express
---
@@ -10,20 +10,21 @@ All collection `find` queries are paginated automatically. Responses are returne
**`Find` response properties:**
| Property | Description |
| ------------- | ---------------------------------------------------------- |
| docs | Array of documents in the collection |
| totalDocs | Total available documents within the collection |
| limit | Limit query parameter - defaults to `10` |
| totalPages | Total pages available, based upon the `limit` queried for |
| page | Current page number |
| pagingCounter | `number` of the first doc on the current page |
| hasPrevPage | `true/false` if previous page exists |
| hasNextPage | `true/false` if next page exists |
| prevPage | `number` of previous page, `null` if it doesn't exist |
| nextPage | `number` of next page, `null` if it doesn't exist |
| Property | Description |
| ------------- | --------------------------------------------------------- |
| docs | Array of documents in the collection |
| totalDocs | Total available documents within the collection |
| limit | Limit query parameter - defaults to `10` |
| totalPages | Total pages available, based upon the `limit` queried for |
| page | Current page number |
| pagingCounter | `number` of the first doc on the current page |
| hasPrevPage | `true/false` if previous page exists |
| hasNextPage | `true/false` if next page exists |
| prevPage | `number` of previous page, `null` if it doesn't exist |
| nextPage | `number` of next page, `null` if it doesn't exist |
**Example response:**
```js
{
// Document Array // highlight-line
@@ -54,7 +55,7 @@ All collection `find` queries are paginated automatically. Responses are returne
All Payload APIs support the pagination controls below. With them, you can create paginated lists of documents within your application:
| Control | Description |
| --------- | ----------------------------------------------------------------------------------------- |
| `limit` | Limits the number of documents returned |
| `page` | Get a specific page number |
| Control | Description |
| ------- | --------------------------------------- |
| `limit` | Limits the number of documents returned |
| `page` | Get a specific page number |