MongoDb: $geoIntersects for multiple input coordinates











up vote
1
down vote

favorite












I have a list of coordinates for each of them I need to perform $geoIntersects query. For one coordinate the query looks like this:



db.polygons.find({ 
geometry: {
$geoIntersects: {
$geometry: {
type: "Point", coordinates: [24.053640, 49.812427]
}
}
}
})


The problem is that there is a list of input coordinates and for each of them I need to find a polygon. The only way I've found so far is to iterate over them in application code and execute query N times.



Is it possible to do it with one MongoDB query? If not, any ideas on how this can optimized are appreciated.










share|improve this question






















  • Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
    – lusitanica
    Nov 12 at 5:08










  • @lusitanica indeed, that works! please post an answer and I will be happy to accept it.
    – Yuriy Yunikov
    2 days ago















up vote
1
down vote

favorite












I have a list of coordinates for each of them I need to perform $geoIntersects query. For one coordinate the query looks like this:



db.polygons.find({ 
geometry: {
$geoIntersects: {
$geometry: {
type: "Point", coordinates: [24.053640, 49.812427]
}
}
}
})


The problem is that there is a list of input coordinates and for each of them I need to find a polygon. The only way I've found so far is to iterate over them in application code and execute query N times.



Is it possible to do it with one MongoDB query? If not, any ideas on how this can optimized are appreciated.










share|improve this question






















  • Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
    – lusitanica
    Nov 12 at 5:08










  • @lusitanica indeed, that works! please post an answer and I will be happy to accept it.
    – Yuriy Yunikov
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a list of coordinates for each of them I need to perform $geoIntersects query. For one coordinate the query looks like this:



db.polygons.find({ 
geometry: {
$geoIntersects: {
$geometry: {
type: "Point", coordinates: [24.053640, 49.812427]
}
}
}
})


The problem is that there is a list of input coordinates and for each of them I need to find a polygon. The only way I've found so far is to iterate over them in application code and execute query N times.



Is it possible to do it with one MongoDB query? If not, any ideas on how this can optimized are appreciated.










share|improve this question













I have a list of coordinates for each of them I need to perform $geoIntersects query. For one coordinate the query looks like this:



db.polygons.find({ 
geometry: {
$geoIntersects: {
$geometry: {
type: "Point", coordinates: [24.053640, 49.812427]
}
}
}
})


The problem is that there is a list of input coordinates and for each of them I need to find a polygon. The only way I've found so far is to iterate over them in application code and execute query N times.



Is it possible to do it with one MongoDB query? If not, any ideas on how this can optimized are appreciated.







mongodb geospatial






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 16:39









Yuriy Yunikov

3,1502247




3,1502247












  • Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
    – lusitanica
    Nov 12 at 5:08










  • @lusitanica indeed, that works! please post an answer and I will be happy to accept it.
    – Yuriy Yunikov
    2 days ago


















  • Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
    – lusitanica
    Nov 12 at 5:08










  • @lusitanica indeed, that works! please post an answer and I will be happy to accept it.
    – Yuriy Yunikov
    2 days ago
















Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
– lusitanica
Nov 12 at 5:08




Did you try with the MultiPoint geometry type and the corresponding array of coordinates pairs?
– lusitanica
Nov 12 at 5:08












@lusitanica indeed, that works! please post an answer and I will be happy to accept it.
– Yuriy Yunikov
2 days ago




@lusitanica indeed, that works! please post an answer and I will be happy to accept it.
– Yuriy Yunikov
2 days ago












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










One possible solution is replacing the Point geometry type with the MultiPoint one, and passing in the the list of input coordinates as an array.






share|improve this answer

















  • 1




    I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
    – Yuriy Yunikov
    2 days ago













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241083%2fmongodb-geointersects-for-multiple-input-coordinates%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










One possible solution is replacing the Point geometry type with the MultiPoint one, and passing in the the list of input coordinates as an array.






share|improve this answer

















  • 1




    I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
    – Yuriy Yunikov
    2 days ago

















up vote
1
down vote



accepted










One possible solution is replacing the Point geometry type with the MultiPoint one, and passing in the the list of input coordinates as an array.






share|improve this answer

















  • 1




    I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
    – Yuriy Yunikov
    2 days ago















up vote
1
down vote



accepted







up vote
1
down vote



accepted






One possible solution is replacing the Point geometry type with the MultiPoint one, and passing in the the list of input coordinates as an array.






share|improve this answer












One possible solution is replacing the Point geometry type with the MultiPoint one, and passing in the the list of input coordinates as an array.







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









lusitanica

30117




30117








  • 1




    I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
    – Yuriy Yunikov
    2 days ago
















  • 1




    I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
    – Yuriy Yunikov
    2 days ago










1




1




I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
– Yuriy Yunikov
2 days ago






I can confirm it works, the command I've used: db.polygons.find({ geometry: { $geoIntersects: { $geometry: { type: "MultiPoint", coordinates: [[24.053640, 49.812427],[...]...] } } } })
– Yuriy Yunikov
2 days ago




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241083%2fmongodb-geointersects-for-multiple-input-coordinates%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."