Skip to content

Commit 4a77a21

Browse files
committed
BREAKING CHANGE: remove use$geoWithin, always use $geoWithin over $within
1 parent 7ece3ec commit 4a77a21

2 files changed

Lines changed: 10 additions & 33 deletions

File tree

lib/mquery.js

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,6 @@ function Query(criteria, options) {
5858
}
5959
}
6060

61-
/**
62-
* This is a parameter that the user can set which determines if mquery
63-
* uses $within or $geoWithin for queries. It defaults to true which
64-
* means $geoWithin will be used. If using MongoDB < 2.4 you should
65-
* set this to false.
66-
*
67-
* @api public
68-
* @property use$geoWithin
69-
*/
70-
71-
let $withinCmd = '$geoWithin';
72-
Object.defineProperty(Query, 'use$geoWithin', {
73-
get: function() { return $withinCmd == '$geoWithin'; },
74-
set: function(v) {
75-
if (true === v) {
76-
// mongodb >= 2.4
77-
$withinCmd = '$geoWithin';
78-
} else {
79-
$withinCmd = '$within';
80-
}
81-
}
82-
});
83-
8461
/**
8562
* Converts this query to a constructor function with all arguments and options retained.
8663
*
@@ -732,7 +709,7 @@ Query.prototype.elemMatch = function() {
732709
Query.prototype.within = function within() {
733710
// opinionated, must be used after where
734711
this._ensurePath('within');
735-
this._geoComparison = $withinCmd;
712+
this._geoComparison = '$geoWithin';
736713

737714
if (0 === arguments.length) {
738715
return this;
@@ -800,7 +777,7 @@ Query.prototype.box = function() {
800777
}
801778

802779
const conds = this._conditions[path] || (this._conditions[path] = {});
803-
conds[this._geoComparison || $withinCmd] = { $box: box };
780+
conds[this._geoComparison || '$geoWithin'] = { $box: box };
804781
return this;
805782
};
806783

@@ -834,7 +811,7 @@ Query.prototype.polygon = function() {
834811
}
835812

836813
const conds = this._conditions[path] || (this._conditions[path] = {});
837-
conds[this._geoComparison || $withinCmd] = { $polygon: val };
814+
conds[this._geoComparison || '$geoWithin'] = { $polygon: val };
838815
return this;
839816
};
840817

@@ -882,7 +859,7 @@ Query.prototype.circle = function() {
882859
? '$centerSphere'
883860
: '$center';
884861

885-
const wKey = this._geoComparison || $withinCmd;
862+
const wKey = this._geoComparison || '$geoWithin';
886863
conds[wKey] = {};
887864
conds[wKey][type] = [val.center, val.radius];
888865

test/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,33 +546,33 @@ describe('mquery', function() {
546546
describe('of length 1', function() {
547547
it('delegates to circle when center exists', function() {
548548
const m = mquery().where('loc').within({ center: [10, 10], radius: 3 });
549-
assert.deepEqual({ $within: { $center: [[10, 10], 3] } }, m._conditions.loc);
549+
assert.deepEqual({ $geoWithin: { $center: [[10, 10], 3] } }, m._conditions.loc);
550550
});
551551
it('delegates to box when exists', function() {
552552
const m = mquery().where('loc').within({ box: [[10, 10], [11, 14]] });
553-
assert.deepEqual({ $within: { $box: [[10, 10], [11, 14]] } }, m._conditions.loc);
553+
assert.deepEqual({ $geoWithin: { $box: [[10, 10], [11, 14]] } }, m._conditions.loc);
554554
});
555555
it('delegates to polygon when exists', function() {
556556
const m = mquery().where('loc').within({ polygon: [[10, 10], [11, 14], [10, 9]] });
557-
assert.deepEqual({ $within: { $polygon: [[10, 10], [11, 14], [10, 9]] } }, m._conditions.loc);
557+
assert.deepEqual({ $geoWithin: { $polygon: [[10, 10], [11, 14], [10, 9]] } }, m._conditions.loc);
558558
});
559559
it('delegates to geometry when exists', function() {
560560
const m = mquery().where('loc').within({ type: 'Polygon', coordinates: [[10, 10], [11, 14], [10, 9]] });
561-
assert.deepEqual({ $within: { $geometry: { type: 'Polygon', coordinates: [[10, 10], [11, 14], [10, 9]] } } }, m._conditions.loc);
561+
assert.deepEqual({ $geoWithin: { $geometry: { type: 'Polygon', coordinates: [[10, 10], [11, 14], [10, 9]] } } }, m._conditions.loc);
562562
});
563563
});
564564

565565
describe('of length 2', function() {
566566
it('delegates to box()', function() {
567567
const m = mquery().where('loc').within([1, 2], [2, 5]);
568-
assert.deepEqual(m._conditions.loc, { $within: { $box: [[1, 2], [2, 5]] } });
568+
assert.deepEqual(m._conditions.loc, { $geoWithin: { $box: [[1, 2], [2, 5]] } });
569569
});
570570
});
571571

572572
describe('of length > 2', function() {
573573
it('delegates to polygon()', function() {
574574
const m = mquery().where('loc').within([1, 2], [2, 5], [2, 4], [1, 3]);
575-
assert.deepEqual(m._conditions.loc, { $within: { $polygon: [[1, 2], [2, 5], [2, 4], [1, 3]] } });
575+
assert.deepEqual(m._conditions.loc, { $geoWithin: { $polygon: [[1, 2], [2, 5], [2, 4], [1, 3]] } });
576576
});
577577
});
578578
});

0 commit comments

Comments
 (0)