AWS DocumentDB - JSON Schema Validator

86 views Asked by At

We have been developing collections in mongoDB, with

db.createCollection('xyzCollection', { 
  validator: 
{ 
  $jsonSchema: {....}}})

Now we are moving to AWS DocumentDB & this script fails with the error: enter image description here

Can someone help identifying the correct keyword to apply validator directly to schema, and not using backend code to do this.

I tried checking supported keywords on AWS documentations : https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html#mongo-apis-database I have also gone through with this link: Alternative to schema validation in AWS DocumentDB But the question is remains unsolved.

But 'validator' is not mentioned anywhere.

Does this mean that we cannot apply validations directly? Do we only have the option to apply validations via API.

1

There are 1 answers

1
cooltodinesh On

AWS DocumentDB now supports schema validations and you can use validator keyword while creating collection.

Example:

db.createCollection('xyzCollection', {
   validator: {
     $jsonSchema: {
       required: ["name"]
     }
    }
  }
)
{ ok: 1 }