How can I add a schema validation for requiring an array of strings in MongoDB from Mongo Shell?









up vote
0
down vote

favorite












I am intending to run the following command in Mongo Shell on my Collection once I have it perfected. However, I cannot figure out how to handle the last item in my required properties list, because it's the only one that is an array. It's an array of strings, to be specific. It's the last item, the imageIDs property. I put enum but I don't think that's right. How can I require its type to be an array of strings?



 db.runCommand( 
collMod: "CustomerOrders",
validator: $jsonSchema:
bsonType: "object",
required: [ "dateTime", "restaurantName", "restaurantCity", "restaurantCountry", "contactName", "contactPhone", "contactEmail", "menuSize", "pricePaid", "currentLanguage", "targetLanguage", "imageIDs" ],
properties:
dateTime:
bsonType: "string",
description: "must be a string and is required"
,
restaurantName:
bsonType: "string",
description: "must be a string and is required"
,
restaurantCity:
bsonType: "string",
description: "must be a string and is required"
,
restaurantCountry:
bsonType: "string",
description: "must be a string and is required"
,
contactName:
bsonType: "string",
description: "must be a string and is required"
,
contactPhone:
bsonType: "string",
description: "must be a string and is required"
,
contactEmail:
bsonType: "string",
description: "must be a string and is required"
,
menuSize:
bsonType: "string",
description: "must be a string and is required"
,
pricePaid:
bsonType: "double",
description: "must be a string and is required"
,
currentLanguage:
bsonType: "string",
description: "must be a string and is required"
,
targetLanguage:
bsonType: "string",
description: "must be a string and is required"
,
imageIDs:
bsonType: "enum",
description: "can only be one of the enum values and is required"


,
validationLevel: "strict"
)









