Last active
January 14, 2021 20:26
-
-
Save katookatoo/80c93d1e0370bf9afbcdbbfd4eff168f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validator = { | |
"$and": [ | |
{ | |
"geoLocation": { | |
"$geoWithin": { | |
"$geometry": { | |
"type": "Polygon", | |
"coordinates": [ | |
[ | |
[ | |
-73.91326904296874, | |
40.91091803848203 | |
], | |
[ | |
-74.01626586914062, | |
40.75297891717686 | |
], | |
[ | |
-74.05677795410156, | |
40.65563874006115 | |
], | |
[ | |
-74.08561706542969, | |
40.65199222800328 | |
], | |
[ | |
-74.14329528808594, | |
40.64417760251725 | |
], | |
[ | |
-74.18724060058594, | |
40.643656594948524 | |
], | |
[ | |
-74.234619140625, | |
40.556591288249905 | |
], | |
[ | |
-74.26345825195312, | |
40.513277131087484 | |
], | |
[ | |
-74.2510986328125, | |
40.49500373230525 | |
], | |
[ | |
-73.94691467285156, | |
40.543026009954986 | |
], | |
[ | |
-73.740234375, | |
40.589449604232975 | |
], | |
[ | |
-73.71826171874999, | |
40.820045086716505 | |
], | |
[ | |
-73.78829956054686, | |
40.8870435151357 | |
], | |
[ | |
-73.91326904296874, | |
40.91091803848203 | |
] | |
] | |
] | |
} | |
} | |
} | |
}, | |
{ | |
"$expr": { | |
"$lt": [ | |
"$discountedPrice", | |
"$originalPrice" | |
] | |
} | |
}, | |
{ | |
"$expr": { | |
"$lte": [ | |
{ | |
"$size": { | |
"$filter": { | |
"input": "$saleDetails.bids.winner", | |
"cond": "$$this" | |
} | |
} | |
}, | |
1 | |
] | |
} | |
}, | |
{ | |
"$jsonSchema": { | |
"bsonType": "object", | |
"properties": { | |
"PID": { | |
"bsonType": "string", | |
"pattern": "^[A-Z]{2}[0-9]{5}[A-Z]+[0-9]+$" | |
}, | |
"localization": { | |
"bsonType": "object", | |
"additionalProperties": false, | |
"patternProperties": { | |
"^description_(es|de|fr)+$": { | |
"bsonType": "string" | |
} | |
} | |
}, | |
"type": { | |
"bsonType": "string", | |
"enum": [ | |
"Residential", | |
"Commercial", | |
"Industrial", | |
"Land" | |
] | |
}, | |
"agents": { | |
"bsonType": "array", | |
"uniqueItems": true, | |
"maxItems": 3, | |
"items": { | |
"bsonType": "object", | |
"properties": { | |
"name": { | |
"bsonType": "string" | |
}, | |
"email": { | |
"bsonType": "string" | |
}, | |
"phone": { | |
"bsonType": "long" | |
} | |
}, | |
"required": [ | |
"name" | |
], | |
"anyOf": [ | |
{ | |
"required": [ | |
"phone" | |
] | |
}, | |
{ | |
"required": [ | |
"email" | |
] | |
} | |
] | |
} | |
} | |
}, | |
"required": [ | |
"PID", | |
"type" | |
], | |
"dependencies": { | |
"saleDate": [ | |
"saleDetails" | |
] | |
} | |
} | |
} | |
] | |
}; | |
use test; | |
db.createCollection("p", {validator: validator}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.p.insert( | |
{ | |
"PID": "1", | |
"agents": [ | |
{ | |
"name": "Ana Blake" | |
}, | |
{ | |
"name": "Felix Morin" | |
}, | |
{ | |
"name": "Dilan Adams" | |
}, | |
{ | |
"name": "Ana Blake" | |
} | |
], | |
"description": "Spacious 2BR apartment", | |
"localization": { | |
"description_cz": "Prostorný byt 2 + kk" | |
}, | |
"type": "House", | |
"address": { | |
"street1": "235 E 22nd St", | |
"city": "New York", | |
"state": "NY", | |
"zip": "10010" | |
}, | |
"originalPrice": 990000, | |
"discountedPrice": 990000, | |
"geoLocation": [ | |
-73.9826509, | |
80.737499 | |
], | |
"saleDate": ISODate("2020-12-01"), | |
"saleDetails": { | |
"price": 970000, | |
"buyer": { | |
"id": "24434" | |
}, | |
"bids": [ | |
{ | |
"price": 950000, | |
"winner": true, | |
"bidder": { | |
"id": "24432", | |
"name": "Sam James", | |
"contact": { | |
"email": "sjames@gmail.com" | |
} | |
} | |
}, | |
{ | |
"price": 970000, | |
"winner": true, | |
"bidder": { | |
"id": "24434", | |
"name": "Joana Miles", | |
"contact": { | |
"email": "jm@gmail.com" | |
} | |
} | |
} | |
] | |
} | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.p.insert( | |
{ | |
"PID": "EV10010A1", | |
"agents": [ | |
{ | |
"name": "Ana Blake", | |
"email": "anab@rcgk.com" | |
} | |
], | |
"description": "Spacious 2BR apartment", | |
"localization": { | |
"description_es": "Espacioso apartamento de 2 dormitorios" | |
}, | |
"type": "Residential", | |
"address": { | |
"street1": "235 E 22nd St", | |
"street2": "Apt 42", | |
"city": "New York", | |
"state": "NY", | |
"zip": "10010" | |
}, | |
"originalPrice": 990000, | |
"discountedPrice": 980000, | |
"geoLocation": [ | |
-73.9826509, | |
40.737499 | |
], | |
"saleDate": ISODate("2020-12-01"), | |
"saleDetails": { | |
"price": 970000, | |
"buyer": { | |
"id": "24434" | |
}, | |
"bids": [ | |
{ | |
"price": 950000, | |
"winner": false, | |
"bidder": { | |
"id": "24432", | |
"name": "Sam James", | |
"contact": { | |
"email": "sjames@gmail.com" | |
} | |
} | |
}, | |
{ | |
"price": 970000, | |
"winner": true, | |
"bidder": { | |
"id": "24434", | |
"name": "Joana Miles", | |
"contact": { | |
"email": "jm@gmail.com" | |
} | |
} | |
} | |
] | |
} | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"writeError": { | |
"code": 121, | |
"errmsg": "Document failed validation", | |
"errInfo": { | |
"failingDocumentId": ObjectId("6000a8b67d26c8e5b1670216"), | |
"details": { | |
"operatorName": "$and", | |
"clausesNotSatisfied": [ | |
{ | |
"index": 0, | |
"details": { | |
"operatorName": "$geoWithin", | |
"specifiedAs": { | |
"geoLocation": { | |
"$geoWithin": { | |
"$geometry": { | |
"type": "Polygon", | |
"coordinates": [ | |
[ | |
[ | |
-73.91326904296874, | |
40.91091803848203 | |
], | |
[ | |
-74.01626586914062, | |
40.75297891717686 | |
], | |
[ | |
-74.05677795410156, | |
40.65563874006115 | |
], | |
[ | |
-74.08561706542969, | |
40.65199222800328 | |
], | |
[ | |
-74.14329528808594, | |
40.64417760251725 | |
], | |
[ | |
-74.18724060058594, | |
40.643656594948524 | |
], | |
[ | |
-74.234619140625, | |
40.556591288249905 | |
], | |
[ | |
-74.26345825195312, | |
40.513277131087484 | |
], | |
[ | |
-74.2510986328125, | |
40.49500373230525 | |
], | |
[ | |
-73.94691467285156, | |
40.543026009954986 | |
], | |
[ | |
-73.740234375, | |
40.589449604232975 | |
], | |
[ | |
-73.71826171874999, | |
40.820045086716505 | |
], | |
[ | |
-73.78829956054686, | |
40.8870435151357 | |
], | |
[ | |
-73.91326904296874, | |
40.91091803848203 | |
] | |
] | |
] | |
} | |
} | |
} | |
}, | |
"reason": "none of the considered geometries were contained within the expression’s geometry", | |
"consideredValues": [ | |
-73.9826509, | |
80.737499 | |
] | |
} | |
}, | |
{ | |
"index": 1, | |
"details": { | |
"operatorName": "$expr", | |
"specifiedAs": { | |
"$expr": { | |
"$lt": [ | |
"$discountedPrice", | |
"$originalPrice" | |
] | |
} | |
}, | |
"reason": "expression did not match", | |
"expressionResult": false | |
} | |
}, | |
{ | |
"index": 2, | |
"details": { | |
"operatorName": "$expr", | |
"specifiedAs": { | |
"$expr": { | |
"$lte": [ | |
{ | |
"$size": { | |
"$filter": { | |
"input": "$saleDetails.bids.winner", | |
"cond": "$$this" | |
} | |
} | |
}, | |
1 | |
] | |
} | |
}, | |
"reason": "expression did not match", | |
"expressionResult": false | |
} | |
}, | |
{ | |
"index": 3, | |
"details": { | |
"operatorName": "$jsonSchema", | |
"schemaRulesNotSatisfied": [ | |
{ | |
"operatorName": "properties", | |
"propertiesNotSatisfied": [ | |
{ | |
"propertyName": "PID", | |
"details": [ | |
{ | |
"operatorName": "pattern", | |
"specifiedAs": { | |
"pattern": "^[A-Z]{2}[0-9]{5}[A-Z]+[0-9]+$" | |
}, | |
"reason": "regular expression did not match", | |
"consideredValue": "1" | |
} | |
] | |
}, | |
{ | |
"propertyName": "localization", | |
"details": [ | |
{ | |
"operatorName": "additionalProperties", | |
"specifiedAs": { | |
"additionalProperties": false | |
}, | |
"additionalProperties": [ | |
"description_cz" | |
] | |
} | |
] | |
}, | |
{ | |
"propertyName": "type", | |
"details": [ | |
{ | |
"operatorName": "enum", | |
"specifiedAs": { | |
"enum": [ | |
"Residential", | |
"Commercial", | |
"Industrial", | |
"Land" | |
] | |
}, | |
"reason": "value was not found in enum", | |
"consideredValue": "House" | |
} | |
] | |
}, | |
{ | |
"propertyName": "agents", | |
"details": [ | |
{ | |
"operatorName": "maxItems", | |
"specifiedAs": { | |
"maxItems": 3 | |
}, | |
"reason": "array did not match specified length", | |
"consideredValue": [ | |
{ | |
"name": "Ana Blake" | |
}, | |
{ | |
"name": "Felix Morin" | |
}, | |
{ | |
"name": "Dilan Adams" | |
}, | |
{ | |
"name": "Ana Blake" | |
} | |
] | |
}, | |
{ | |
"operatorName": "uniqueItems", | |
"specifiedAs": { | |
"uniqueItems": true | |
}, | |
"reason": "found a duplicate item", | |
"consideredValue": [ | |
{ | |
"name": "Ana Blake" | |
}, | |
{ | |
"name": "Felix Morin" | |
}, | |
{ | |
"name": "Dilan Adams" | |
}, | |
{ | |
"name": "Ana Blake" | |
} | |
], | |
"duplicatedValue": { | |
"name": "Ana Blake" | |
} | |
}, | |
{ | |
"operatorName": "items", | |
"reason": "At least one item did not match the sub-schema", | |
"itemIndex": 0, | |
"details": [ | |
{ | |
"operatorName": "anyOf", | |
"schemasNotSatisfied": [ | |
{ | |
"index": 0, | |
"details": [ | |
{ | |
"operatorName": "required", | |
"specifiedAs": { | |
"required": [ | |
"phone" | |
] | |
}, | |
"missingProperties": [ | |
"phone" | |
] | |
} | |
] | |
}, | |
{ | |
"index": 1, | |
"details": [ | |
{ | |
"operatorName": "required", | |
"specifiedAs": { | |
"required": [ | |
"email" | |
] | |
}, | |
"missingProperties": [ | |
"email" | |
] | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
} | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment