0

Is there any way I can insert a property into this validator for inserting documents into MongoDB that will not impact validation but that I can retrieve via query?

To give some context: I use the validator to create a form dynamically, and I need some extra information to create the form according to my needs.

{
  $jsonSchema: {
    bsonType: 'object',
    required: [
      'active',
      'productive',
      'translation',
      'code'
    ],
    properties: {
      code: {
        bsonType: 'string',
        minLength: 0,
        maxLength: 50,
      },
      active: {
        bsonType: 'bool'
      },
      productive: {
        bsonType: 'bool'
      },
      translation: {
        bsonType: 'object',
        properties: {
          'pt-BR': {
            bsonType: 'object',
            required: [
              'description'
            ],
            properties: {
              description: {
                bsonType: 'string',
                minLength: 0,
                maxLength: 50
              }
            }
          },
          'en-US': {
            bsonType: 'object',
            required: [
              'description'
            ],
            properties: {
              description: {
                bsonType: 'string',
                minLength: 0,
                maxLength: 50
              }
            }
          }
        }
      },
      audit: {
        bsonType: 'object',
        required: [
          'user'
        ],
        properties: {
          user: {
            bsonType: 'string'
          }
        }
      }
    }
  }
}

1 Answer 1

0

MongoDB is based on JSON Schema draft-04. By the Specification, unknown keywords should be ignored during validation.

A common pattern for unknown or custom keywords is to prefix x-

{
  $jsonSchema: {
    bsonType: 'object',
    x-mycustomKeyword: {
      bsonType: 'string'
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.