---
title: "Sample & Validate Documents"
method: POST
path: "/groups/{groupId}/apps/{appId}/services/{datasourceId}/commands/validate_documents"
tags: ["schemas"]
---

# Sample & Validate Documents

`POST /groups/{groupId}/apps/{appId}/services/{datasourceId}/commands/validate_documents`

Query a subset of documents in a collection and validate each match against a schema.

## Request body

- object
  - `database_name` string, required — The name of the database that contains the collection to validate.
  - `collection_name` string, required — The name of the collection to validate.
  - `from_schema` object, required — The EJSON schema to validate sampled documents against.
  - `query` object — A [MongoDB query](https://www.mongodb.com/docs/manual/tutorial/query-documents/) that matches documents in the collection. The result of running this query is the sample population. Use this to narrow the sample to a subset of documents in the collection.
  - `limit` number — The maximum number of documents to sample.
  - `sort` object — A [MongoDB sort](https://www.mongodb.com/docs/manual/reference/method/cursor.sort/) for the collection. Use this to determine which end of a range query to start sampling from.

## Response `200`

OK

- object
  - `errors` object[]
    - `error_code` union — An EJSON schema validation error.
      - 'false'
      - 'required' — A required field is missing.
      - 'invalid_type' — A field has an invalid value type.
      - 'unique' — A field contains a unique array with non-unique values.
      - 'missing_dependency'
      - 'internal'
      - 'const' — A field has an invalid constant value.
      - 'enum' — A field has an invalid enum value.
      - 'number_any_of' — A field does not match any schema in [anyOf](https://json-schema.org/understanding-json-schema/reference/combining.html#anyof).
      - 'number_one_of' — A field does not match exactly one schema in [oneOf](https://json-schema.org/understanding-json-schema/reference/combining.html#oneof).
      - 'number_all_of' — A field does not match all schemas in [allOf](https://json-schema.org/understanding-json-schema/reference/combining.html#allof).
      - 'number_not' — A field matches an exclusive schema in not.
      - 'number_gte' — A field contains a number that is not greater than or equal to the minimum value.
      - 'number_gt' — A field contains a number that is not strictly greater than the minimum value.
      - 'number_lte' — A field contains a number that is not less than or equal to the maximum value.
      - 'number_lt' — A field contains a number that is not strictly less than the maximum value.
      - 'multiple_of' — A field contains a number that is not a multiple of the specified value.
      - 'array_no_additional_items' — A field contains a closed tuple array with invalid additional elements.
      - 'array_min_items' — A field contains an array with too few elements.
      - 'array_max_items' — A field contains an array with too many elements.
      - 'contains' — An array does not contain any element of its contained type.
      - 'array_min_properties' — An array does not contain enough elements of its contained type.
      - 'array_max_properties' — An array contains too many elements of its contained type.
      - 'additional_property_not_allowed' — A field is present but not defined in a closed schema.
      - 'invalid_property_pattern' — A field name that matched a pattern property does not contain a valid value.
      - 'invalid_property_name' — A field name is invalid.
      - 'string_gte' — A field contains a string that is not greater than or equal to the minimum length.
      - 'string_gt' — A field contains a string that is not strictly greater than the minimum length.
      - 'string_lte' — A field contains a string that is not less than or equal to the maximum length.
      - 'string_lt' — A field contains a string that is not strictly less than the maximum length.
      - 'pattern' — A field contains a string that does not match the field's pattern.
      - 'format' — A field contains a string with an invalid format.
      - 'condition_then' — A value is not valid when a conditional expression evaluates to `true`.
      - 'condition_else' — A value is not valid when a conditional expression evaluates to `false`.
    - `error_count` number — The number of sampled documents that failed this validation.
    - `field` string — The path of the field that failed this validation.
    - `failed_ids` string[] — A list of the `_id` values for sampled documents that failed this validation.
    - `failed_documents_query` object — A MongoDB query filter that matches sampled documents that failed this validation.
  - `total_processed_count` number — The total number of documents that were sampled.
  - `total_error_count` number — The total number of documents that failed any validation.

---

[API](https://skmtc.dev/mongodb/apis/mongodb-atlas-app-services-admin-api.md) · [All operations](https://skmtc.dev/mongodb/apis/mongodb-atlas-app-services-admin-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/mongodb/mongodb-atlas-app-services-admin-api/revisions/1365ab72bc03/schema)