share|improve this question

























    up vote
    0
    down vote

    favorite












    I am intending to run the following command in Mongo Shell on my Collection once I have it perfected. However, I cannot figure out how to handle the last item in my required properties list, because it's the only one that is an array. It's an array of strings, to be specific. It's the last item, the imageIDs property. I put enum but I don't think that's right. How can I require its type to be an array of strings?



     db.runCommand( 
    collMod: "CustomerOrders",
    validator: $jsonSchema:
    bsonType: "object",
    required: [ "dateTime", "restaurantName", "restaurantCity", "restaurantCountry", "contactName", "contactPhone", "contactEmail", "menuSize", "pricePaid", "currentLanguage", "targetLanguage", "imageIDs" ],
    properties:
    dateTime:
    bsonType: "string",
    description: "must be a string and is required"
    ,
    restaurantName:
    bsonType: "string",
    description: "must be a string and is required"
    ,
    restaurantCity:
    bsonType: "string",
    description: "must be a string and is required"
    ,
    restaurantCountry:
    bsonType: "string",
    description: "must be a string and is required"
    ,
    contactName:
    bsonType: "string",
    description: "must be a string and is required"
    ,
    contactPhone:
    bsonType: "string",
    description: "must be a string and is required"
    ,
    contactEmail:
    bsonType: "string",
    description: "must be a string and is required"
    ,
    menuSize:
    bsonType: "string",
    description: "must be a string and is required"
    ,
    pricePaid:
    bsonType: "double",
    description: "must be a string and is required"
    ,
    currentLanguage:
    bsonType: "string",
    description: "must be a string and is required"
    ,
    targetLanguage:
    bsonType: "string",
    description: "must be a string and is required"
    ,
    imageIDs:
    bsonType: "enum",
    description: "can only be one of the enum values and is required"


    ,
    validationLevel: "strict"
    )









    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am intending to run the following command in Mongo Shell on my Collection once I have it perfected. However, I cannot figure out how to handle the last item in my required properties list, because it's the only one that is an array. It's an array of strings, to be specific. It's the last item, the imageIDs property. I put enum but I don't think that's right. How can I require its type to be an array of strings?



       db.runCommand( 
      collMod: "CustomerOrders",
      validator: $jsonSchema:
      bsonType: "object",
      required: [ "dateTime", "restaurantName", "restaurantCity", "restaurantCountry", "contactName", "contactPhone", "contactEmail", "menuSize", "pricePaid", "currentLanguage", "targetLanguage", "imageIDs" ],
      properties:
      dateTime:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      restaurantName:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      restaurantCity:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      restaurantCountry:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      contactName:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      contactPhone:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      contactEmail:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      menuSize:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      pricePaid:
      bsonType: "double",
      description: "must be a string and is required"
      ,
      currentLanguage:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      targetLanguage:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      imageIDs:
      bsonType: "enum",
      description: "can only be one of the enum values and is required"


      ,
      validationLevel: "strict"
      )









      share|improve this question













      I am intending to run the following command in Mongo Shell on my Collection once I have it perfected. However, I cannot figure out how to handle the last item in my required properties list, because it's the only one that is an array. It's an array of strings, to be specific. It's the last item, the imageIDs property. I put enum but I don't think that's right. How can I require its type to be an array of strings?



       db.runCommand( 
      collMod: "CustomerOrders",
      validator: $jsonSchema:
      bsonType: "object",
      required: [ "dateTime", "restaurantName", "restaurantCity", "restaurantCountry", "contactName", "contactPhone", "contactEmail", "menuSize", "pricePaid", "currentLanguage", "targetLanguage", "imageIDs" ],
      properties:
      dateTime:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      restaurantName:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      restaurantCity:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      restaurantCountry:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      contactName:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      contactPhone:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      contactEmail:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      menuSize:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      pricePaid:
      bsonType: "double",
      description: "must be a string and is required"
      ,
      currentLanguage:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      targetLanguage:
      bsonType: "string",
      description: "must be a string and is required"
      ,
      imageIDs:
      bsonType: "enum",
      description: "can only be one of the enum values and is required"


      ,
      validationLevel: "strict"
      )






      mongodb






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 8 at 21:49









      Aerovistae

      16.4k2895160




      16.4k2895160






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          For imageIDs, the property that needed to be an array of strings, I changed the schema with the following specifications:



           imageIDs: 
          bsonType: "array",
          description: "must be an array and is required",
          minItems: 1,
          maxItems: 25,
          items:
          bsonType: "string",




          Honestly the MongoDB documentation is kind of exhausting and severely lacking in examples. This page on the json schema properties is mildly helpful. I figured this out by just trial and error to see what was rejected and what wasn't until I knew that what I had was correct.






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53216671%2fhow-can-i-add-a-schema-validation-for-requiring-an-array-of-strings-in-mongodb-f%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            For imageIDs, the property that needed to be an array of strings, I changed the schema with the following specifications:



             imageIDs: 
            bsonType: "array",
            description: "must be an array and is required",
            minItems: 1,
            maxItems: 25,
            items:
            bsonType: "string",




            Honestly the MongoDB documentation is kind of exhausting and severely lacking in examples. This page on the json schema properties is mildly helpful. I figured this out by just trial and error to see what was rejected and what wasn't until I knew that what I had was correct.






            share|improve this answer
























              up vote
              0
              down vote



              accepted










              For imageIDs, the property that needed to be an array of strings, I changed the schema with the following specifications:



               imageIDs: 
              bsonType: "array",
              description: "must be an array and is required",
              minItems: 1,
              maxItems: 25,
              items:
              bsonType: "string",




              Honestly the MongoDB documentation is kind of exhausting and severely lacking in examples. This page on the json schema properties is mildly helpful. I figured this out by just trial and error to see what was rejected and what wasn't until I knew that what I had was correct.






              share|improve this answer






















                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                For imageIDs, the property that needed to be an array of strings, I changed the schema with the following specifications:



                 imageIDs: 
                bsonType: "array",
                description: "must be an array and is required",
                minItems: 1,
                maxItems: 25,
                items:
                bsonType: "string",




                Honestly the MongoDB documentation is kind of exhausting and severely lacking in examples. This page on the json schema properties is mildly helpful. I figured this out by just trial and error to see what was rejected and what wasn't until I knew that what I had was correct.






                share|improve this answer












                For imageIDs, the property that needed to be an array of strings, I changed the schema with the following specifications:



                 imageIDs: 
                bsonType: "array",
                description: "must be an array and is required",
                minItems: 1,
                maxItems: 25,
                items:
                bsonType: "string",




                Honestly the MongoDB documentation is kind of exhausting and severely lacking in examples. This page on the json schema properties is mildly helpful. I figured this out by just trial and error to see what was rejected and what wasn't until I knew that what I had was correct.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 8 at 22:28









                Aerovistae

                16.4k2895160




                16.4k2895160



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53216671%2fhow-can-i-add-a-schema-validation-for-requiring-an-array-of-strings-in-mongodb-f%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                    How do I collapse sections of code in Visual Studio Code for Windows?

                    ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