Answer the question
In order to leave comments, you need to log in
How to properly search for documents by city/country using MongoDB and GoogleMaps APIv3?
I am implementing a system for storing and searching ads like Airbnb and using MongoDB as a database. In the ad itself, I store the latitude / longitude coordinates that the user specifies using GoogleMaps Places Autocomplete
and the document data in the database looks like this:
{
"_id": {
"$oid": "54f34c8bbb465c1d119bef49"
},
"author": {
"$oid": "54ea447c23f6f81f676083c9"
},
'Заголовок объявления',
"location": {
"name": "Санкт-Петербург, Россия",
"loc": [
30.335098600000038,
59.9342802
]
},
"created_at": {
"$date": "2015-03-01T17:29:47.603Z"
},
"__v": 0
}
Answer the question
In order to leave comments, you need to log in
You need to have a polygon in geoJSON format that represents the outlines of Russia, and select those documents that fall into it using $geoWithin . If this turns out to be too long a query, you can select by ownership of the bounding box first.
Where to store this polygon is the tenth thing, even in the same mong in another collection, even just in jason. These polygons can be taken by downloading the vector outlines of countries in .shp and converting them using qgis, it is not difficult to google.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question