如何在MongoDB中使用Map/Reduce? [英] How do I use Map/Reduce in MongoDB?

查看:71
本文介绍了如何在MongoDB中使用Map/Reduce?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在围绕Map/reduce在MongoDB中的工作方式时遇到了麻烦.我有一个具有以下字段的集合:areacode, state, county, zip, city, lat, lon,其中列出了美国的每个邮政编码以及相应的县,州等.

我希望能够查询特定州的所有县或城市.因此,基本上是某种查询,用于查找"State = MI"的所有记录.在这种情况下,大约返回900条记录.我如何按县对它们进行分组,以便仅获得该州的83个县?我不想使用distinct,因为我希望能够按字母顺序对其进行排序,并可能同时拉出纬度/经度.

关于如何使用map/reduce完成此操作的任何建议?我觉得这很基本,我只是想不通.

解决方案

我对PHP没有任何经验,但是如果您想了解MongoDB Map-Reduce的工作原理,那么可以查看一下..

有关更多信息,请查看

I'm having trouble wrapping my head around how map/reduce works in MongoDB. I have a collection with the fields: areacode, state, county, zip, city, lat, lon that lists every zip code in the US along with the corresponding county, state, etc.

I'd like to be able to query say all the counties or cities in a given state. So basically some sort of a query that looks for all records where "State=MI". In this case, there are about 900 records returned. How do I group them by county so that I just get the 83 counties for that state? I don't want to use distinct as I would like to be able to order them in alphabetical order and possibly pull out the lat/long as well.

Any advice on how to use map/reduce to accomplish this? I feel like it's rather basic, I just can't figure it out.

解决方案

I don't have any experience in PHP, but if you wanted to learn how MongoDB Map-Reduce works, then you can check this out..

For more info, check out this

这篇关于如何在MongoDB中使用Map/Reduce?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