{"id":8306,"date":"2024-07-31T07:00:31","date_gmt":"2024-07-31T14:00:31","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cosmosdb\/?p=8306"},"modified":"2024-07-17T10:34:28","modified_gmt":"2024-07-17T17:34:28","slug":"transforming-fleet-operations-with-vcore-based-azure-cosmos-db-for-mongodb-geospatial-capabilities","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cosmosdb\/transforming-fleet-operations-with-vcore-based-azure-cosmos-db-for-mongodb-geospatial-capabilities\/","title":{"rendered":"Transforming Fleet Operations with vCore-based Azure Cosmos DB for MongoDB Geospatial Capabilities"},"content":{"rendered":"<p><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Header.png\"><img decoding=\"async\" class=\"aligncenter wp-image-8316 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Header.png\" alt=\"Transforming Fleet Operations with vCore based Azure Cosmos DB for MongoDB Geospatial Capabilities\" width=\"1099\" height=\"610\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Header.png 1099w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Header-300x167.png 300w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Header-1024x568.png 1024w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Header-768x426.png 768w\" sizes=\"(max-width: 1099px) 100vw, 1099px\" \/><\/a><\/p>\n<p>Efficient fleet management is essential for industries that rely on transportation, such as logistics, delivery services, and public transportation. <a href=\"https:\/\/learn.microsoft.com\/azure\/cosmos-db\/mongodb\/vcore\/introduction\" target=\"_blank\" rel=\"noopener\">vCore-based Azure Cosmos DB for MongoDB<\/a> supports enabling developers to create sophisticated geo-enabled applications with ease. Organizations can streamline fleet operations, monitor vehicle locations in real-time, and optimize routes for enhanced efficiency.<\/p>\n<h2>Scenario: Streamlining Fleet Operations<\/h2>\n<p>Imagine you are responsible for managing a fleet of vehicles in a logistics company. Geospatial data, which includes location coordinates and spatial relationships, is crucial for effective fleet management. It enables you to:<\/p>\n<ol>\n<li><strong>Track Vehicle Locations:<\/strong> Monitor where your vehicles are at any given time.<\/li>\n<li><strong>Optimize Routes:<\/strong> Find the best routes to improve delivery times and reduce fuel costs.<\/li>\n<li><strong>Monitor Fleet Efficiency:<\/strong> Analyze data to make informed decisions and improve operational efficiency.<\/li>\n<li><strong>Respond to Real-Time Events:<\/strong> Quickly locate vehicles in case of emergencies or changes in plans.<\/li>\n<\/ol>\n<p>In this tutorial, we will explore various geospatial queries and operations using vCore-based Azure Cosmos DB for MongoDB. We will walk through practical examples of how these features can be applied to manage a fleet of vehicles.<\/p>\n<h3>Data Format<\/h3>\n<p>Consider a fleet of vehicles, each transmitting location coordinates periodically. We will use a JSON object to represent a vehicle&#8217;s location as a &#8220;Point&#8221; on Earth&#8217;s surface, including a timestamp for the last update.<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"vehicle_id\": \"V1\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"type\": \"Sedan\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"location\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"type\": \"Point\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"coordinates\": [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -84.37685835556678,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 33.72763398775282\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"timestamp\": \"2024-05-09T06:01:44.078110\"\r\n}<\/code><\/pre>\n<p>To make things simple, let us consider that you have a fleet of 10 vehicles. Each vehicle is navigating one of the following predefined routes:<\/p>\n<ol>\n<li>Delhi to Mumbai<\/li>\n<li>Jaipur to Kolkata<\/li>\n<li>Hyderabad to Chennai<\/li>\n<li>Ahmedabad to Pune<\/li>\n<\/ol>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/All-Routes-1.png\"><img decoding=\"async\" class=\"alignleft size-full wp-image-8409\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/All-Routes-1.png\" alt=\"Map of India\" width=\"767\" height=\"425\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/All-Routes-1.png 767w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/All-Routes-1-300x166.png 300w\" sizes=\"(max-width: 767px) 100vw, 767px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3>Exploring Data<\/h3>\n<p>To ensure efficient query performance, let us create a 2dsphere index on the &#8220;fleet&#8221; collection:<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">db.fleet.createIndex({ \"location\": \"2dsphere\" })<\/code><\/pre>\n<p>Now that we have the data and the index defined, let us examine some queries that could be useful for your everyday operations as a fleet manager. For example, you might want to get the most recent location of a vehicle, identify all vehicles on a designated route, or locate all vehicles within a certain area, among other tasks.<\/p>\n<h3>Track the latest location of Vehicles<\/h3>\n<p>You can retrieve the most recent location of any vehicle using the query provided below. In this example, we demonstrate how to get the latest location for vehicle_id = V3. However, the same approach can be applied to obtain information for any other specific vehicle or for all vehicles in your fleet.<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">db.fleet.aggregate([\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$match\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"vehicle_id\": \"V3\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$sort\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"timestamp\": -1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$group\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"_id\": \"$vehicle_id\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"latest_record\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$first\": \"$$ROOT\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$replaceRoot\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"newRoot\": \"$latest_record\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 }\r\n])<\/code><\/pre>\n<p><span style=\"font-weight: normal !msorm;\"><strong>Result: <\/strong><\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">[\r\n\u00a0 {\r\n\u00a0\u00a0\u00a0 _id: ObjectId(\"668bc073f288fdc0919e6daf\"),\r\n\u00a0\u00a0\u00a0 vehicle_id: 'V3',\r\n\u00a0\u00a0\u00a0 type: 'Van',\r\n\u00a0\u00a0\u00a0 location: {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 type: 'Point',\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 coordinates: [ 81.54067689606191, 24.927085602346466 ]\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 timestamp: '2024-07-09T10:17:50.830400'\r\n\u00a0 }\r\n]<\/code><\/pre>\n<h3><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Latest-Location-V3-1.png\"><img decoding=\"async\" class=\"alignleft wp-image-8412\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Latest-Location-V3-1.png\" alt=\"Image Latest Location V3 1\" width=\"803\" height=\"310\" \/><\/a><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<p>&nbsp;<\/p>\n<h3>Find all Vehicles on the Jaipur to Kolkata Route<\/h3>\n<p>In this case, we are utilizing the $geoWithin operator to identify the vehicles that fall within the bounding box specified by Jaipur and Kolkata.<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">db.fleet.aggregate([\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$sort\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"timestamp\": -1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$group\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"_id\": \"$vehicle_id\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"latest_record\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$first\": \"$$ROOT\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$replaceRoot\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"newRoot\": \"$latest_record\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$match\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"location.coordinates\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$geoWithin\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$box\": [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [75.7873, 22.5726],\u00a0 \/\/ Southwest corner (Jaipur)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [88.3639, 26.9124]\u00a0\u00a0 \/\/ Northeast corner (Kolkata)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$project\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"vehicle_id\": 1,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"_id\": 0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 }\r\n])<\/code><\/pre>\n<p>Result:<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">[ { vehicle_id: 'V7' }, { vehicle_id: 'V1' }, { vehicle_id: 'V3' } ]\r\n<\/code><\/pre>\n<h3><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Jaipur-to-Kolkata.png\"><img decoding=\"async\" class=\"alignleft size-full wp-image-8418\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Jaipur-to-Kolkata.png\" alt=\"Image Jaipur to Kolkata\" width=\"842\" height=\"440\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Jaipur-to-Kolkata.png 842w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Jaipur-to-Kolkata-300x157.png 300w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2024\/07\/Jaipur-to-Kolkata-768x401.png 768w\" sizes=\"(max-width: 842px) 100vw, 842px\" \/><\/a><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<h3><\/h3>\n<p>&nbsp;<\/p>\n<h3>Find Vehicles Within a Polygon (Specific Area)<\/h3>\n<p>Similarly, the\u00a0$geoWithin\u00a0operator can be paired with\u00a0$polygon\u00a0to locate all vehicles within the boundary delineated by the polygon.<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">db.fleet.aggregate([\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$sort\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"timestamp\": -1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$group\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"_id\": \"$vehicle_id\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"latest_record\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$first\": \"$$ROOT\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$replaceRoot\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"newRoot\": \"$latest_record\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$match\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"location.coordinates\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$geoWithin\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$polygon\": [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [77.2090, 28.6139],\u00a0 \/\/ Delhi\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [72.8777, 19.0760],\u00a0 \/\/ Mumbai\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [78.4867, 17.3850],\u00a0 \/\/ Hyderabad\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [80.2785, 13.0878],\u00a0 \/\/ Chennai\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [77.2090, 28.6139]\u00a0\u00a0 \/\/ Closing point\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 }\r\n])<\/code><\/pre>\n<p><span style=\"font-weight: normal !msorm;\"><strong>Result:<\/strong><\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">[\r\n\u00a0 {\r\n\u00a0\u00a0\u00a0 _id: ObjectId(\"668bc073f288fdc0919e6db2\"),\r\n\u00a0\u00a0\u00a0 vehicle_id: 'V6',\r\n\u00a0\u00a0\u00a0 type: 'Sedan',\r\n\u00a0\u00a0\u00a0 location: {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 type: 'Point',\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 coordinates: [ 73.675490313612, 19.155134403709194 ]\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 timestamp: '2024-07-09T10:17:50.830400'\r\n\u00a0 },\r\n\u00a0 {\r\n\u00a0\u00a0\u00a0 _id: ObjectId(\"668bc073f288fdc0919e6db4\"),\r\n\u00a0\u00a0\u00a0 vehicle_id: 'V8',\r\n\u00a0\u00a0\u00a0 type: 'SUV',\r\n\u00a0\u00a0\u00a0 location: {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 type: 'Point',\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 coordinates: [ 78.99440743680374, 16.16738620525001 ]\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 timestamp: '2024-07-09T10:17:50.830400'\r\n\u00a0 }\r\n]<\/code><\/pre>\n<h3>Find the Nearest Vehicle to a Point<\/h3>\n<p>Locate the nearest vehicle to a specific point:<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">db.fleet.aggregate([\r\n\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$geoNear\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"near\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"type\": \"Point\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"coordinates\": [77.2090, 28.6139]\u00a0 \/\/ Reference point (longitude, latitude)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"distanceField\": \"distance\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"spherical\": true,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"key\": \"location\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$sort\": {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"distance\": 1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"$limit\": 1\u00a0 \/\/ Limit to the nearest vehicle\r\n\u00a0\u00a0\u00a0 }\r\n])<\/code><\/pre>\n<p><span style=\"font-weight: normal !msorm;\"><strong>Result:<\/strong><\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">[\r\n\u00a0 {\r\n\u00a0\u00a0\u00a0 _id: ObjectId(\"668bc073f288fdc0919e6b09\"),\r\n\u00a0\u00a0\u00a0 vehicle_id: 'V5',\r\n\u00a0\u00a0\u00a0 type: 'Truck',\r\n\u00a0\u00a0\u00a0 location: {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 type: 'Point',\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 coordinates: [ 77.20667999325272, 28.60879114299288 ]\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 timestamp: '2024-07-08T17:17:50.830400',\r\n\u00a0\u00a0\u00a0 distance: 611.5587173247432\r\n\u00a0 }\r\n]<\/code><strong>\u00a0<\/strong><\/pre>\n<h2>Conclusion<\/h2>\n<p>By leveraging the geospatial capabilities of vCore-based Azure Cosmos DB for MongoDB, you can build sophisticated, data-driven fleet management systems that handle real-time tracking, route optimization, and detailed operational analytics.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<h2>About Azure Cosmos DB<\/h2>\n<p>Azure Cosmos DB is a fully managed and serverless distributed database for modern app development, with SLA-backed speed and availability, automatic and instant scalability, and support for open-source PostgreSQL, MongoDB, and Apache Cassandra.\u00a0<a href=\"https:\/\/cosmos.azure.com\/try\/\" target=\"_blank\" rel=\"noopener\">Try Azure Cosmos DB for free here.<\/a>\u00a0To stay in the loop on Azure Cosmos DB updates, follow us on\u00a0<a href=\"https:\/\/twitter.com\/AzureCosmosDB\" target=\"_blank\" rel=\"noopener\">X<\/a>,\u00a0<a href=\"https:\/\/aka.ms\/AzureCosmosDBYouTube\" target=\"_blank\" rel=\"noopener\">YouTube<\/a>, and\u00a0<a href=\"https:\/\/www.linkedin.com\/company\/azure-cosmos-db\/\" target=\"_blank\" rel=\"noopener\">LinkedIn<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Efficient fleet management is essential for industries that rely on transportation, such as logistics, delivery services, and public transportation. vCore-based Azure Cosmos DB for MongoDB supports enabling developers to create sophisticated geo-enabled applications with ease. Organizations can streamline fleet operations, monitor vehicle locations in real-time, and optimize routes for enhanced efficiency. Scenario: Streamlining Fleet Operations [&hellip;]<\/p>\n","protected":false},"author":125125,"featured_media":8316,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"image","meta":{"_acf_changed":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-8306","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-core-sql-api","post_format-post-format-image"],"acf":[],"blog_post_summary":"<p>Efficient fleet management is essential for industries that rely on transportation, such as logistics, delivery services, and public transportation. vCore-based Azure Cosmos DB for MongoDB supports enabling developers to create sophisticated geo-enabled applications with ease. Organizations can streamline fleet operations, monitor vehicle locations in real-time, and optimize routes for enhanced efficiency. Scenario: Streamlining Fleet Operations [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/8306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/users\/125125"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/comments?post=8306"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/8306\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media\/8316"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media?parent=8306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/categories?post=8306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/tags?post=8306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}