2 releases
new 0.1.1 | Feb 4, 2025 |
---|---|
0.1.0 | Feb 3, 2025 |
#1293 in Database interfaces
41 downloads per month
84KB
2K
SLoC
jsonutil
Library to handle JSON schema and BSON schema types.
Document validation on MongoDB uses an hybrid form of JSON schema and BSON schema to implement runtime validation of data inserted/updated on a database collection.
JSON schema is too limited to express all database native types which are thus expressed by BSON types. MongoDB allows to define data schema and validation, when possible, as JSON type using the key type and enhance with the key bsonType.
lib.rs
:
Library to handle JSON schema and BSON schema types
Document validation on MongoDB uses an hybrid form of JSON schema and BSON schema to implement runtime validation of data inserted/updated on a database collection.
JSON schema is too limited to express all database native types
which are thus expressed by BSON types.
MongoDB allows to define data schema and validation, when possible, as
JSON type using the key type
and enhance with the key bsonType
.
Thus there are 3 forms to read validations from MongoDB
- bson::BsonSchema using only the
bsonType
key - mongodb::MongodbJsonSchema hybrid using both
type
andbsonType
key - json::JsonSchema which is a partial view on previous methods and complies with Draft-04
BSON types are mapped onto JSON types using the following table:
BSON Type | bsonType |
type |
JSON type |
---|---|---|---|
Double | "double" | "number" | Number |
String | "string" | "string" | String |
Object | "object" | "object" | Object |
Array | "array" | "array" | Array |
Binary Data | "binData" | - | - |
ObjectId | "objectId" | - | - |
Boolean | "bool" | "boolean" | Boolean |
Date | "date" | - | - |
Null | "null" | "null" | Null |
Regular Expression | "regex" | - | - |
JavaScript | "javascript" | - | - |
32-bit Signed Integer | "int" | "integer" | Integer |
64-bit Signed Integer | "long" | "integer" | Integer |
Timestamp | "timestamp" | - | - |
128-bit Decimal Float | "decimal" | "number" | Number |
Min Key | "minKey" | - | - |
Max Key | "maxKey" | - | - |
Dependencies
~0.7–1.8MB
~38K SLoC