KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Everybody. In mongo group query, the result shows only the key(s) in arguments. How to keep the first document in each group like mysql query group. for example: ------------------------------------------------------------------------- | name | age | sex | province | city | area | address | ------------------------------------------------------------------------- | ddl1st | 22 | 纯爷们 | BeiJing | BeiJing | ChaoYang | QingNianLu | | ddl1st | 24 | 纯爷们 | BeiJing | BeiJing | XuHui | ZhaoJiaBangLu | | 24k | 220 | ... | .... | ... | ... | ... | ------------------------------------------------------------------------- db.users.group({key: { name: 1},reduce: function ( curr, result ) { result.count ++ },initial: {count : 0 } }) result: [ { "name" : "ddl1st", "count" : 1 }, { "name" : "24k", "count" : 1 } ] How to get the following: [ { "name" : "ddl1st", "age" : 22, "sex" : "纯爷们", "province" : "BeiJing", "city" : "BeiJing", "area" : "ChaoYang", "address" : "QingNianLu", "count" : 1 }, { "name" : "24k", "age" : 220, "sex" : "...", "province" : "...", "city" : "...", "area" : "...", "address" : "...", "count" : 1 } ]
Tags (comma-separated)
Save Edits
Cancel