Я изучаю MongoDB, я создал коллекцию, и теперь, когда я пытаюсь вставить документ, в котором отображается "errmsg": "Проверка документа не пройдена", код: "121"
Ниже приведен код моей коллекции:
db.createCollection( "personprofiles", {
validator: { $jsonSchema: {
bsonType: "object",
required: [ "PersonID", "PersonName", "Gender", "DOB", "Occupation", "Noofchildren", "ProfileType", "Purge" ],
properties: {
PersonID: {
bsonType: "number",
description: "must be an integer and is required"
},
PersonName: {
bsonType: "string",
description: "must be an string and is required"
},
Gender: {
enum: [ "Male", "Female" ],
description: "can only be one of the enum values"
},
MartialStatus: {
enum: [ "Single", "Married" ],
description: "can only be one of the enum values"
},
DOB : {
bsonType: "date",
description: "must be an date and is required"
},
Occupation: {
bsonType: "string",
description: "must be an string and is required"
},
Noofchildren: {
bsonType: "number",
description: "must be an integer and is required"
},
ProfileType: {
enum: [ "Gymnast", "Judge", "CompetitionDirector", "Organizers", "Coach", "Administrator", "Volunteers" ],
description: "can only be one of the enum values"
},
Purge: {
enum: [ "Yes", "No" ],
description: "can only be one of the enum values"
},
Addresses: {
bsonType: "array",
description: "must be an array and is required",
required: [ "AddressID", "AddressType", "AddressLine1", "AddressLine2", "Area", "Locality","City","State","Country","PostalCode"],
properties: {
AddressID: {
bsonType: "number",
description: "must be an integer and is required"
},
AddressType: {
enum: [ "Permanent", "Temporary", "Correspondence", "Office" ],
description: "can only be one of the enum values"
},
AddressLine1: {
bsonType: "string",
description: "must be an string and is required"
},
AddressLine2: {
bsonType: "string",
description: "must be an string and is required"
},
Area: {
bsonType: "string",
description: "must be an string and is required"
},
Locality: {
bsonType: "string",
description: "must be an string and is required"
},
City: {
bsonType: "string",
description: "must be an string and isrequired"
},
State: {
bsonType: "string",
description: "must be an string and is required"
},
Country: {
bsonType: "string",
description: "must be an string and is required"
},
PostalCode: {
bsonType: "string",
description: "must be an string and is required"
}
}
},
ContactNumbers: {
bsonType: "array",
description: "must be an array and is required",
required:[ "ContactID", "ContactType"],
properties: {
ContactID: {
bsonType: "number",
description: "must be an integer and is required"
},
ContactType: {
enum: [ "Home", "Mobile", "Office", "CareOf", "Emergency" ],
description: "can only be one of the enum values and is required"
},
ContactNumber: {
bsonType: "object",
description: "must be an string and is required",
required: ["CountryCode", "RegionCode", "PhoneNumber"],
properties:{
CountryCode: {
bsonType: "string",
pattern: "^[+0-9]{2,4}$",
description: "must be an string and is required"
},
RegionCode: {
bsonType: "string",
pattern: "^[0-9]{3}$",
description: "must be an string and is required"
},
PhoneNumber:
{
bsonType: "string",
pattern: "^[0-9]{10}$",
description: "must be an string and is required"
}
}
}
}
},
Email:{
bsonType: "array",
description:"must be an array and is required",
required:["EmailID", "EmailType"],
properties:{
EmailID: {
bsonType: "number",
description:"must be an integer and is required"
},
EmailType:{
bsonType: "string",
pattern : "^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$",
description: "must be a string and match regular expression pattern"
}
}
}
}
} }
} )
Это документ, который я пытаюсь вставить
db.personprofiles.insert({
"PersonID": 1001,
"PersonName": "john simon",
"Gender": "Male",
"MartialStatus": "Single",
"DOB": "1997-8-1",
"Occupation": "Service",
"Noofchildren": 0,
"ProfileType": "Administrator",
"Purge": "yes",
"Addresses":[{
"AddressID": 1,
"AddressType":"Permanent",
"AddressLine1": "101/4",
"AddressLine2":"sundar nagar",
"Area": "kalina",
"Locality": "Santacruz(east)",
"City": "Mumbai",
"State": "Maharashtra",
"Country": "India",
"PostalCode": "400055"
}],
"ContactNumbers": [{
"ContactID":1,
"ContactType":"Home",
"ContactNumber":{
"CountryCode": "+91",
"RegionCode": "022",
"PhoneNumber": "700383555"
}
}],
Email:[{
EmailID: 1,
EmailType: "johnxyz@gmail.com"
}]
})
коллекция была созданауспешно, единственная проблема, я должен вставить документ.Невозможно определить ошибку.Кто-то может мне помочь?Похоже, я что-то забыл.