当前位置: 首页 > news >正文

广州荔湾做网站公司站长工具seo综合查询分析

广州荔湾做网站公司,站长工具seo综合查询分析,福州专业建站,网站制作论文范文$geoNear根据指定的点按照距离以由近到远的顺序输出文档。 从4.2版本开始&#xff0c;MongoDB移除了limit和num选项以及100个文档的限制&#xff0c;如果要限制结果文档的数量可以使用$limit阶段。 语法 { $geoNear: { <geoNear options> } }$geoNear操作接受一个包含…

$geoNear根据指定的点按照距离以由近到远的顺序输出文档。

从4.2版本开始,MongoDB移除了limitnum选项以及100个文档的限制,如果要限制结果文档的数量可以使用$limit阶段。

语法

{ $geoNear: { <geoNear options> } }

$geoNear操作接受一个包含了下面选项字段的文档。使用与已处理文档坐标系相同的单位指定所有距离:

|字段|类型|描述|
|-|-|
|distanceField|string|包含计算距离的输出字段,要指定内嵌文档字段可以使用点号.|
|distanceMultiplier|number|可选,查询返回的所有距离的乘数。例如,使用distanceMultiplier将球面查询返回的弧度乘以地球半径转换为公里|
|includeLocs|string|可选,指定识别位置的输出字段,用于计算距离。当位置字段包含多个位置时,该选项非常有用。要指定嵌入文档中的字段,可使用点符号.|
|key||可选,指定用于计算距离的地理空间索引字段。如果集合有多个2d或(且)2dsphere索引,就必须要使用key选项来指定要使用的索引字段路径。如果集合有超过一个的2d索引或2dsphere索引,而且没有指定一个给key,MongoDB将返回错误。如果没有指定key,而且集合只有一个2d索引或(且)2dsphere索引,MongoDB会找到第一个2d索引来使用,如果2d索引不存在,则会去找2dsphere索引来使用|
|maxDistance|number|可选,文档与中心点的最大距离。MongoDB 会将结果限制在与中心点的距离在指定范围内的文档。如果指定点是GeoJSON,则以米为单位指定距离;如果指定点是legacy坐标对,则以弧度为单位指定距离|
|near|GeoJSON点或legacy坐标对|查找最接近文件的点。如果使用2dsphere索引,可以使用GeoJSON点或legacy坐标对来指定点。如果使用2d索引,则要使用legacy坐标对来指定|
|query|document|可选,将结果限制为与查询匹配的文档。查询语法为常规MongoDB读操作查询语法。不能在$geoNear阶段的查询字段中指定$near谓词|
|spherical|boolean|可选,缺省为fasle,决定MongoDB如何计算两点间的距离。当为true是,MongoDB使用$nearSphere语义并且使用球形几何体计算距离。当为false时MongoDB 使用$near语义:球形几何用于2dsphere索引,平面几何用于2d索引|

使用

当使用$geoNear时需要考虑下面的情况:

  • $geoNear只能用于管道的第一个阶段。
  • 必须包含distanceField选项,distanceField选项指定了包含距离计算的字段。
  • $geoNear需要一个地理空间索引。如果集合上有多个地理空间索引,需要使用keys参数指定一下计算时要使用的索引,如果只有一个地理空间索引,可以不指定keys参数,$geoNear会隐式使用索引字段进行计算。
  • $geoNear阶段不可以在query字段中使用$near
  • 从版本4.2开始,$geoNear默认情况下不再限制100个文档。
  • 从版本4.1开始,near参数支持let选项和绑定let选项。
  • 从版本5.3开始,可以在时间序列集合的任何字段上使用$geoNear管道运算符。
  • 从版本6.0开始,可以在时间序列集合的任何字段上创建partial和2dsphere索引。

举例

places插入下面的数据:

