Created
February 29, 2024 16:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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