Thursday, 15 July 2010

Mongoose sum aggregation -


I have this Mongoose schema, where I want to get the sum of sizes based on the manufacturer.

 Record: [[collection: string, url: string, name: string, size: number, haset: {type: boolean, default:  constructor: {type: schema. type. Object ID, Ref: 'User'}, False}, Timestamp: {Type: Date, Default: Date.none ()}}}  

This is what I have tried so far, But as a total of 0

  var object id = is required ('mongoos'). Type.ObjectId; ArchiveModel.aggregate ({$ match: {'creator': new object id (creatorId),}}, {$ group: {_id: null, total: {$ sum: '$ archives.size'}}}, {$ Project: {creator: 1, total: 1}}, function (error, result) {console.log (err); console.log (result);});  

db.col.aggregate ([// all docs with mail Match correct creator {$ match: {Creator: my_creator}}, // array array {$ unwind: '$ archives'}, // calculate all docs {$ group: {_id: 'total', calculate} : {$ Sum: 1}}}]);

No comments:

Post a Comment