Working with GPS and real time data in MongoDB
In a previous article, I spoke about my experience during the certification process. It is now time to share more details about two features that stood out for me.
GPS data : It is natively included in MongoDB (we can index the field) and it supports GeoJSON format. Complex queries are easily supported : We can find/sort the nearest documents (equivalent of row in traditional databases) to a specific coordinate, find which documents are within/intersect a specified geometry (LineString, Polygon, etc). With these filters, there is the possibility of creating additional variables that could be used in machine learning models.
We could also create an alert if a document is "far" from a specified coordinate/other documents (logic done inside the database with Change Streams, more on that in the second point).
It all depends on the use case. The documentation is available for additional details.
For even more complex queries, you can easily do side programming in Python.
The other feature uses real time streams to calculate values on new input data. IoT devices can make full usage of this feature.
Stream data in real time (Change Streams) : We can program in advance what kind of response we want to do depending on the input data (updating selected fields, use the aggregation framework).
SQL servers rarely support this feature natively, it normally needs to be through a third party application (like Kafka). The less dependencies we have, the better ! I learned this in a project where we had to rely on several external tools for the code to be running. Changing a small part of the code made another one break. Not fun !
To recap : MongoDB supports a variety of data and use cases. How we could benefit from streaming data in real time ? It is the subject of an upcoming article !