Get the App
SLTechnology News&Howtos  ›  Database  › 

Implementation of Group packet query of MongoDB under MongoVUE

Shulou Source: shulou.com Published: 2022-06-01 18:16:02 09月22日 Update

We know that MongoDB is a non-relational database, so its query method is very different from the standard structured query language SQL. But no matter how complex a structure it is, when it passes through the hands of the developer, it can only become the structure that the customer wants. What we are going to talk about today is how to MongoDB Group grouping query under MongoVUE.

The query format of MongoVUE is as follows:

Db.collection.group ({key, reduce, initial, [keyf,] [cond,] finalize})

From the above, we can see that in order to realize the grouping query of MongoDB, key (grouping field), cond (grouping condition), refuce (grouping calculation) and initial (initial condition) are the indispensable values of MongoDB grouping query. Next, let's take a look at how to implement the grouping query function of MongoDB under MongoVUE:

(1) Select the tables to be grouped, select "Collection--Group", and turn on the grouping function.

(2) enter the fields to be grouped under Key and the filter conditions for grouping under Conditions. Open the ReduceTab page, enter "{" count ": 0}" in the Initial Value output, and enter at the following Reduce function:

FunctionReduce (doc, out) {

Out.count + = 1

}

Select GO, which pops up the grouping result of MongoDB.

(3) at Shell, type out the query sentence of MongoDB automatically.

Db.EQUIPMENT.group ({

Key: {

"equipType": true

}

Cond: {

"siteId": "Beijing"

}

Initial: {

"count": 0

}

Reduce: function Reduce (doc, out) {

Out.count + = 1

}

Finalize: function Finalize (out) {

Return out

}

});

Tags: Grouping query input function condition structure field method selection different complex large and then initial conditions hands customers that is developers data databases. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker MariaDB Xiaomi Huawei