From f913baafeb1c3757f458628d2b6ddec291d2e203 Mon Sep 17 00:00:00 2001 From: Hans Kristian Flaatten Date: Sat, 6 Aug 2016 19:44:07 +0200 Subject: [PATCH] fix(near): return coordinates array with two (2) coordinates --- index.js | 6 +++--- test.js | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 74da3d6..4b488bc 100644 --- a/index.js +++ b/index.js @@ -75,16 +75,16 @@ module.exports.prototype.customNear = field => (query, point) => { $near: { $geometry: { type: 'Point', - coordinates: pointArr, + coordinates: pointArr.splice(0, 2), }, }, }; if (!isNaN(max)) { - query[field].$near.$maxDistance = parseInt(pointArr[2], 10); + query[field].$near.$maxDistance = max; if (!isNaN(min)) { - query[field].$near.$minDistance = parseInt(pointArr[3], 10); + query[field].$near.$minDistance = min; } } } diff --git a/test.js b/test.js index e950336..1fccf94 100644 --- a/test.js +++ b/test.js @@ -77,7 +77,7 @@ describe('customNear()', () => { $near: { $geometry: { type: 'Point', - coordinates: point.split(',').splice(0, 3).map(parseFloat, 10), + coordinates: point.split(',').splice(0, 2).map(parseFloat, 10), }, $maxDistance: parseInt(point.split(',')[2], 10), }, @@ -85,6 +85,26 @@ describe('customNear()', () => { }); }); }); + + it('returns $near query with max and min distance', () => { + ['0,1,2,4', '60.70908,10.37140,211.123,321.456'].forEach(point => { + const q = {}; + + mqs.customNear('geojson')(q, point); + assert.deepEqual(q, { + geojson: { + $near: { + $geometry: { + type: 'Point', + coordinates: point.split(',').splice(0, 2).map(parseFloat, 10), + }, + $maxDistance: parseInt(point.split(',')[2], 10), + $minDistance: parseInt(point.split(',')[3], 10), + }, + }, + }); + }); + }); }); describe('customAfter()', () => {