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"
)
mongodb
add a comment |
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"
)
mongodb
add a comment |
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"
)
mongodb
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
mongodb
asked Nov 8 at 21:49
Aerovistae
16.4k2895160
16.4k2895160
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 8 at 22:28
Aerovistae
16.4k2895160
16.4k2895160
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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