Skip to content

Fix/improve interface examples for Concepts > Documents #716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 18, 2025
1 change: 1 addition & 0 deletions CIRCLECI.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ or for multiple versions.
| string | `workflow` | `generate` |
| string | `arangodb-3_10` | [Upstream reference](#upstream-references) for 3.10 |
| string | `arangodb-3_11` | [Upstream reference](#upstream-references) for 3.11 |
| string | `arangodb-3_12` | [Upstream reference](#upstream-references) for 3.12 |
| string | `generators` | `examples` |
| boolean | `commit-generated` | `true` |
| string | `deploy-url` | `deploy-preview-{PR_NUMBER}` |
Expand Down
4 changes: 2 additions & 2 deletions site/content/3.11/concepts/data-structure/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ in the _JavaScript API_ for details.
curl -d '{"name":"coll"}' http://localhost:8529/_db/mydb/_api/collection
```

See the [`POST /_db/{database-name}/_api/collection`](../../develop/http-api/databases.md#create-a-database)
See the [`POST /_db/{database-name}/_api/collection`](../../develop/http-api/collections.md#create-a-collection)
endpoint in the _HTTP API_ for details.
{{< /tab >}}

Expand Down Expand Up @@ -399,7 +399,7 @@ in the _JavaScript API_ for details.
curl http://localhost:8529/_db/mydb/_api/collection
```

See the [`GET /_db/{database-name}/_api/collection`](../../develop/http-api/collections.md#get-the-collection-information)
See the [`GET /_db/{database-name}/_api/collection`](../../develop/http-api/collections.md#list-all-collections)
endpoint in the _HTTP API_ for details.
{{< /tab >}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ curl -XPUT -d '{"computedValues":[{"name":"title","expression":"RETURN \"TBA\"",
```

See the [`PUT /_db/{database-name}/_api/collection/{collection-name}/properties`](../../../develop/http-api/collections.md#change-the-properties-of-a-collection)
endpoint in the _HTTP API_for details.
endpoint in the _HTTP API_ for details.
{{< /tab >}}

{{< tab "JavaScript" >}}
Expand Down
148 changes: 118 additions & 30 deletions site/content/3.11/concepts/data-structure/documents/schema-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@ description: >-
How to enforce attributes and their data types for documents of individual
collections using JSON Schema
---
While ArangoDB is schema-less, it allows to enforce certain document structures
on the collection level. The desired structure can be described in the popular
While ArangoDB is schema-less, it allows you to enforce certain document structures
on the collection level. You can describe the desired structure in the popular
[JSON Schema](https://json-schema.org/) format (draft-4, without support for
remote schemas for security reasons). The level of validation and a custom error
message can be configured. The system attributes `_key`, `_id`, `_rev`, `_from`
message are configurable. The system attributes `_key`, `_id`, `_rev`, `_from`
and `_to` are ignored by the schema validation.

## Enable schema validation for a collection
## Schema validation interfaces

Schema validation can be managed via the JavaScript API, typically
using _arangosh_, as well as via the HTTP interface.
The following sections show examples of how you can configure the
schema validation for collections using the APIs of ArangoDB and
the official drivers, as well as the ArangoDB Shell and the built-in web interface.

To enable schema validation either pass the `schema` property on collection
creation or when updating the properties of an existing collection. It expects an
object with the following attributes: `rule`, `level` and `message`.
### Enable schema validation for a collection

- The `rule` attribute must contain the JSON Schema description.
- `level` controls when the validation is applied.
- `message` sets the message that is used when validation fails.
You can define a schema when creating a collection as well as update the
properties of a collection later on to add, modify, or remove a schema.

The `schema` property of a collection expects an object with the following
attributes:

- `rule`: Must contain the JSON Schema description.
- `level`: Controls when the validation is applied.
- `message`: Defines the message that is used when validation fails.

See [Schema validation properties](#schema-validation-properties) for details.

{{< tabs "interfaces" >}}

Expand Down Expand Up @@ -90,18 +97,6 @@ var coll = db._create("schemaCollection", { "schema": schema });
db.schemaCollection.properties({ "schema": schema });
~addIgnoreCollection(coll.name());
```
{{< comment >}}TODO: Move disabling/removing schema to separate headline?{{< /comment >}}

To remove an existing schema from a collection, a schema value of either `null`
or `{}` (empty object) can be stored:

```js
~var coll = db._collection("schemaCollection");
/* Remove the schema of an existing collection */
db.schemaCollection.properties({ "schema": null });
~removeIgnoreCollection(coll.name());
~db._drop(coll.name());
```

See [`collection.properties()`](../../../develop/javascript-api/@arangodb/collection-object.md#collectionpropertiesproperties)
in the _JavaScript API_ for details.
Expand All @@ -112,8 +107,8 @@ in the _JavaScript API_ for details.
curl -XPUT -d '{"schema":{"rule":{"type":"object","properties":{"nums":{"type":"array","items":{"type":"number","maximum":6}}},"additionalProperties":{"type":"string"},"required":["nums"]},"level":"moderate","message":"The document does not contain an array of numbers in attribute \"nums\", one of the numbers is greater than 6, or another top-level attribute is not a string."}}' http://localhost:8529/_db/mydb/_api/collection/coll/properties
```

See the [`GET /_db/{database-name}/_api/collection/{collection-name}/properties`](../../../develop/http-api/collections.md#get-the-properties-of-a-collection)
endpoint in the _HTTP API_for details.
See the [`PUT /_db/{database-name}/_api/collection/{collection-name}/properties`](../../../develop/http-api/collections.md#change-the-properties-of-a-collection)
endpoint in the _HTTP API_ for details.
{{< /tab >}}

{{< tab "JavaScript" >}}
Expand Down Expand Up @@ -216,7 +211,6 @@ in the _arangodb-java-driver_ documentation for details.
```py
coll = db.collection("coll")
props = coll.configure(
sync=True,
schema={
"rule": {
"type": "object",
Expand Down Expand Up @@ -244,7 +238,101 @@ in the _python-arango_ documentation for details.

{{< /tabs >}}

## JSON Schema Rule
### Remove schema validation for a collection

To remove an existing schema from a collection, set a `schema` value of either
`null` or `{}` (empty object).

{{< tabs "interfaces" >}}

{{< tab "Web interface" >}}
1. If necessary, [switch to the database](../databases.md#set-the-database-context)
that contains the desired collection.
2. Click **COLLECTIONS** in the main navigation.
3. Click the card of the desired collection.
4. Go to the **Schema** tab.
5. You can temporarily disable the document validation by setting the validation
`level` to `"none"`. To fully remove the schema from the collection, replace
the entire configuration with `null`.
6. Click the **Save** button.
{{< /tab >}}

{{< tab "arangosh" >}}
```js
---
name: arangosh_remove_collection_properties_schema
description: ''
---
~var coll = db._collection("schemaCollection");
db.schemaCollection.properties({ "schema": null });
~removeIgnoreCollection(coll.name());
~db._drop(coll.name());
```

See [`collection.properties()`](../../../develop/javascript-api/@arangodb/collection-object.md#collectionpropertiesproperties)
in the _JavaScript API_ for details.
{{< /tab >}}

{{< tab "cURL" >}}
```sh
curl -XPUT -d '{"schema":null}' http://localhost:8529/_db/mydb/_api/collection/coll/properties
```

See the [`PUT /_db/{database-name}/_api/collection/{collection-name}/properties`](../../../develop/http-api/collections.md#change-the-properties-of-a-collection)
endpoint in the _HTTP API_ for details.
{{< /tab >}}

{{< tab "JavaScript" >}}
```js
let coll = db.collection("coll");
const props = await coll.properties({ schema: null });
```

See [`DocumentCollection.properties()`](https://arangodb.github.io/arangojs/latest/interfaces/collections.DocumentCollection.html#properties.properties-2)
in the _arangojs_ documentation for details.
{{< /tab >}}

{{< tab "Go" >}}
```go
ctx := context.Background()
coll, err := db.GetCollection(ctx, "coll", nil)
err = coll.SetProperties(ctx, arangodb.SetCollectionPropertiesOptions{
Schema: &arangodb.CollectionSchemaOptions{} // empty object
})
```

See [`Collection.SetProperties()`](https://pkg.go.dev/github.com/arangodb/go-driver/v2/arangodb#Collection)
in the _go-driver_ v2 documentation for details.
{{< /tab >}}

{{< tab "Java" >}}
```java
CollectionPropertiesOptions options = new CollectionPropertiesOptions()
.schema(null);

ArangoCollection coll = db.collection("coll");
CollectionPropertiesEntity props = coll.changeProperties(options);
```

See [`ArangoCollection.changeProperties()`](https://www.javadoc.io/doc/com.arangodb/arangodb-java-driver/latest/com/arangodb/ArangoCollection.html#changeProperties%28com.arangodb.model.CollectionPropertiesOptions%29)
in the _arangodb-java-driver_ documentation for details.
{{< /tab >}}

{{< tab "Python" >}}
```py
coll = db.collection("coll")
props = coll.configure(schema={})
```

See [`Collection.configure()`](https://docs.python-arango.com/en/main/specs.html#arango.collection.Collection.configure)
in the _python-arango_ documentation for details.
{{< /tab >}}

{{< /tabs >}}

## Schema validation properties

### JSON Schema Rule

The `rule` must be a valid JSON Schema object as outlined in the
[specification](https://json-schema.org/specification.html).
Expand All @@ -265,7 +353,7 @@ attribute to integer values, use `"type": "number"` together with `"multipleOf":
Remote schemas are not supported for security reasons.
{{< /security >}}

## Levels
### Levels

The level controls when the validation is triggered:

Expand All @@ -279,7 +367,7 @@ The level controls when the validation is triggered:
- `strict`: All new and modified document must strictly pass validation.
No exceptions are made (default).

## Error message
### Error message

If the schema validation for a document fails, then a generic error is raised.
You may customize the error message via the `message` attribute to provide a
Expand Down
2 changes: 1 addition & 1 deletion site/content/3.12/about-arangodb/use-cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ aliases:
---
## ArangoDB as a Graph Database

ArangoDB as a **graph database** is a great fit for use cases like fraud detection,
ArangoDB as a graph database is a great fit for use cases like fraud detection,
knowledge graphs, recommendation engines, identity and access management,
network and IT operations, social media management, traffic management, and many
more.
Expand Down
4 changes: 2 additions & 2 deletions site/content/3.12/concepts/data-structure/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ in the _JavaScript API_ for details.
curl -d '{"name":"coll"}' http://localhost:8529/_db/mydb/_api/collection
```

See the [`POST /_db/{database-name}/_api/collection`](../../develop/http-api/databases.md#create-a-database)
See the [`POST /_db/{database-name}/_api/collection`](../../develop/http-api/collections.md#create-a-collection)
endpoint in the _HTTP API_ for details.
{{< /tab >}}

Expand Down Expand Up @@ -397,7 +397,7 @@ in the _JavaScript API_ for details.
curl http://localhost:8529/_db/mydb/_api/collection
```

See the [`GET /_db/{database-name}/_api/collection`](../../develop/http-api/collections.md#get-the-collection-information)
See the [`GET /_db/{database-name}/_api/collection`](../../develop/http-api/collections.md#list-all-collections)
endpoint in the _HTTP API_ for details.
{{< /tab >}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ curl -XPUT -d '{"computedValues":[{"name":"title","expression":"RETURN \"TBA\"",
```

See the [`PUT /_db/{database-name}/_api/collection/{collection-name}/properties`](../../../develop/http-api/collections.md#change-the-properties-of-a-collection)
endpoint in the _HTTP API_for details.
endpoint in the _HTTP API_ for details.
{{< /tab >}}

{{< tab "JavaScript" >}}
Expand Down
Loading