Hola, podrian anadir en recursos el curso que el profesor menciona en el minuto 2:41?
Introducci贸n
Conoce el potencial de Aggregation Framework usando datos reales
Casos para usar Aggregation Framework y no queries de MongoDB o map-reduce
Preparando entorno de trabajo: configurando MongoDB Atlas y la base de datos
Preparando entorno de trabajo: Docker y Mongo Compass
Operaciones b谩sicas
Filtrando documentos con $match
Tranformando los datos con $group
Moldeamos los resultados con $project
Agregamos etapas con $count y $avg
Manipulando campos con $set
Etapas de Aggregation Framework
Trabajando con arrays y $unwind
Persistencia de datos con $out
Trabajamos y conocemos $geoNear
Consultas geoespaciales con $geoNear
Aprendemos a usar $lookup
Operaciones avanzadas
Funciones personalizadas
Evaluando expresiones con $redact
Usando funciones personalizadas con $accumulator
Agrupaciones avanzadas con $bucket y $bucketAuto
Performance y optimizaci贸n
Recomendaciones para optimizaci贸n y uso de recursos
Realizando profiling en MongoDB
Pr贸ximos pasos
Repaso de lo aprendido y recomendaciones
You don't have access to this class
Keep learning! Join and start boosting your career
Georeferenced coordinates are fundamental to spatial analysis and allow MongoDB to manage large amounts of spatial data efficiently. This integration is vital in applications that require visualizing, analyzing and manipulating location-based data, such as Airbnb does when displaying properties on a map. Using MongoDB's geolocation capabilities, which include the GeoJSON standard and the Aggregation Framework, allows you to perform complex queries quickly and accurately.
GeoJSON is a standardized data format that represents geographic geometry such as points, lines, and polygons. MongoDB supports GeoJSON, making it easy to represent and query georeferenced data. In a MongoDB collection, a document may contain a field that uses GeoJSON to store, for example, the location of a property represented as a point. The syntax of GeoJSON in MongoDB is generally structured as follows:
{ " type": "Point", " coordinates": [longitude, latitude]}
It is important to note that MongoDB requires the first coordinate to be the longitude and the second coordinate to be the latitude, something to keep in mind when working with this data.
$geoNear
operator used in MongoDB?The $geoNear
operator of the Aggregation Framework in MongoDB allows you to filter and sort documents in a collection based on their proximity to a geographic point. This operator is ideal for finding items close to a specific location within a maximum range of distance.
$geoNear
usage:To use $geoNear
, several parameters need to be defined:
near
: The reference point from which distances will be calculated.distanceField
: The field where the calculated distance will be stored.maxDistance
: The maximum distance in meters within which documents will be searched.spherical
: A boolean value that determines if the calculation should consider the curvature of the Earth.An example implementation would be:
{ $geoNear: { near: { type: { type: "Point", coordinates: [longitude, latitude] }, distanceField: "distance", maxDistance: 30000, // In meters, here a range of 30 km is used spherical: true }}
This operator returns documents that are within the specified distance from the given point, sorted by proximity.
Performing geospatial queries can be resource intensive, therefore, it is crucial to optimize these queries for better performance. Here are some tips to optimize your queries in MongoDB:
2dsphere
.maxDistance
avoids processing unnecessary documents.These techniques not only improve performance, but also ensure that georeferenced data handled in MongoDB is accurate and useful for spatial analysis. Continue exploring these concepts to enhance your skills in the fascinating field of GIS and geospatial databases!
Contributions 4
Questions 0
Hola, podrian anadir en recursos el curso que el profesor menciona en el minuto 2:41?
use("sample_airbnb")
db.listingsAndReviews.aggregate(
[
{
$geoNear: {
near: {
type: "Point",
coordinates: [
-73.95552676483872,
40.7994839486901
]
},
distanceField: "distancia",
maxDistance: 30000,
spherical: true
}
}
]
)
enlace de interes para profundizar:
https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/
https://www.practical-mongodb-aggregations.com/front-cover.html
Want to see more contributions, questions and answers from the community?