Mongo scatter -- aggregate & Query, aggregate aggregation
Mongo Official Website: http://www.mongodb.org/
Mongo is used in work, but Mongo has not been systematically studied. It only records some knowledge points in the use of Mongo during work and can be supplemented at any time, to achieve the purpose of summary and memo.
This article mainly Ends Record aggregation and query.
Aggregation)
Count
Db. view_view.count ()
Db. view_view.count ({_ id: "521842 "})
Db. view_view.find (). count ()
Db. view_view.find ({_ id: "521842"}). count ()
Distinct
Db. view_view.distinct ("_ id ")
Db. view_view.distinct ("view") view is an array. The elements of each array are distinct.
Group
db.invoke_stat.group({ key:{ip:true}, cond:{ date:{$gte:ISODate("2014-07-09 16:00:00"),$lt:ISODate("2014-07-10 16:00:00")} }, reduce:function(curr,result){ result.count += curr.times; }, initial:{count:0}, finalize:function(result) {result.count = '$' + result.count}});db.view_view.group({ keyf:function(doc){return {view_num:doc.view.length}}, reduce:function(curr,result){ result.count += 1; result.id = curr._id; }, initial:{count:0}});
The two groups are described as follows:
Key/keyf: The columns to be grouped. The key selects the columns in the table directly. kef is a function that processes the columns. The function returns an object, for example, {view_num: doc. view. length}, doc. view. length is the length of the view in the array column of the table.
Cond: the query condition to be filtered
Reduce: processing functions
Initial: returns the initial value of a column.
Finalize: further processing of reduce results, such as formatting
MapReduce
db.invoke_stat.mapReduce( function(){ var key = this.ip; emit(key,{r_times:this.times}) }, function(key,emits){ total=0; for(var k in emits) { total+=emits[k].r_times; } return {r_times:total} }, {out:'mr'})
Above: r_times is the name of the column we define to return, ip and times are the columns in the table, mr is the set where we want to save the MapReduce computing result to mr.
MapReduce is prototype: function (map, reduce, optionsOrOutString). The following describes the three parameters of the function:
Map function, which traverses every document in the set. this indicates the document. It uses the emit method to group the document by pressing the buttons and returns the data to be counted;
Reduce function, which collects and counts data. The two parameters are the key value and data array returned by the map function;
The optionsOrOutString parameter is an object and defines some additional work. For example, the out parameter in the column above puts the statistical result into the mr set. If the set does not exist, it is created and overwritten if it exists.
The optionsOrOutString object has other keys besides the out key:
The finalize function is the same as the finalize completor of the group. It can process the reduce result;
Query document, filtering documents before map functions;
The sort document sorts Documents before the map function. You must index the sorted fields first;
Limit integer. Set the number of documents before the map function;
Scope document, variables used in js functions, the client can pass some values through scope;
The Boolean jsMode specifies whether the objects transmitted between map and reduce functions use the BSON format or javascript Object. The default value is false, indicating that the BSON format is used. The advantage is that the intermediate BSON data is stored on the hard disk, therefore, the transmitted data volume can be large, but it will affect the performance. using javascript objects, the performance is high, but only 0.5 million different key values can be transferred;
Verbos Boolean, true by default, displays detailed time statistics.
The above shows that MapReduce is powerful and can easily implement different statistical functions.
Query)
Mongo query syntax:
Db. access_logs_140701.find ({jxTime: {$ gt: 1407011300, $ lt: 1407011400}, "curl. sku ":" 99978033 "}). sort ({jxTime:-1 }). skip (1 ). limit (1, 100)
Db. invoke_stat.find ({date: {$ gte: ISODate ("10:00:00"), $ lt: ISODate ("11:00:00 ")}})
Db. view_view.find ({view: {$ size: 10}) queries an array of less than 10 characters in length. Currently, Mongo does not support Data Length range query, for example, query a data length of less than 10, mapReduce programming only
What is Aggregation MSDU (A-MSDU) in wireless routing settings?
The conflicts arising from the channel competition and the Backoff Mechanism introduced to resolve the conflicts greatly reduce the throughput of the system. To solve these two problems on the MAC layer, 802.11n adopts frame aggregation technology and BlockAcknowledgement mechanism.
Frame aggregation technology also includes MSDU aggregation (A-MSDU) and MPDU aggregation (A-MPDU ):
A-MSDU
A-MSDU technology refers to the aggregation of multiple MSDU into a large load in a certain way. MSDU can be considered as an Ethernet packet. Generally, when an AP or wireless client receives A message (MSDU) from the protocol stack, the Ethernet packet header is entered. Here we call it A-MSDUSubframe. before sending the packet through the RF port, it needs to be converted to 802.11 packet format one by one. The A-MSDU Technology aims to aggregate several A-MSDUSubframe and encapsulate it into A 802.11 packet for sending. This reduces the overhead of PLCPPreamble, PLCPHeader, and 802.11MAC headers required to send each 802.11 packets, reduces the number of response frames, and improves the packet sending efficiency.
A-MPDU
Unlike the A-MSDU, The A-MPDU aggregates the MPDU encapsulated by 802.11 packets, where the MPDU refers to the data frame encapsulated by 802.11 packets. By sending several MPDU packets at a time, PLCPPreamble and PLCPHeader required to send each 802.11 packets are reduced, thus increasing the system throughput.
Q: What is the difference between aggregate and aggregation in terms of terminology?
Aggregate refers to the sum of things, such as the sum of numbers and the total number of people. It is a set that emphasizes the quantity of things;
Aggregation refers to the cluster effect, such as city clusters and circuit clusters. It tends to describe the aggregation of things in scale;