Comparing version 0.3.1 to 0.3.2
0.3.2 / 2013-09-06 | ||
================== | ||
* added; geometry support for near() | ||
0.3.1 / 2013-08-22 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -865,2 +865,4 @@ 'use strict'; | ||
* query.near('loc', { center: [10, 10], maxDistance: 5 }); | ||
* query.near({ center: { type: 'Point', coordinates: [..] }}) | ||
* query.near().geometry({ type: 'Point', coordinates: [..] }) | ||
* | ||
@@ -877,7 +879,11 @@ * @param {String} [path] | ||
if (1 === arguments.length) { | ||
this._geoComparison = '$near'; | ||
if (0 === arguments.length) { | ||
return this; | ||
} else if (1 === arguments.length) { | ||
this._ensurePath('near'); | ||
path = this._path; | ||
val = arguments[0]; | ||
} else if (arguments.length === 2) { | ||
} else if (2 === arguments.length) { | ||
path = arguments[0]; | ||
@@ -889,8 +895,8 @@ val = arguments[1]; | ||
if (!val.center) | ||
if (!val.center) { | ||
throw new Error('center is required'); | ||
} | ||
var conds = this._conditions[path] || (this._conditions[path] = {}); | ||
var type = val.spherical | ||
@@ -900,7 +906,8 @@ ? '$nearSphere' | ||
// center could be a GeoJSON object or an Array | ||
if (Array.isArray(val.center)) { | ||
conds[type] = val.center; | ||
} else { | ||
if (!val.center.type && val.center.type == 'Point' | ||
|| !val.center.coordinates) { | ||
// GeoJSON? | ||
if (val.center.type != 'Point' || !Array.isArray(val.center.coordinates)) { | ||
throw new Error(util.format("Invalid GeoJSON specified for %s", type)); | ||
@@ -912,7 +919,8 @@ } | ||
var radius = 'maxDistance' in val | ||
? val.maxDistance | ||
: null; | ||
? val.maxDistance | ||
: null; | ||
if (null != radius) | ||
if (null != radius) { | ||
conds.$maxDistance = radius; | ||
} | ||
@@ -1000,4 +1008,5 @@ return this; | ||
'$geoWithin' == this._geoComparison || | ||
'$near' == this._geoComparison || | ||
'$geoIntersects' == this._geoComparison)) { | ||
throw new Error('geometry() must come after either `within()` or `intersects()`'); | ||
throw new Error('geometry() must come after `within()`, `intersects()`, or `near()'); | ||
} | ||
@@ -1004,0 +1013,0 @@ |
{ | ||
"name": "mquery", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Expressive query building for MongoDB", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -387,5 +387,8 @@ #mquery | ||
query.where('loc').intersects().geometry({ type: 'Point', coordinates: polyC }) | ||
// or | ||
query.where('loc').near().geometry({ type: 'Point', coordinates: [3,5] }) | ||
``` | ||
`geometry()` **must** come after either `intersects()` or `within()`. | ||
`geometry()` **must** come after `intersects()`, `within()`, or `near()`. | ||
@@ -533,2 +536,7 @@ The `object` argument must contain `type` and `coordinates` properties. | ||
// GeoJSON | ||
query.where('loc').near({ center: { type: 'Point', coordinates: [10, 10] }}); | ||
query.where('loc').near({ center: { type: 'Point', coordinates: [10, 10] }, maxDistance: 5, spherical: true }); | ||
query.where('loc').near().geometry({ type: 'Point', coordinates: [10, 10] }); | ||
// For a $nearSphere condition, pass the `spherical` option. | ||
@@ -535,0 +543,0 @@ query.near({ center: [10, 10], maxDistance: 5, spherical: true }); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
179379
4865
980