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

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

问题描述

我很难理解 map/reduce 在 MongoDB 中的工作原理.我有一个包含以下字段的集合:areacode, state, County, zip, city, lat, lon 列出了美国的每个邮政编码以及相应的县、州等.

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.

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

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.

关于如何使用 map/reduce 来完成此任务的任何建议?我觉得它很基础,我就是想不通.

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.

推荐答案

我没有任何 PHP 经验,但是如果你想了解 MongoDB Map-Reduce 是如何工作的,那么你可以看看这个..

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..

有关更多信息,请查看 this

For more info, check out this

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

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