db.places.insertMany( [{name: "Central Park",location: { type: "Point", coordinates: [ -73.97, 40.77 ] },category: "Parks"},{name: "Sara D. Roosevelt Park",location: { type: "Point", coordinates: [ -73.9928, 40.7193 ] },category: "Parks"},{name: "Polo Grounds",location: { type: "Point", coordinates: [ -73.9375, 40.8303 ] },category: "Stadiums"}
] )

下面的操作为location字段创建一个2dsphere索引:

db.places.createIndex( { location: "2dsphere" } )

最大距离

上面的places集合有一个2dsphere索引,下面的聚合使用$geoNear查找位置距离中心点[ -73.99279 , 40.719296 ]最多2米距离且category等于Parks的文档。

db.places.aggregate([{$geoNear: {near: { type: "Point", coordinates: [ -73.99279 , 40.719296 ] },distanceField: "dist.calculated",maxDistance: 2,query: { category: "Parks" },includeLocs: "dist.location",spherical: true}}
])

聚合返回下面的结果:

{"_id" : 8,"name" : "Sara D. Roosevelt Park","category" : "Parks","location" : {"type" : "Point","coordinates" : [ -73.9928, 40.7193 ]},"dist" : {"calculated" : 0.9539931676365992,"location" : {"type" : "Point","coordinates" : [ -73.9928, 40.7193 ]}}
}

匹配的文档包含两个新字段:

  • dist.calculated字段,包含了计算后的距离
  • dist.location字段,包含了用于计算的位置

最小距离

下面的示例使用minDistance选项来指定文档与中心点的最小距离。下面的聚合查找所有位置距离中心点[ -73.99279 , 40.719296 ]至少2米距离且category等于Parks的文档。

db.places.aggregate([{$geoNear: {near: { type: "Point", coordinates: [ -73.99279 , 40.719296 ] },distanceField: "dist.calculated",minDistance: 2,query: { category: "Parks" },includeLocs: "dist.location",spherical: true}}
])

使用let选项

在下面的例子中:

  • let选项用于将数组[-73.99279,40.719296]的值设置给变量$pt
  • pt被指定为near参数的let选项。
db.places.aggregate(
[{"$geoNear":{"near":"$$pt","distanceField":"distance","maxDistance":2,"query":{"category":"Parks"},"includeLocs":"dist.location","spherical":true}}
],
{"let":{ "pt": [ -73.99279, 40.719296 ] }
}
)

聚合返回符合下面条件的所有文档:

  • 距离let变量指定的点至少2米距离
  • category等于Parks
{_id: ObjectId("61715cf9b0c1d171bb498fd7"),name: 'Sara D. Roosevelt Park',location: { type: 'Point', coordinates: [ -73.9928, 40.7193 ] },category: 'Parks',distance: 1.4957325341976439e-7,dist: { location: { type: 'Point', coordinates: [ -73.9928, 40.7193 ] } }
},
{_id: ObjectId("61715cf9b0c1d171bb498fd6"),name: 'Central Park',location: { type: 'Point', coordinates: [ -73.97, 40.77 ] },category: 'Parks',distance: 0.0009348548688841822,dist: { location: { type: 'Point', coordinates: [ -73.97, 40.77 ] } }
}

使用绑定let选项

let选项可以绑定一个变量用于$geoNear查询。

在下面的例子中,$lookup

  • 使用let定义$pt
  • pipeline使用$geoNear阶段。
  • $geoNear阶段用pt定义near
db.places.aggregate( [{$lookup: {from: "places",let: { pt: "$location" },pipeline: [{$geoNear: {near: "$$pt",distanceField: "distance"}}],as: "joinedField"}},{$match: { name: "Sara D. Roosevelt Park" }}
] );

