- Reference >
- Database Commands >
- Diagnostic Commands >
- validateDBMetadata
validateDBMetadata¶
On this page
Definition¶
New in version 5.0.
-
validateDBMetadata
¶ The
validateDBMetadata
command checks that the stored metadata of a database or a collection is valid within a particular API version.validateDBMetadata
reports errors, but does not have the capability to fix errors.
Syntax¶
The command has the following syntax:
Command Fields¶
The command takes the following fields:
Field | Type | Description |
---|---|---|
apiParameters | document | All Fields are Required.
|
db |
string | Optional. The name of the database to validate. If no database is specified, all databases will be validated. |
collection |
string | Optional. The name of the collection or view to validate. If no
collection or view is specified, all collections in the database
specified by db will be validated. If no database is
specified, all collections in all databases will be validated. |
Behavior¶
Validate all collections in all databases, reporting APIStrictError and APIVersionError error responses.
Validate all collections in
inventory
:Validate the
sales
collection in theinventory
database:Validate any and all
sales
collections across all databases:
Note
Your user must have the validate
privilege action on
all collections you want to validate.
Output¶
-
validateDBMetadata.
apiVersionErrors
¶ Array of documents describing API Version errors.
-
validateDBMetadata.apiVersionErrors[n].
ns
¶ Namespace of the collection or view with error.
-
validateDBMetadata.apiVersionErrors[n].
code
¶ Numeric error code.
-
validateDBMetadata.apiVersionErrors[n].
codeName
¶ Name of the error code.
-
validateDBMetadata.apiVersionErrors[n].
errmsg
¶ String describing the error.
-
validateDBMetadata.
ok
¶ If the command fails,
ok
is set to1
. Otherwise,ok
is set to0
.validateDBMetadata.ok
may have a value of0
and still report validation errors.
-
validateDBMetadata.
hasMoreErrors
¶ If
true
, there are additional errors.
Example¶
Use the sample Query API code to create a sales
collection in mongosh
:
Add a text index on the item
field.
Validate the sales
collection for strict compliance with API
version 1 and include deprecationErrors
in the output.
validateDBMetadata
reports an APIStrictError
on the
item_text
index.