mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
7bc7864fc0
This commit removes the geoNear command and moves its implementation into the aggregation framework. Users should use the aggregate command with a $geoNear stage. The implementation rewrite additionally removes the limit in the $geoNear aggregation stage. To limit the number of results, use a $limit stage.
49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
load('jstests/readonly/lib/read_only_test.js');
|
|
|
|
runReadOnlyTest(function() {
|
|
'use strict';
|
|
|
|
return {
|
|
name: 'geo',
|
|
|
|
load: function(writableCollection) {
|
|
assert.commandWorked(writableCollection.createIndex({loc: "2dsphere"}));
|
|
|
|
var locDocs = [
|
|
{name: "Berry Park", loc: {type: "Point", coordinates: [40.722396, -73.9573645]}},
|
|
{
|
|
name: "Northern Territory",
|
|
loc: {type: "Point", coordinates: [40.7252334, -73.9595218]}
|
|
},
|
|
{
|
|
name: "Kent Ale House",
|
|
loc: {type: "Point", coordinates: [40.7223364, -73.9614495]}
|
|
},
|
|
{name: "The Shanty", loc: {type: "Point", coordinates: [40.7185752, -73.9510538]}},
|
|
{
|
|
name: "The Counting Room",
|
|
loc: {type: "Point", coordinates: [40.7209601, -73.9588041]}
|
|
},
|
|
{name: "Kinfolk 94", loc: {type: "Point", coordinates: [40.7217058, -73.9605489]}}
|
|
];
|
|
|
|
writableCollection.insertMany(locDocs);
|
|
},
|
|
exec: function(readableCollection) {
|
|
const res = readableCollection
|
|
.aggregate([
|
|
{
|
|
$geoNear: {
|
|
near: {type: "Point", coordinates: [40.7211404, -73.9591494]},
|
|
distanceField: "dist",
|
|
spherical: true,
|
|
}
|
|
},
|
|
{$limit: 1}
|
|
])
|
|
.toArray();
|
|
assert.eq(res[0].name, "The Counting Room", printjson(res));
|
|
}
|
|
};
|
|
}());
|