如何在 MongoDB 中使用 Map/Reduce?

2022-01-13 00:00:00 mongodb mapreduce php

我很难理解 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

相关文章