使用mongodb地理位置索引查询,延时索引
2020-07-18 05:24
1126 查看
下面使用的mongdb图形化界面工具Robo 3T 1.3.1
数据库需要有对应的地理位置索引字段
查看索引
loc字段为一个长度为2的数组,代表当前数据的地理位置X, Y 坐标
索引类型: 2dsphere (地理位置索引)
应用场景推荐: 根据用户坐标查找附近店铺或商家
在Java中通过给定的位置坐标,查询出数据库20公里范围内的数据
Aggregation aggregation = Aggregation.newAggregation( Aggregation.geoNear( NearQuery.near(new Point(longitude, latitude)) //坐标数据 .maxDistance(20, Metrics.KILOMETERS) //查找范围(半径),单位公里 .inKilometers() .spherical(true), "distance"), Aggregation.match(Criteria.where("status").is(1)), Aggregation.match(Criteria.where("category_id").is(categoryId)), Aggregation.match(Criteria.where("name").regex(".*?" + name + ".*", "i")), //模糊查询,匹配正则表达式 Aggregation.skip(Long.valueOf((page - 1) * rows)), Aggregation.limit(rows) /** * @param aggregation :封装的查询条件 * @param "db_gpo_sales" :索要查询的目标数据空 * @param DbGpoSales.class :封装查询结果的实体类 * @return :所有范围内的数据 */ AggregationResults<DbGpoSales> results = mongoTemplate.aggregate(aggregation, "db_gpo_sales", DbGpoSales.class);
数据库添加延时索引创建
右键点击Indexes
在高级选项里勾选延时索引,设置超时时间(单位:秒)
应用场景推荐: 用户下单,超过半小时未支付,自动取消订单
相关文章推荐
- MongoDB的地理位置查询,以及和mysql的使用对比
- MongoDB的地理位置查询,以及和mysql的使用对比
- 获取客户IP并查询IP的地理位置(使用淘宝IP地址库)
- MongoDB 地理位置索引
- python使用在线API查询IP对应的地理位置信息实例
- mongodb的地理位置索引
- MongoDB的地理位置搜索GeoSearch使用方法探索
- mongodb地理位置索引实现原理
- 图解 MongoDB 地理位置索引的实现原理
- 图解 MongoDB 地理位置索引的实现原理(转)
- MongoDB 创建地图索引及根据位置坐标查询地点小例子
- mongodb地理位置索引实现原理
- mongodb的地理位置索引
- 使用html5 地理位置技术 和 百度地图api查询当前位置
- MongoDB 地理位置索引的实现原理
- 连接mongodb,查询地理位置的问题
- 使用mongodb提供的dotnet core sdk进行地理位置运算
- mongodb 的查询如何使用索引
- mongoDb地理空间索引和查询
- Mongodb 地理位置索引