聚合返回的结果中:

  • Sara D. Roosevelt Park文档作为主文档。
  • 将地点集合中的每个文档作为子文档,使用$pt变量计算距离。
{_id: ObjectId("61715cf9b0c1d171bb498fd7"),name: 'Sara D. Roosevelt Park',location: { type: 'Point', coordinates: [ -73.9928, 40.7193 ] },category: 'Parks',joinedField: [{_id: ObjectId("61715cf9b0c1d171bb498fd7"),name: 'Sara D. Roosevelt Park',location: { type: 'Point', coordinates: [ -73.9928, 40.7193 ] },category: 'Parks',distance: 0},{_id: ObjectId("61715cf9b0c1d171bb498fd6"),name: 'Central Park',location: { type: 'Point', coordinates: [ -73.97, 40.77 ] },category: 'Parks',distance: 5962.448255234964},{_id: ObjectId("61715cfab0c1d171bb498fd8"),name: 'Polo Grounds',location: { type: 'Point', coordinates: [ -73.9375, 40.8303 ] },category: 'Stadiums',distance: 13206.535424939102}]
}

指定地理空间索引

假定有一个places集合,该集合的location字段上有一个2dsphere索引,legacy字段上有一个2d索引。

places集合中的文档类似这个:

{"_id" : 3,"name" : "Polo Grounds","location": {"type" : "Point","coordinates" : [ -73.9375, 40.8303 ]},"legacy" : [ -73.9375, 40.8303 ],"category" : "Stadiums"
}

下面的例子使用key选项,为$geoNear聚合操作指定使用location字段的值而不是使用legacy字段的值。聚合管道同事使用$limit返回最多5个文档。

db.places.aggregate([{$geoNear: {near: { type: "Point", coordinates: [ -73.98142 , 40.71782 ] },key: "location",distanceField: "dist.calculated",query: { "category": "Parks" }}},{ $limit: 5 }
])

聚合返回下面的结果:

{"_id" : 8,"name" : "Sara D. Roosevelt Park","location" : {"type" : "Point","coordinates" : [-73.9928,40.7193]},"category" : "Parks","dist" : {"calculated" : 974.175764916902}
}
{"_id" : 1,"name" : "Central Park","location" : {"type" : "Point","coordinates" : [-73.97,40.77]},"legacy" : [-73.97,40.77],"category" : "Parks","dist" : {"calculated" : 5887.92792958097}
}
http://www.dinnco.com/news/9307.html

相关文章:

  • 深圳积分商城网站制作高级搜索引擎
  • 建站之星官网建设刷关键词排名seo软件
  • 网站建设的基本流程如何做网络推广运营
  • 泊头做网站的全球疫情最新数据消息
  • 仪征市建设局网站网站的优化从哪里进行
  • 不要域名做网站站长之家源码
  • 淘宝代码网站有哪些小程序开发需要哪些技术
  • 我国外贸企业网站建设整合营销传播工具有哪些
  • 做网站小程序挣钱吗今日最新头条新闻条
  • 网站编辑的职业特点有哪些佛山网站建设公司哪家好
  • 天津武清做淘宝网站seo优化分析
  • 做销售在哪个网站找客户端快速排名网站
  • 给做网站建设的一些建议企业网站搜索优化网络推广
  • 天长做网站常州seo排名收费
  • 公司网站后台怎么上传视频发软文的平台
  • 做外围网站代理合法不网站建立具体步骤是
  • 公益网站建设 参考文献企业网站seo优化公司
  • 重庆高端设计公司朝阳区seo
  • 网站代备案服务关键词歌曲歌词
  • 让医院做网站的策划书微博推广
  • 网站管理后台怎么做天津seo优化排名
  • 电商网站怎样做优化才最合理线上销售培训机构
  • 用ps做网站导航自己想做个网站怎么做
  • 青海省城乡建设信息官官方网站口碑营销的模式
  • 江苏股票配资网站建设东莞做网站排名优化推广
  • 网站做服装那个平台好一点新手运营从哪开始学
  • 网站续费怎么做济南seo整站优化招商电话
  • 怎么做盗版电影网站青岛百度推广优化怎么做的
  • 西安网站建设培训网站搜索引擎优化方案的案例
  • 深圳移动官网网站建设厦门seo网站推广