Skip to content

Support for MongoDB $bsonType extensions #586

@ee987

Description

@ee987

When working with mongodb the database can enforce document structure with jsonSchema according to [1].

However mongodb has some own datatypes [2], like ObjectId, Date, Bool, Int that are not supported natively by json schema. These can be encoded by using the extension "bsonType" property instead of "type".

It would be very useful if jsonschema could validate such objects also. When a document fails validation inside mongodb you don't get any explanation why [3], so you always have to validate it with another validator client-side on failed insertions. Right now there is no such validator for python so the best workaround is to remove all bsonTypes before using jsonschema or convert the document into nodejs and use ajv. Neither option is really smooth.

[1] https://docs.mongodb.com/manual/reference/operator/query/jsonSchema/#jsonschema-extension
[2] https://docs.mongodb.com/manual/reference/operator/query/type/#document-type-available-types
[3] https://jira.mongodb.org/browse/SERVER-20547

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions