Advertisement
Aldin-SXR

$jsonSchema validation

Oct 14th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.61 KB | None | 0 0
  1. db.createCollection("publishers", {
  2.     validator: {
  3.         $jsonSchema: {
  4.             bsonType: "object",
  5.             required: [ "name", "email_address", "status", "created_at" ],
  6.             properties: {
  7.                 name: {
  8.                   bsonType: "string",
  9.                   description: "must be a string and is required",
  10.                 },
  11.                 email_address: {
  12.                   bsonType: "string",
  13.                   description: "must be a string and is required",
  14.                 },
  15.                 status: {
  16.                   enum: [ 1, 0 ],
  17.                   description: "must be either 0 or 1 and is required"
  18.                 },
  19.                 created_at: {
  20.                   bsonType: "int",
  21.                   description: "must be an integer and is required",
  22.                 }
  23.             }
  24.         }
  25.     }
  26. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement