Skip to content

Instantly share code, notes, and snippets.

@mrmarcondes
Created December 11, 2012 21:05
Show Gist options
  • Save mrmarcondes/4262138 to your computer and use it in GitHub Desktop.
Save mrmarcondes/4262138 to your computer and use it in GitHub Desktop.
10gen: M101 MongoDB for Developers - Final - question 2
db.messages.aggregate([
{$project: {"_id": 0,
"headers.From": 1,
"headers.To": 1
}},
{$unwind: "$headers.To"},
{$group: {
"_id": {from: "$headers.From",
to: "$headers.To"},
sum: {"$sum": 1}
}},
{$sort: {"sum": 1}}
])
@Sagar-Gohad7
Copy link

Sagar-Gohad7 commented Aug 26, 2016

I am new to MongoDb , I have to store Post and its comments in MongoDb. Please tell me is structure given below will work good.

{"POST_TITLE":"Title", "POST_DESCRIPTION":"Description", "COMMENTS":[ {COMMENT1}, {COMMENT2} ] }

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment