Created
February 29, 2024 16:30
-
-
Save jlescalonap/2e78c2342340b049748dfd027d2b0720 to your computer and use it in GitHub Desktop.
Ejemplo de validación de schema en MongoDb.
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.createCollection('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' | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment