0

我有我的测试集合,如下所示..

> db.test.find()
{ "_id" : "111-21212121", "Mawb" : "111-1111111", "Hawb" : "111111", "Hawb_date" : "date1" }
{ "_id" : "111-21212122", "Mawb" : "111-1111111", "Hawb" : "222222", "Hawb_date" : "date1" }
{ "_id" : "111-21212123", "Mawb" : "222-2222222", "Hawb" : "333333", "Hawb_date" : "date1" }
{ "_id" : "111-21212124", "Mawb" : "222-2222222", "Hawb" : "444444", "Hawb_date" : "date1" }
{ "_id" : "111-21212125", "Mawb" : "333-3333333", "Hawb" : "555555", "Hawb_date" : "date1" }
{ "_id" : "111-21212126", "Mawb" : "333-3333333", "Hawb" : "666666", "Hawb_date" : "date1" }

我想通过“Mawb”键对它进行分组(映射/组合)......这样我就可以输出分组文档,例如,

[
{ "_id" : "111-21212121", "Mawb" : "111-1111111", "Hawb" : "111111", "Hawb_date" : "date1" }
{ "_id" : "111-21212122", "Mawb" : "111-1111111", "Hawb" : "222222", "Hawb_date" : "date1" }],
[{ "_id" : "111-21212123", "Mawb" : "222-2222222", "Hawb" : "333333", "Hawb_date" : "date1" }
{ "_id" : "111-21212124", "Mawb" : "222-2222222", "Hawb" : "444444", "Hawb_date" : "date1" }],
[{ "_id" : "111-21212125", "Mawb" : "333-3333333", "Hawb" : "555555", "Hawb_date" : "date1" }
{ "_id" : "111-21212126", "Mawb" : "333-3333333", "Hawb" : "666666", "Hawb_date" : "date1" }]

我尝试过减少地图,但无法通过。我该怎么做?

4

1 回答 1

2

如果您使用的是 MongoDB 2.1 或更高版本(2.1.x 是导致即将发布的 2.2.0 稳定版本的开发系列),您可以使用聚合框架在服务器端完成所有这些工作。

http://www.mongodb.org/display/DOCS/Aggregation+Framework

于 2012-04-19T09:22:12.750 回答