...

Database Managment - Mongo DB

Back to Course

Lesson Description


Lession - #1426 MongoDB Aggregation


MongoDB - Aggregation

Aggregations activities process information records and return figured outcomes. Collection activities gather values from various archives, and can play out an assortment of procedure on the assembled information to return a solitary outcome. In SQL count(*>
and with bunch by is a likeness MongoDB total.

The aggregate(>
Method

For the aggregation in MongoDB, you ought to utilize total(>
technique.
Syntax Basic syntax of aggregate(>
method is as follows

>db.COLLECTION_NAME.aggregate(AGGREGATE_OPERATION>

Example In the collection you have the following data −

{
   _id: ObjectId(7df78ad8902c>
title: 'MongoDB Overview', description: 'MongoDB is no sql database', by_user: 'tutorials point', url: 'http://www.tutorialspoint.com', tags: ['mongodb', 'database', 'NoSQL'], likes: 100 }, { _id: ObjectId(7df78ad8902d>
title: 'NoSQL Overview', description: 'No sql database is very fast', by_user: 'tutorials point', url: 'http://www.tutorialspoint.com', tags: ['mongodb', 'database', 'NoSQL'], likes: 10 }, { _id: ObjectId(7df78ad8902e>
title: 'Neo4j Overview', description: 'Neo4j is no sql database', by_user: 'Neo4j', url: 'http://www.neo4j.com', tags: ['neo4j', 'database', 'NoSQL'], likes: 750 },

Now from the above assortment, to show a rundown expressing the number of instructional exercises are composed by every client, then, at that point, you will utilize the accompanying total(>
strategy

> db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$sum : 1}}}]>
{ "_id" : "tutorials point", "num_tutorial" : 2 } { "_id" : "Neo4j", "num_tutorial" : 1 } >

Pipeline Concept

In UNIX order, shell pipeline implies the likelihood to execute a procedure on some information and utilize the result as the contribution for the following order, etc. MongoDB additionally upholds same idea in collection system. There is a bunch of potential stages and every one of those is taken as a bunch of archives as an info and produces a subsequent arrangement of reports (or the last coming about JSON record toward the finish of the pipeline>
. This can then thusly be utilized for the following stage, etc. Following are the potential stages in collection system −
  • $project − Used to choose a few explicit fields from an assortment.
  • $match − This is a sifting activity and hence this can diminish how much records that are given as contribution to the following stage.
  • $group − This does the genuine collection as examined previously.
  • $sort − Sorts the records.
  • $skip − With this, it is feasible to skirt forward in the rundown of records for a given measure of archives.
  • $limit − This restricts how much reports to check out, by the given number beginning from the ongoing positions.
  • $loosen up − This is utilized to loosen up record that are utilizing exhibits. While utilizing an exhibit, the information is somewhat pre-joined and this activity will be scattered with this to have individual reports once more. Accordingly with this stage we will build how much archives for the following stage.


install mongodb mac

install mongodb mac

Mongodb docker composer

Mongodb docker compose

mongodb w3schools

mongodb w3schools

mongodb community server

mongodb community server