English 中文(简体)
mongodb 分类文件
原标题:mongodb document grouping
  • 时间:2012-04-19 06:23:31
  •  标签:
  • mongodb

i 我的测试收集如下。

> 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" }

and i want to group(map/combine) it by "Mawb" key... so that i can have output of grouped document like,

[
{ "_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" }]

我试图绘制一个地图,但不能通过地图。 如何做到这一点?

问题回答

如果你使用MongoDB 2.1或之后(2.1.x是开发系列,最终实现预期很快稳定的释放2.0),那么你就可以利用Aggregation Framework在服务器方面做所有这一切。

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





相关问题
Access DB Ref MongoDB

Whats the best way to access/query a DB Ref: UPDATE: users: name, groupref : {$ref:"groups",$id:"ObjectId ..." } } groups: name, topic, country,...,.. Assumption is that user belongs to only one ...

MongoDB nested sets

What re the best practices to store nested sets (like trees of comments) in MongoDB? I mean, every comment can have a parent comment and children-comments (answers). Storing them like this: { ...

MongoMapper and migrations

I m building a Rails application using MongoDB as the back-end and MongoMapper as the ORM tool. Suppose in version 1, I define the following model: class SomeModel include MongoMapper::Document ...

MongoDB takes long for indexing

I have the following setup: Mac Pro with 2 GB of RAM (yes, not that much) MongoDB 1.1.3 64-bit 8 million entries in a single collection index for one field (integer) wanted Calling .ensureIndex(...) ...

Storing and accessing large amounts of data

My application creates pieces of data that, in xml, would look like this: <resource url="someurl"> <term> <name>somename</name> <frequency>somenumber</...

热门标签