MongoDB records the data of the field location information, and how to aggregate the data to obtain the query results

  mongodb, question

The vehicle monitoring project records the GPS positioning data of the vehicle. When we detected the expressways in Zhejiang Province, the GPS thermal diagram showed that the result became as follows, as shown in the figure:
图片描述

In MongoDB, the format for storing data is as follows
{

"_id" : ObjectId("593e58b8d1eece32080d6632"),
 "x" : 121.494230074275,
 "y" : 29.6998736880818

}

After passing the query, the returned json format is as follows:

{“lng”:”121.98826732480999624″,”lat”:”29.88628748150999925″,”count”:1},{“lng”:”122.00810540175000085″,”lat”:”29.82699952501900142″,”count”:1}, {“lng”:”122.00148151521000273″,”lat”:”29.82556419141700133″,”count”:1},{“lng”:”122.09566082377000384″,”lat”:”29.86581727309599898″,”count”:1}, {“lng”:”121.99538599286999840″,”lat”:”29.82299558164600128″,”count”:1},{“lng”:”121.98481996031999586″,”lat”:”29.81670171825599880″,”count”:1}, {“lng”:”121.97925141116000702″,”lat”:”29.81335324424399857″,”count”:1},{“lng”:”121.96654822066000179″,”lat”:”29.80203305154499915″,”count”:1}, {“lng”:”121.96121962927000482″,”lat”:”29.79876428024099866″,”count”:1},{“lng”:”121.94649301222000304″,”lat”:”29.79243430893799882″,”count”:1}, {“lng”:”121.94300499519999903″,”lat”:”29.79132642105500040″,”count”:1},{“lng”:”121.93624256578000598″,”lat”:”29.79261412193099900″,”count”:1}, {“lng”:”121.92976345401000060″,”lat”:”29.79086531288499984″,”count”:1},{“lng”:”121.91419359308000026″,”lat”:”29.78270234553000151″,”count”:1}

Excuse me, what kind of query method can you use to aggregate the data of a point and get the query result? The following count value is the aggregated value. It is similar to group by in mysql, but this is not a simple group by. I don’t know what solution there is.

Personal understanding is that one idea is to divide many areas in the map and count the number of locations ($geowithin) that fall in each area.

For reference.

Love MongoDB! Have fun!