Skip to content

Instantly share code, notes, and snippets.

@jlescalonap
Created February 29, 2024 16:39
Show Gist options
  • Save jlescalonap/c476dbddf8a658d4446ac6c5f62ac497 to your computer and use it in GitHub Desktop.
Save jlescalonap/c476dbddf8a658d4446ac6c5f62ac497 to your computer and use it in GitHub Desktop.
Ejemplo de la modificación del validation action, es decir si es error, o un simple warn.
db.runCommand({
collMod: 'posts',
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['title', 'text', 'creator', 'comments'],
properties: {
title: {
bsonType: 'string',
description: 'must be a string and is required'
},
text: {
bsonType: 'string',
description: 'must be a string and is required'
},
creator: {
bsonType: 'objectId',
description: 'must be an objectid and is required'
},
comments: {
bsonType: 'array',
description: 'must be an array and is required',
items: {
bsonType: 'object',
required: ['text', 'author'],
properties: {
text: {
bsonType: 'string',
description: 'must be a string and is required'
},
author: {
bsonType: 'objectId',
description: 'must be an objectid and is required'
}
}
}
}
}
}
},
validationAction: 'warn'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment