mongo near set maxDistance as value in collection
up vote
1
down vote
favorite
I am sorry by the title. I was hard to describe. I have this collection
{
"_id" : ObjectId("55cb9c666c522cafdb053a68"),
location: {
type: "Point",
coordinates: [-73.856077, 40.848447]
},
"maxDistancevalue" : 100000
}
Now I want to find of the current location is within: 100000 as defined is the collection by "maxDistancevalue"
The code will be like this. But how set the maxDistancevalue?
db.places.find(
{
location:
{ $near :
{
$geometry: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
$minDistance: **??????, -->maxDistancevalue**
$maxDistance: 0
}
}
}
)
javascript node.js mongodb geolocation
add a comment |
up vote
1
down vote
favorite
I am sorry by the title. I was hard to describe. I have this collection
{
"_id" : ObjectId("55cb9c666c522cafdb053a68"),
location: {
type: "Point",
coordinates: [-73.856077, 40.848447]
},
"maxDistancevalue" : 100000
}
Now I want to find of the current location is within: 100000 as defined is the collection by "maxDistancevalue"
The code will be like this. But how set the maxDistancevalue?
db.places.find(
{
location:
{ $near :
{
$geometry: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
$minDistance: **??????, -->maxDistancevalue**
$maxDistance: 0
}
}
}
)
javascript node.js mongodb geolocation
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am sorry by the title. I was hard to describe. I have this collection
{
"_id" : ObjectId("55cb9c666c522cafdb053a68"),
location: {
type: "Point",
coordinates: [-73.856077, 40.848447]
},
"maxDistancevalue" : 100000
}
Now I want to find of the current location is within: 100000 as defined is the collection by "maxDistancevalue"
The code will be like this. But how set the maxDistancevalue?
db.places.find(
{
location:
{ $near :
{
$geometry: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
$minDistance: **??????, -->maxDistancevalue**
$maxDistance: 0
}
}
}
)
javascript node.js mongodb geolocation
I am sorry by the title. I was hard to describe. I have this collection
{
"_id" : ObjectId("55cb9c666c522cafdb053a68"),
location: {
type: "Point",
coordinates: [-73.856077, 40.848447]
},
"maxDistancevalue" : 100000
}
Now I want to find of the current location is within: 100000 as defined is the collection by "maxDistancevalue"
The code will be like this. But how set the maxDistancevalue?
db.places.find(
{
location:
{ $near :
{
$geometry: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
$minDistance: **??????, -->maxDistancevalue**
$maxDistance: 0
}
}
}
)
javascript node.js mongodb geolocation
javascript node.js mongodb geolocation
asked yesterday
Wouter
11218
11218
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You can use Aggregation Framework's $geoNear pipeline stage to reference other existing field. It requires 2dsphere index to be created on your collection, so start with:
db.places.createIndex({location:"2dsphere"});
and then you can run your aggregate()
query:
db.places.aggregate([
{
$geoNear: {
near: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
distanceField: "dist.calculated",
maxDistance: "$maxDistancevalue"
}
}
])
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can use Aggregation Framework's $geoNear pipeline stage to reference other existing field. It requires 2dsphere index to be created on your collection, so start with:
db.places.createIndex({location:"2dsphere"});
and then you can run your aggregate()
query:
db.places.aggregate([
{
$geoNear: {
near: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
distanceField: "dist.calculated",
maxDistance: "$maxDistancevalue"
}
}
])
add a comment |
up vote
1
down vote
accepted
You can use Aggregation Framework's $geoNear pipeline stage to reference other existing field. It requires 2dsphere index to be created on your collection, so start with:
db.places.createIndex({location:"2dsphere"});
and then you can run your aggregate()
query:
db.places.aggregate([
{
$geoNear: {
near: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
distanceField: "dist.calculated",
maxDistance: "$maxDistancevalue"
}
}
])
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can use Aggregation Framework's $geoNear pipeline stage to reference other existing field. It requires 2dsphere index to be created on your collection, so start with:
db.places.createIndex({location:"2dsphere"});
and then you can run your aggregate()
query:
db.places.aggregate([
{
$geoNear: {
near: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
distanceField: "dist.calculated",
maxDistance: "$maxDistancevalue"
}
}
])
You can use Aggregation Framework's $geoNear pipeline stage to reference other existing field. It requires 2dsphere index to be created on your collection, so start with:
db.places.createIndex({location:"2dsphere"});
and then you can run your aggregate()
query:
db.places.aggregate([
{
$geoNear: {
near: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
distanceField: "dist.calculated",
maxDistance: "$maxDistancevalue"
}
}
])
answered yesterday
mickl
9,76551435
9,76551435
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237982%2fmongo-near-set-maxdistance-as-value-in-collection%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password