From 443009db00b50717c5eacafd12b02d67af363116 Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Tue, 18 Mar 2025 11:02:21 -0400 Subject: [PATCH] chore(mongodb-constants): add validation template --- packages/mongodb-constants/src/index.spec.ts | 1 + packages/mongodb-constants/src/index.ts | 1 + .../src/validation-template.ts | 29 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 packages/mongodb-constants/src/validation-template.ts diff --git a/packages/mongodb-constants/src/index.spec.ts b/packages/mongodb-constants/src/index.spec.ts index 4eb886f3..62e7a779 100644 --- a/packages/mongodb-constants/src/index.spec.ts +++ b/packages/mongodb-constants/src/index.spec.ts @@ -29,6 +29,7 @@ describe('constants', function () { 'FULL_SCAN_STAGES', 'REQUIRED_AS_FIRST_STAGE', 'SYSTEM_VARIABLES', + 'VALIDATION_TEMPLATE', 'ATLAS_SEARCH_TEMPLATES', 'ATLAS_VECTOR_SEARCH_TEMPLATE', ]); diff --git a/packages/mongodb-constants/src/index.ts b/packages/mongodb-constants/src/index.ts index 214efc4a..d58137de 100644 --- a/packages/mongodb-constants/src/index.ts +++ b/packages/mongodb-constants/src/index.ts @@ -9,6 +9,7 @@ export * from './ns'; export * from './query-operators'; export * from './stage-operators'; export * from './system-variables'; +export * from './validation-template'; export { getFilteredCompletions, wrapField } from './filter'; export type { Completion, diff --git a/packages/mongodb-constants/src/validation-template.ts b/packages/mongodb-constants/src/validation-template.ts new file mode 100644 index 00000000..83b7d99b --- /dev/null +++ b/packages/mongodb-constants/src/validation-template.ts @@ -0,0 +1,29 @@ +export const VALIDATION_TEMPLATE = `/** + * This is a starter template for a schema validation rule for a collection. + * More information on schema validation rules can be found at: + * https://www.mongodb.com/docs/manual/core/schema-validation/ + */ +{ + $jsonSchema: { + title: "Library.books", + bsonType: "object", + required: ["fieldname1", "fieldname2"], + properties: { + fieldname1: { + bsonType: "string", + description: "Fieldname1 must be a string", + }, + fieldname2: { + bsonType: "int", + description: "Fieldname2 must be an integer", + }, + arrayFieldName: { + bsonType: "array", + items: { + bsonType: "string" + }, + description: "arrayFieldName must be an array of strings" + }, + } + } +}`;