Alibabacloud.com offers a wide variety of articles about mongodb compass aggregate, easily find your mongodb compass aggregate information here online.
Label:in the two previous articles the basic aggregation function of data aggregation in MongoDB count, distinct, group > and the MapReduce of data aggregation in MongoDB >, we've provided two implementations for data aggregation, and today, in this article, we talk about another way to implement data aggregation in MongoDB-the aggregation pipeline
consecutive $skip will be merged into one, followed by a number of two $skip.Two consecutive $match. are merged into 1, the conditions are merged together.{$sort: {Age:-1}},{$skip: 10},{$limit: 5}{$sort: {Age:-1}},{$limit: 15}{$skip: 10}Example{$sort: {Age:-1}},{$skip: 10},{$limit: 5}====>>>>{$sort: {Age:-1}},{$limit: 15}{$skip: 10}====>>>>$sort + $limit Merge{$limit: 100},{$skip: 5},{$limit: 10},{$skip: 2}==========>>>>>>>{$limit: 100},{$limit: 15},{$skip: 5},{$skip: 2}=========>>>>>>>>>{$limi
Tags: MongoDB aggregate multiple grouping conditionsWhen using aggregate for grouping, multiple grouping conditions are as followsNative sql:Db.test.aggregate ({$group: {_id:{name: ' $name ', Pro: ' $pro},total:{$sum: ' $num '}}},{$project: {Total:1}})In Java, this corresponds to the following:Grouped according to Subjname and province
dbobject groupfields = new
go out of the _id field, and then sort by the cat_id,color of the item, and the result skips a row. Take only 30 hang records and push the results into the result set[{$math: {goods_price:{$gte:3000}}}, {$project: {cat_id:1,goods_name:1, Goods_number:1, _id:0}}, {$group: {_id:{cat_id:"$cat _id", Color: "$color"}, total:{$sum: "$goods _number"}}}, {$skip:1}, {$limit:30}, {$out:"Result"} ] . MapReduce Method*Grammatical StructureDb.collection.mapReduce (function() {Emit ( This. cat_
MONGO Aggregate query:Db.collection.aggregate ({$group: {_id: ' $id ',//' $_id ' represents the _id column max_value:{$max in the Reference collection: ' $times '}//' $times ' represents Refer to The Times column in the collection}, $match: {times:{$gte: 100}})Equivalent to SQL query:Select _id, Max (times) from Collectionwhere times>=100This article is from the architect's path blog, so be sure to keep this source http://lizhuquan0769.blog.51cto.com/
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.