Friday, 15 May 2015

aggregation framework - Mongodb query Aggregate Documents -


I have several types of rows in my Mangodeb archive. Please note that many key values ​​are added within "Category". / P>

Is there any way, I can write aggregate queries to date, like dates: / 20130202 / sum up all the values ​​inside all sections with CTT, all the rows starting from 20130202 And it also states that the prices of the game, national, int, finance etc. are output. ("51c34a871d56bd16c34e7887"), "Date": "2013020219", "Music", "Date", "Date", "Date", "Date": "42", National: 6, International: 11, Finance: 9, Other: 17, Technical: 20, {"Sports": 40, "National": 2, "International": 6, "Finance": 2, "Other": 16, "Technology": 10, "Music": 32}} {"_id "," Date ":" 2013020218 "," Category ": {" Sports ": 2," National ": 4," International ": 5," Finance ": 7," Other ": Object ID: 1, "Technology": 10, "Music": 2}

}

You can try:

  db.coll.aggregate ([{$ match: {d {$ Sum: "$ category.national"}, International: {$ sum: / 20130202}}, {$ group: {_id: null, game: {$ sum: "$ category.sport"}, national: {$ sum: {$ Sum: "$ category.others"}, Technology: {$ sum: "$ category.tech"}, "$ category.international"}, Finance: {$ sum: "$ category.finance"}, Music: {$ sum: "$ category.Music"}}}))    

No comments:

Post a Comment