{"action":"opened","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/2890","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/2890/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/2890/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/2890/events","html_url":"https://github.com/Automattic/mongoose/issues/2890","id":69008669,"number":2890,"title":"Polygon validation error?","user":{"login":"malcommac","id":235645,"avatar_url":"https://avatars.githubusercontent.com/u/235645?v=3","gravatar_id":"","url":"https://api.github.com/users/malcommac","html_url":"https://github.com/malcommac","followers_url":"https://api.github.com/users/malcommac/followers","following_url":"https://api.github.com/users/malcommac/following{/other_user}","gists_url":"https://api.github.com/users/malcommac/gists{/gist_id}","starred_url":"https://api.github.com/users/malcommac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malcommac/subscriptions","organizations_url":"https://api.github.com/users/malcommac/orgs","repos_url":"https://api.github.com/users/malcommac/repos","events_url":"https://api.github.com/users/malcommac/events{/privacy}","received_events_url":"https://api.github.com/users/malcommac/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-16T20:59:47Z","updated_at":"2015-04-16T20:59:47Z","closed_at":null,"body":"I would to store a polygon inside a MongoDB document using mongoose.\r\nThis is my schema:\r\n\r\n    var alarmSchema = new mongoose.Schema({\r\n    \t// ... some other fields ....\r\n    \tloc :   {\r\n    \t\t\"type\": {\r\n    \t\t\t\"type\": String,\r\n    \t\t\t\"enum\": [\r\n    \t\t\t\t\"Point\",\r\n    \t\t\t\t\"MultiPoint\",\r\n    \t\t\t\t\"LineString\",\r\n    \t\t\t\t\"MultiLineString\",\r\n    \t\t\t\t\"Polygon\",\r\n    \t\t\t\t\"MultiPolygon\"\r\n    \t\t\t]\r\n    \t\t},\r\n    \t\t\"coordinates\": [[Number]]\r\n    \t}\r\n    });\r\n\r\nSo I've tried to add a new object of this type using:\r\n\r\n    var Alarm = db.model('Alarm', alarmSchema);\r\n    var alarmObj = new Alarm();\r\n    var polygonArray = [[10.371094,42.391009],[14.238281,44.024422],[16.259766,42.130821]];\r\n    alarmObj.loc = {type : \"Polygon\" , coordinates : polygonArray};\r\n    return alarmObj;\r\n\r\nWhen i try to save this I get this error:\r\n\r\n> ValidationError: CastError: Cast to Array failed for value ....(the\r\n> array passed)...\r\n\r\nAny idea?\r\n\r\nAfter that I would to find a list of these alarmObj which contains a passed point.\r\nI think this is the right query:\r\n\r\n    var geojsonPoint = { type: 'Point', coordinates: [44.95899,8.911711] }\r\n    AlarmModel.find({loc: { $geoIntersects: { $geometry: geojsonPoint}}},function(err,list) {});\r\n\r\nIs it okay?"}}