Skip to content

Analyse Schema

The driver supports an automated detection of the schema of an existing collection. The schema is used to detect the types of the columns.

Usage

Schema Analysis

Analyse a collection to detect the values for each field and the percentage distribution of the types.

scala
val schemaExplorer = new SchemaExplorer()
val schemaAnalysis = schemaExplorer.analyzeSchema(PersonDocumentDAO)

Detect Schema

The Schema Detector can be used to detect the schema of a collection and is based on Schema Anaysis. The schema is used to detect the types of the columns and generate a JSON Schema for the collection. In case of multiple types of a field the Generation of the JSON Schema use the type with the most elements.

TIP

The JSON Schema format can be use to validate or generate data, as well to secure your Mongo Collection.

scala
val schemaExplorer = new SchemaExplorer()
val schema         = schemaExplorer.detectSchema(PersonDocumentDAO)
val schemaJson     = schema.toJson

Released under the Apache License 2.0.