Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to group sub array inside document using mongodb

Posted on 2017-04-09
4
Medium Priority
?
95 Views
Last Modified: 2017-04-16
hi, i have the following document on mongodb

name: "john",
state: "GA",
city: [
     {"atlanta", 30350},
     {"atlanta", 30351},
     {"atlanta", 30352},
     {"marietta", 45093}
]


how do i aggregate the array of citys and get a document like this:

name: "john",
state: "GA",
city: [
     {"atlanta", "30350, 30351, 30352"},
     {"marietta", "45093"}
]
0
Comment
Question by:rafaelrgl
  • 3
4 Comments
 
LVL 11

Expert Comment

by:Nitin Sontakke
ID: 42085989
I am almost certainly (not yet) an expert on MongoDB, however, I suspect if you can do that without getting data back, manipulate it and put it back again.

How many records (Ooops! documents) are involved here? Please wait for others to comment as well.
0
 
LVL 1

Accepted Solution

by:
rafaelrgl earned 0 total points
ID: 42088568
{ $concatArrays: [ [ "hello", " "], [ "world" ] ] }
0
 
LVL 1

Author Closing Comment

by:rafaelrgl
ID: 42094660
that is the right solution for it.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question