echoes-xyz / mongoose-geojson-schema Goto Github PK
View Code? Open in Web Editor NEWSchema definitions for GeoJSON types for use with Mongoose JS
License: MIT License
Schema definitions for GeoJSON types for use with Mongoose JS
License: MIT License
Right now, this will get past validation when passed as the validate for the coordinates
key of a GeoJSON Point:
[ 193 ]
However, Mongo may then respond with an error along the following lines. This could in turn crash your server, if you expected the record to work in Mongo once it got passed Mongoose validation:
Can't extract geo keys from object, malformed geometry?:{ type: "Point", coordinates: [ 193 ] }
The ideal solution is to add stricter validation to the validation of coordinate pairs so that this wouldn't pass validation.
The Latitude value should be restricted to -90 to 90, while the Longitude value should be restricted to -180 to 180.
Hi,
We are currently using your awesome library in a project, and we use another library to convert models into JsonSchemas.
I've seen that this library lacks of the schemaName of each SchemaType, which is required for conversion.
In fact, you can see that mongoose schemas implement this property string.js, date.js
I'll be doing a pull request in some minutes, and if you like it, I would really appreciate a merge :)
Thanks!
Mongoose 5.11 now includes its own types & this is causing type errors.
This:
var pointData = {
type: 'Point',
coordinates: [NaN, NaN]
};
passes the range checks but it shouldn't.
A benefit of using Mongoose over raw Mongo is that field names are
explicitly defined and validated.
It would be nice if GeoJSON.Feature could allow defining specific
'properties' as well as continuing to provide the boilerplate schema
that it already does.
Some potential syntax options:
// Option 1:
// Allow defining just properties:
geoFeature: GeoJSON.Feature({
a: 1,
b: 2,
);
//Option 2:
// Allow defining anything or everything.
// Internally, add any missing bits from the boilerplate
geoFeature: GeoJSON.Feature({
properties: {
a: 1,
b: 2,
},
});
Option 2 is the more flexible way to go. I don't think either is
backcompat, though. You would to start doing this:
geoFeature: GeoJSON.Feature();
But, perhaps that's a good direction to go anyway, as it allows you to
add extra validation to any GeoJSON schema element:
myPolyGon : geoJSON.Polygon({ required: true, validator: myValidator });
When updating a document with a mongoose geojson schema, and trying to set it to null, when required: false
, I'm getting :
error: TypeError: Cannot read property 'type' of null
at SchemaType.Polygon.cast (C:\Users\Cyril\Code\imagine-network-api\node_modules\mongoose-geojson-schema\index.js:27
5:15)
at SchemaType.castForQuery (C:\Users\Cyril\Code\imagine-network-api\node_modules\mongoose\lib\schematype.js:952:15)
at castUpdateVal (C:\Users\Cyril\Code\imagine-network-api\node_modules\mongoose\lib\services\query\castUpdate.js:288
:17)
at walkUpdatePath (C:\Users\Cyril\Code\imagine-network-api\node_modules\mongoose\lib\services\query\castUpdate.js:20
9:20)
at castUpdate (C:\Users\Cyril\Code\imagine-network-api\node_modules\mongoose\lib\services\query\castUpdate.js:70:18)
at Query._castUpdate (C:\Users\Cyril\Code\imagine-network-api\node_modules\mongoose\lib\query.js:2804:10)
at castDoc (C:\Users\Cyril\Code\imagine-network-api\node_modules\mongoose\lib\query.js:2830:18)
at Query._findAndModify (C:\Users\Cyril\Code\imagine-network-api\node_modules\mongoose\lib\query.js:2000:17)
at Query._findOneAndUpdate (C:\Users\Cyril\Code\imagine-network-api\node_modules\mongoose\lib\query.js:1856:8)
at C:\Users\Cyril\Code\imagine-network-api\node_modules\kareem\index.js:253:8
at C:\Users\Cyril\Code\imagine-network-api\node_modules\kareem\index.js:18:7
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
https://datatracker.ietf.org/doc/html/rfc7946#section-3.2
A Feature object has a member with the name "properties". The value of the properties member is an object (any JSON object or a JSON null value).
I found that you could remove a Feature "properties" property and still have the format validated.
Such property can be null or any object, possibly empty, but should always be there.
Delete line 609 to 611 in test/GeoJSON.integration.js: all tests are still successful.
Despite using mongoose.Error()
when I use the Schema Types in another project I get this:
Unhandled rejection ValidationError: CastError: Cast to Point failed for value "[object Object]" at path "loc"
and no 'reason' which is less than helpful since I can't see why my object is not passing. Building a custom error seems unnecessarily onerous (Automattic/mongoose#4113).
Thoughts @markstos ?
.../node_modules/mongoose/lib/schema.js:317
throw new TypeError('Invalid value for schema path `' + prefix + key + '`');
^
TypeError: Invalid value for schema path `location`
mongodb: 3.4.10
mongoose: 5.0.4
mongoose-geojson-schema: 2.1.2
Hi, ive just started using this library so no doubt this is a dumb question but I was wondering what the correct way(s) to create geospatial indices using these schema is/are?
This package currently works by performing side effects. That definitely discourages its usage. I'm going to look for alternatives now, but I would have definitely used this package if there was a way to require/import it without modifying other stuff.
There's no need to break any existing code. My suggestion is to have a types/
folder, with each separate type as a file, that doesn't modify anything, but rather just exports the type, so you can import all of them through const geoJsonTypes = require('mongoose-geojson-schema/types')
, or only Point
through const Point = require('mongoose-geojson-schema/types/Point')
.
The way I would more commonly use it is const { Point, Polygon } = require('mongoose-geojson-schema/types');
I would be happy to write up a PR for this, I just want to make sure it wouldn't get rejected because of philosophical reasons
Hi, I'm new to this module so I'm not sue if it is my mistake or the readme.
If I try:
any: { type: "Point", point: [-113.806458, 44.847784] }
as in the readme, the result is this error...
ValidationError: CastError: Cast to GeoJSON failed for value "{ type: 'Point', point: [ -113.806458, 44.847784 ] }" at path "any"
It works fine if I change to
any: { type: "Point", coordinate: [-113.806458, 44.847784] }
Am I doing something wrong, is the readme incorrect?
I'm trying to add the following object to mongoose
{
"name": "Edificio Roberto Franco",
"key": "Gb",
"address": {
"line1": "Cra. 1 # 18A - 12",
"city": "Santa Fe",
"state": "Bogotá DC",
"country": "Colombia",
"geolocation": {
"coordinates": [
-74.06639482,
4.601515
],
"type": "Point"
}
},
"polygon": {
"type": "Feature",
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "Polygon",
"coordinates": [
[
[
-74.065899,
4.601595,
0
],
[
-74.066125,
4.601672,
0
],
[
-74.066135,
4.601643,
0
],
[
-74.066159,
4.601566,
0
],
[
-74.066158,
4.601566,
0
],
[
-74.065986,
4.601464,
0
],
[
-74.065942,
4.601531,
0
],
[
-74.065928,
4.601532,
0
],
[
-74.065928,
4.601552,
0
],
[
-74.065899,
4.601595,
0
]
]
]
},
{
"type": "Polygon",
"coordinates": [
[
[
-74.065993,
4.601765,
0
],
[
-74.066032,
4.601641,
0
],
[
-74.065899,
4.601595,
0
],
[
-74.065854,
4.601661,
0
],
[
-74.065993,
4.601765,
0
]
]
]
}
]
},
"properties": {
"styleUrl": "#poly-FFEA00-1200-76",
"styleHash": "-26c96a1f",
"styleMapHash": {
"normal": "#poly-FFEA00-1200-76-normal",
"highlight": "#poly-FFEA00-1200-76-highlight"
},
"description": "FID 30 <br> OBJECTID_1 31 <br> BLOQUE Gb <br> FOTO c:\\proyectos\\sigcampus\\graficos\\imagenes\\bloques\\Gb.jpg <br> AREA 556,780195 <br> PERIMETER 137,657 <br> HECTARES 0,056 <br> Sotanos <br> Shape_Leng 137,657271 <br> Tratamient reestructuración <br> mov_reduci Completa <br> AREA_ÚTIL 2686 <br> FID_sala_s 0 <br> Name <br> FID_Bloque 0 <br> USO <br> Oport_2048 <br> existente <br> Estrategia <br> tipo <br> FID_bloq_1 0 <br> BLOQUE_1 <br> FOTO_1 <br> AREA_1 0 <br> PERIMETE_1 0 <br> HECTARES_1 0 <br> Sotanos_1 <br> TIPO_1 <br> Demolicion <br> Shape_Le_1 0 <br> Shape_Ar_1 0 <br> FID_Bloq_2 0 <br> BLOQUE_12 <br> FOTO_12 <br> AREA_12 0 <br> PERIMETE_2 0 <br> HECTARES_2 0 <br> Sotanos_12 <br> Shape_Le_2 0 <br> Shape_Ar_2 0 <br> BLOQUE_PRO <br> Nombre <br> bloque_id <br> Estado <br> FID_Bloq_3 0 <br> OBJECTID_2 0 <br> BLOQUE__13 <br> FOTO_12_13 <br> AREA_12_13 0 <br> PERIMETE_3 0 <br> HECTARES_3 0 <br> Sotanos_13 <br> Shape_Le_3 0 <br> Shape_Ar_3 0 <br> Tratamie_1 <br> mov_redu_1 <br> USO_1 <br> Oport_2049 <br> existent_1 <br> Estrateg_1 <br> tipo_12 <br> Shape_Le_4 137,657201",
"stroke": "#ffea00",
"stroke-opacity": 1,
"stroke-width": 1.2,
"fill": "#ffea00",
"fill-opacity": 0.2980392156862745
}
},
"entrypoints": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-74.065987,
4.60144,
0
]
},
"properties": {
"name": "Conexión B - Gb",
"styleUrl": "#icon-1739-BDBDBD-labelson",
"styleHash": "-312153aa",
"icon": "http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png",
"description": "Conexión B - Gb <br> <br> FID 266 <br> NOMBRE Conexión B - Gb <br> PISO 0 <br> BLOQUE TRANS <br> AREA 21,078034 <br> CONCENTRAC 0 <br> CAP 0"
}
}
]
}
}
This is the Schema:
{
name: {
type: String,
required: true
},
key: {
type: String,
required: true
},
address: {
type: Schema.Types.Mixed,
ref: 'Address',
required: true
},
polygon: {
type: Schema.Types.Feature,
required: true
},
innerNodes: Schema.Types.FeatureCollection,
entrypoints: {
type: Schema.Types.FeatureCollection,
required: true
}
}
And I'm getting the following error:
2018-04-11T18:18:36-0500 <error> migrate.js:422 (require.then.then.catch.e) { ValidationError: Building validation failed: polygon: Cast to Feature failed for value "{ type: 'Feature',
geometry:
{ type: 'GeometryCollection',
geometries: [ [Object], [Object] ] },
properties:
{ styleUrl: '#poly-FFEA00-1200-76',
styleHash: '-26c96a1f',
styleMapHash:
{ normal: '#poly-FFEA00-1200-76-normal',
highlight: '#poly-FFEA00-1200-76-highlight' },
description: 'FID 30',
stroke: '#ffea00',
'stroke-opacity': 1,
'stroke-width': 1.2,
fill: '#ffea00',
'fill-opacity': 0.2980392156862745 } }" at path "polygon"
at ValidationError.inspect (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/error/validation.js:57:23)
at formatValue (util.js:430:38)
at Object.inspect (util.js:324:10)
at Object.exports.format (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/tracer/lib/utils.js:22:22)
at logMain (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/tracer/lib/console.js:49:25)
at Object._self.(anonymous function) [as error] (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/tracer/lib/console.js:140:12)
at require.then.then.catch.e (/Users/pa.dorado/Documents/Development/AgentOwl/api/scripts/database/migrate.js:422:9)
at <anonymous>:null:null
at process._tickCallback (internal/process/next_tick.js:188:7)
errors:
{ polygon:
{ CastError: Cast to Feature failed for value "{ type: 'Feature',
geometry:
{ type: 'GeometryCollection',
geometries: [ [Object], [Object] ] },
properties:
{ styleUrl: '#poly-FFEA00-1200-76',
styleHash: '-26c96a1f',
styleMapHash:
{ normal: '#poly-FFEA00-1200-76-normal',
highlight: '#poly-FFEA00-1200-76-highlight' },
description: 'FID 30',
stroke: '#ffea00',
'stroke-opacity': 1,
'stroke-width': 1.2,
fill: '#ffea00',
'fill-opacity': 0.2980392156862745 } }" at path "polygon"
at new CastError (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/error/cast.js:27:11)
at model.$set (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/document.js:773:7)
at model._handleIndex (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/document.js:594:14)
at model.$set (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/document.js:554:24)
at model.Document (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/document.js:83:12)
at model.Model (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/model.js:56:12)
at new model (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/model.js:3921:13)
at /Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/model.js:2062:22
at /Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/node_modules/async/internal/parallel.js:27:9
at eachOfArrayLike (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/node_modules/async/eachOf.js:57:9)
at exports.default (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/node_modules/async/eachOf.js:9:5)
at _parallel (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/node_modules/async/internal/parallel.js:26:5)
at parallelLimit (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/node_modules/async/parallel.js:85:26)
at /Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/model.js:2078:5
at new Promise (<anonymous>:null:null)
at Function.create (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/model.js:2033:17)
at Function.Schema.statics.insert (/Users/pa.dorado/Documents/Development/AgentOwl/api/plugins/crud_mongoose.js:34:39)
at BoolJSComponent.insert (/Users/pa.dorado/Documents/Development/AgentOwl/api/plugins/crud_dao.js:25:27)
at MigrationHistory.0.15.0 (/Users/pa.dorado/Documents/Development/AgentOwl/api/scripts/database/migrate.js:18:32)
at <anonymous>:null:null
at process._tickCallback (internal/process/next_tick.js:188:7)
message: 'Cast to Feature failed for value "{ type: \'Feature\',\n geometry: \n { type: \'GeometryCollection\',\n geometries: [ [Object], [Object] ] },\n properties: \n { styleUrl: \'#poly-FFEA00-1200-76\',\n styleHash: \'-26c96a1f\',\n styleMapHash: \n { normal: \'#poly-FFEA00-1200-76-normal\',\n highlight: \'#poly-FFEA00-1200-76-highlight\' },\n description: \'FID 30\',\n stroke: \'#ffea00\',\n \'stroke-opacity\': 1,\n \'stroke-width\': 1.2,\n fill: \'#ffea00\',\n \'fill-opacity\': 0.2980392156862745 } }" at path "polygon"',
name: 'CastError',
stringValue: '"{ type: \'Feature\',\n geometry: \n { type: \'GeometryCollection\',\n geometries: [ [Object], [Object] ] },\n properties: \n { styleUrl: \'#poly-FFEA00-1200-76\',\n styleHash: \'-26c96a1f\',\n styleMapHash: \n { normal: \'#poly-FFEA00-1200-76-normal\',\n highlight: \'#poly-FFEA00-1200-76-highlight\' },\n description: \'FID 30\',\n stroke: \'#ffea00\',\n \'stroke-opacity\': 1,\n \'stroke-width\': 1.2,\n fill: \'#ffea00\',\n \'fill-opacity\': 0.2980392156862745 } }"',
kind: 'Feature',
value: [Object],
path: 'polygon',
reason: [Object] } },
_message: 'Building validation failed',
name: 'ValidationError' }
I have:
"mongoose": "^4.4.12",
When I'm trying to do something like that:
MyModel.find({
myLocField: {
$geoIntersects: {
$geometry: {
type: 'Point' ,
coordinates: [32.694865977875075, 35.293922424316406]
}
}
}
});
I'm getting:
Unhandled rejection Error: Can't use $geoIntersects
at SchemaType.castForQuery (/xxx/node_modules/mongoose/lib/schematype.js:875:13)
at cast (/xxx/node_modules/mongoose/lib/cast.js:169:39)
at Query.cast (/xxx/node_modules/mongoose/lib/query.js:2575:10)
I solved this, implementing:
GeoJSON.prototype.castForQuery = function ($cond, val) {
if (arguments.length === 2) {
return val;
}
return $cond;
}
If you think, it's good enough, you can put it to the code, and do the same for other classes.
There is a workaround, without changing the module:
mongoose.SchemaType.prototype.$conditionalHandlers.$geoIntersects = ($cond, val) => {
if (arguments.length === 2) {
return val;
}
return $cond;
};
But you'll need to do this for every additional condition you want to support, and you need to understand possible impact of this way.
Hi!
It could be a behance the "typescript" implementation?
i suggest that would be nice if we could add index to schema.
What you guys think?
The object I am trying to persist :
{ rating:
{ type: 'Feature',
geometry: { coordinates: [Object], type: 'Point' },
properties: { Typ: 'Velo', currentRating: '2' } },
created_at: Thu Dec 10 2015 19:14:28 GMT+0100 (W. Europe Standard Time),
updated_at: Thu Dec 10 2015 19:14:28 GMT+0100 (W. Europe Standard Time),
_id: 5669c104018a6b5c1009d4c1,
htmlverified: 'Nope (Thanks for spamming my map...)',
location: [ 4.482, 27.372 ],
favlang: 'asda sd',
age: 99,
gender: 'What's it to ya?',
username: 'asdad' }
The error I recieve:
{ [MongoError: Can't extract geo keys: { _id: ObjectId('5669c104018a6b5c1009d4c1'), username: "asdad", gender: "What's it to ya?", age: 99, favlang: "asda sd", location: [ 4.482, 27.372 ], htmlverified: "Nope (Thanks for spamming my map...)", updated_at: new Date(1449771268368), created_at: new Date
(1449771268329), rating: { properties: { currentRating: "2", Typ: "Velo" }, geometry: { type: "Point", coordinates: [ "4.482", "27.372" ] }, type: "Feature" }, __v: 0 } unknown GeoJSON type: { properties: { currentRating: "2", Typ: "Velo" }, geometry: { type: "Point", coordinates: [ "4.482", "27.37
2" ] }, type: "Feature" }]
name: 'MongoError',
message: 'Can't extract geo keys: { _id: ObjectId('5669c104018a6b5c1009d4c1'), username: "asdad", gender: "What's it to ya?", age: 99, favlang: "asda sd", location: [ 4.482, 27.372 ], htmlverified: "Nope (Thanks for spamming my map...)", updated_at: new Date(1449771268368), created_at: new Dat
e(1449771268329), rating: { properties: { currentRating: "2", Typ: "Velo" }, geometry: { type: "Point", coordinates: [ "4.482", "27.372" ] }, type: "Feature" }, __v: 0 } unknown GeoJSON type: { properties: { currentRating: "2", Typ: "Velo" }, geometry: { type: "Point", coordinates: [ "4.482", "27.3
72" ] }, type: "Feature" }',
driver: true,
code: 16755,
My mongoose Schema:
var UserSchema = new mongoose.Schema({
rating:GeoJSON.Feature,
username: {type: String, required: true},
gender: {type: String, required: true},
age: {type: Number, required: true},
favlang: {type: String, required: true},
location: {type: [Number], required: true}, // [Long, Lat]
htmlverified: String,
created_at: {type: Date, default: Date.now},
updated_at: {type: Date, default: Date.now}
});
On building my Typescript app, I noticed the following errors when running tsc
:
yarn run v1.12.3
$ rm -rf dist && tsc
node_modules/@types/mongoose-geojson-schema/node_modules/@types/mongoose/index.d.ts:55:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: NativeBuffer, NativeDate, NativeError, Mongoose, CastError, ConnectionBase, Connection, Error, VirtualType, Schema, MongooseDocument, Subdocument, Array, DocumentArray, Buffer, ObjectIdConstructor, Decimal128, Embedded, Query, DocumentQuery, mquery, Aggregate, SchemaType
55 declare module "mongoose" {
~~~~~~~
node_modules/@types/mongoose/index.d.ts:55:1
55 declare module "mongoose" {
~~~~~~~
Conflicts are in this file.
node_modules/@types/mongoose-geojson-schema/node_modules/@types/mongoose/index.d.ts:84:14 - error TS2403: Subsequent variable declarations must have the same type. Variable 'SchemaTypes' must be of type 'typeof Types', but here has type 'typeof Types'.
84 export var SchemaTypes: typeof Schema.Types;
~~~~~~~~~~~
node_modules/@types/mongoose-geojson-schema/node_modules/@types/mongoose/index.d.ts:1086:5 - error TS2374: Duplicate string index signature.
1086 [path: string]: SchemaTypeOpts<any> | Schema | SchemaType;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@types/mongoose-geojson-schema/node_modules/@types/mongoose/index.d.ts:1218:5 - error TS2374: Duplicate string index signature.
1218 [other: string]: any;
~~~~~~~~~~~~~~~~~~~~~
Apparently, the typings of this package goes into conflict with those of mongoose
itself. How to resolve this? Is this a bug in the typings of this package? Or a misconfiguration on my part? It's not clear to me at this point.
I was trying out the sample code on version 2.1.2 and I keep getting the following error
Typeerror: GeoJSON is not a constructor
var test = new GeoJSON({
any: {
type: "Point",
point: [-113.806458, 44.847784]
},
point: {
type: "Point",
coordinates: [12.123456, 13.134578]
}
});
I also tried the following
var pointData = {
point: {
type: "Point",
coordinates: [12.123456, 13.134578]
}
};
var geoLocation= new GeoJSON(pointData);
..\data\node_modules\mongoose\lib\schema\array.js:58
this.caster = new caster(null, castOptions);
^
TypeError: string is not a function
at new SchemaArray (\data\node_modules\mongoose\lib\schema\array.js:58:19)
at Function.Schema.interpretAsType (..\data\node_modules\mongoose\lib\schema.js:350:12)
at Schema.path (..\data\node_modules\mongoose\lib\schema.js:305:29)
at Schema.add (..\data\node_modules\mongoose\lib\schema.js:217:12)
at Schema.add (..\data\node_modules\mongoose\lib\schema.js:212:14)
at new Schema (..\data\node_modules\mongoose\lib\schema.js:73:10)
at Mongoose.Schema (..\data\node_modules\mongoose\lib\schema.js:53:12)
at Object.
Not sure if this is related to #13.
My schema is:
const MySchema = new mongoose.Schema({
name: {
type: String,
required: true
},
points: [mongoose.Schema.Types.Feature]
});
MySchema.index({ 'points.geometry': '2dsphere' });
I can query it in mogodb:
db.myCollection.find({"points.geometry": {$nearSphere: {$geometry: {type: "Point", coordinates: [8.66, 50.10] }}}})
Querying it with mongoose throws an error.
query.points = {
geometry: {
$nearSphere: {
$geometry: {
type: 'Point',
coordinates: [lon, lat]
}
}
}
};
return this.find(query) // ...
→ Error: Feature must have a type
I can work around all the validation errors by adding missing properties to the query:
query.points = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [1, 1],
$nearSphere: {
$geometry: {
type: 'Point',
coordinates: [lon, lat]
}
}
}
};
return this.find(query) // ...
But this, of course, does not return any results as long as I don't have a point at [1, 1]
.
How should I query in this case?
This issue is explained upstream: Automattic/mongoose#4113
@joshkopecek Would you mind testing a code update that throws a different type of error besides CastError
to see if that exposes the raw error messages?
Maybe a MongooseError ?
I've just realised something quite obvious:
If we instead used mongoose.SchemaTypes.GeoJSON
and did all the validation using the type
parameter we'd avoid polluting the SchemaTypes object with all the separate GeoJSON types. What do you think @markstos ?
I've been doing a bit of work on a GeoJSON schema and I could merge some of the validation work I've been doing?
I am using
mongoose 4.11.6
express 4.15.4
node 8.2.1
Everything seems great, however when I make a post request which is delivering JSON it comes up with error because it's not parsing the JSON.
I have cloned the repo and made some changes to account for this. Do you have any contributing guidelines to follow? Should I checkout a new branch and request a pull?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.