Saturday, April 25, 2015

Chanakya The Great


All living beings on this planet takes birth. And among the living beings on this earth, it is human beings, also known as homo-sapiens, who is supposed to be deemed special as human beings possess intellect, which separates the humans from the animals.


Man kind is something where, the process of intellectual thoughts is promoted and nurtured. This is why humans are also known as a species who spend time in thinking.


But this thinking process and the capability to think even in human is not possessed by everyone.  Some people acquire knowledge by living in the company of intellectual, some have traits of working hard, and some, despite being hard workers, never ever up move up the echelons of the intellectuals.


And then, there are people who are born intellectuals. It is said that intellectual person can even change the course of the rivers. Rivers, which flows as per the laws of nature. They don't conform to the norms of the society, but  rather make society to think and act as per their visions.


One such person who walked down to this planet was 'Chanakya'. He is best known as the person who perished a powerful dhananda empire, author of a famous treatise 'Arthashashtra' and the prime minister of powerful Chandra Gupta Maurya.


                                               File:Chanakya artistic depiction.jpg



Son of rishi Canak, Chanakya, also known as Kautilya or Vishnugupta, was born in Pataliputra,Magadh (modern Bihar), and later moved to Taxila, in Gandhar province(now in Pakistan). At a very early age little Chanakya started studying Vedas. The Vedas; considered to be the toughest scriptures to study were completely studied and memorized by Chanakya in his infancy. He was attracted to studies in politics. In politics Chanakya’s acumen and shrewdness was visible right from childhood. He was a student of politics right from child hood. Known as a masterful political strategist, He knew how to put his own people in the opposite camp and spy the enemy without his knowledge before destroying him forever. Chanakya was an ace in turning tables in his favor irrespective of the circumstances. He never budged to pressure tactics by the ruthless politicians. In this way after studying religion and politics, he turned his attention to economics, which remained his lifelong friend. "Nitishastra", a treatise on the ideal way of life shows his in depth study of the Indian way of lifeHe was a professor (acharya) of political science at the Takshashila University and later the Prime Minister of the Emperor Chandragupta Maurya. He is regarded as one of the earliest known political thinkers, economists and king-makers. He was the man to envision the first Indian empire by unification of the then numerous kingdoms in the Indian sub-continent and provide the impetus for fights against the Greek conqueror Alexander.



Chanakya received his education at a famous school in a city well known in those days as Takshashila (corrupted later into 'Taxila'). The teachers at Takshashila were great scholars known all over the world. Students from different parts of Bharat went there for their education. Even kings sent their sons for education there. It is said that a certain teacher there had one hundred and one students and all of them were princes!

Generally a student entered the University of Takshashila at the age of sixteen. The four Vedas, archery, hunting,elephant-lore, and eighteen arts were being taught there.
The faculties there, which taught law, medicine and warfare, were famous not only in Bharat but also abroad.

Such was the center where Chanakya had his education. With this education, his inherent brilliance became like a polished diamond.



After finishing his education, Chanakya decided to return to Pataliputra, his birth place. The city was industrious in producing essential commodities and luxurious goods for the rich. When Chanakya entered the city, it was known for respecting knowledgeable people and scholars. The intellectuals from across the country were warmly invited for the intercourse of new ideas and development of the state. It was virtually the city of fortunes as it recognized the true talent and rewarded richly for the work done by an individual. No wonder Chanakya decided to start his glorious campaign from Patliputra.

Dhanananda, the ruler of Patliputra was unscrupulous and cruel by nature. He was always busy gathering money without thinking about consequences. He was always dissatisfied with the amount of money he had. Collecting taxes exorbitantly, he was a villain in the public eye. There was public outrage on the taxes which were collected on unwanted things. The main aim of collecting taxes was to serve the selfish interests of the king. There were taxes on hides, tax on wood and tax even on stone! The amount of money which Dhanananda had was unimaginable.

When Chanakya arrived at Patliputra, there was a change in the way he ran his kingdom. He gave gifts to the poor and was on the way of becoming lenient in administration. He had formed a trust or committee to administer his gifts and charities. The committee was headed by scholars and influential people of the society. It is said that the president had the powers to make up to ten million gold coins.

Since Chanakya was a great scholar from Taxila, he was included in the committee for charity. Chanakya later on became the president of the ‘Sungha’ (Trust). The Sungha used to help the king in the distribution of the money allotted for charity to the different sections of the society. In the process of delegation of the funds for charity, the president of the trust had to meet the king frequently. When Chanakya met the king for the first time, he was disgusted at the ugly appearance of Chanakya. As time passed he developed contempt for Chanakya. There was no refinement in words and conduct. To increase the fire between Dhanananda and Chanakya, the courtiers dissuaded the king from having a cordial relationship with Chanakya. Chanakya acted like a thorough professional and avoided praising the king. He always spoke bluntly and tersely. The king did not like the way Chanakya behaved with him. The king removed Chanakya from the post of president without any reasons.Infact, stupid king dhananda insulted Chanakya ,a majestic Brahman by pulling his shikha or tuft and and throwing Chanakya out from the palace humiliated and unceremoniously.

True to his Brahmanical upbringing, Chanakya felt outraged on this unjust. Infact, this foolish act by the foolish king made chanakya to take an oath:  'I will not tie my tuft of hair until I uproot the whole Nanda dynasty and establish dharma in magadha. Rulers like you have spoiled Bharat. The tuft of hair which you arrogantly pull now will be like a serpent which comes back to bite you.'

And as we all know, the rest is history. The learned Brahman Chanakya then trained Chandragupta Maurya. He advised Chandragupta in the matters of state affairs, got dhananda and his entire lineage uprooted, and made Chandragupta the king. And as we all know, the Maurya Empire was one of the largest empires of the world in its time. It was also the largest empire ever in the Indian subcontinent. At its greatest extent, the empire stretched to the north along the natural boundaries of the Himalayas, to the east into Assam, to the west into Balochistan (south west Pakistan and south east Iran) and the Hindu Kush mountains of what is now Afghanistan. The Empire was expanded into India's central and southern regions by the emperors Chandragupta andBindusara, but it excluded a small portion of unexplored tribal and forested regions near Kalinga (modern Odisha), until it was conquered by Ashoka. It declined for about 50 years after Ashoka's rule ended, and it dissolved in 185 BCE with the foundation of the Sunga Dynasty in Magadha,whose rein is a different matter of debate, as sunga's imperialism came in response to buddhist patronage given by the kings of post mauryan empire  who took up and converted to buddist faiths.







But Chanakya is not only known as a  prime minister and author of one of the famous treatise Arthashathra, but also for Chanakya neeti. Chanakya Niti/neeti is a collection of aphorisms, said to be selected by Chanakya from the various shastras. It describes how people must behave in their daily life, and when they encounter a particular situation. Some of the neeti which I like the most are:



  • Money comes and goes, so is the youth. Life goes and goes the soul, Nothing lasts forever. Only thing that stays firm is your faith.

  • The best place to live is where fools are not honoured, grains are stored safely, where husband and wife don’t quarrel. Goddess Laxmi (Goddess of wealth) resides at such locations.

  • A hard working person cannot remain poor, a person who continuously remembers God is unlikely to perform a sin, a person with peace cannot quarrel. Similarly, a vigilant person has no fears.

  • In case of natural disasters, famine and unstoppable enemy invasion; one should run away and save life. (Save yourself for another day).


  • Those who desire only wealth belong to lowest class of people. Who desire wealth and respect are above them. The men who desire honor and respect are superior to all.

  • Everyone respects wise men. They are rewarded with honor and money.  A person can attain everything through knowledge.  It is worshiped everywhere.

  • If a snake is non-poisonous, then too it must pretend like one with ability to take life.

  • A person must walk with his eyes open, must drink clean water, speak words of wisdom, and must perform an action only after thinking about pros & cons.

  • A person who leaves his community to join another community is likely to face quick destruction. Same will be the case with king who don’t cares for his subjects.

  • A student who continuously thinks about comforts of home (homesick) will not be able to gain knowledge. One with greed cannot be truthful. One who debauch cannot acquire piety.

  • One must not be afraid of future, nor shall regret upon past. Wise men concentrate on utilizing the present to frame a brighter future.

  • The nature of noble people is quite strange i.e. instead of acting arrogant upon attaining wealth they bow down in humility and act more modestly and respectfully.

  • One who plans and prepares himself to face challenges and difficulties is most likely to succeed against them. On the other hand, if a man leaves everything on luck then he will perish for sure.

  • Poverty, diseases, conflicts, and other problems in life are nothing, but the fruits from tree of ones own misdeeds.

  • A really wise man is an expert in the art of speaking, he talks as per situation, speak the words that add to his fame, and shows anger in accordance to the authority he possesses.

  • It is better to die than living a life of humiliation. You die once, but humiliation kills you every moment.

Indeed, Chanakya himself proved that instead of living a life full of disgrace, it is better to die with dignity and honor.

People such as Chanakya take birth for once, but with their works, remain eternal.





Friday, April 24, 2015

University of Edinburgh - Conditional Offer



Hello Everyone,

It has been long time that I have written something. But what a break it has been.

I am writing this post with a proud feeling. The reason for this is that I have received a conditional offer for Masters of Science from the University of Edinburgh.

Well, I struggled for nearly 2 years, and finally, my efforts have come to the fruition. The University of Edinbugrh is a prestigious university, where finest minds of the world come together and entry is extremely competitive.

The University of Edinburgh is the sixth oldest university in the English speaking world.

Famous personalities of this university includes Charles Darwin, Alexander Graham Bell-Founder of Bell Labs, Mathematician Thomas Bayes, and Arthur Conan Doyle who created famous detective Sherlock Holmes.

Informatics is the study of natural and engineered computational systems. It encompasses the academic disciplines of computer science, software engineering, artificial intelligence and cognitive science.

This indeed is the beginning of a new journey of my life.



Thursday, January 15, 2015

2014-A lookback

                                                       || OM NAMAH SHIVAYA ||


First of all, wishing all the readers Happy New Year.

This is my first post of the new year 2015.

The post is about 2014, a Look back. I will be writing my highs,my lows.

Overall, 2014 has been a year for me where I have explored a new dimension of my own life.

I never thought that I will be passing through such ardous journey, but then, as lord krishna says to yudhistira, the past is gone, future is yet to come.

My highs of 2014:


  • An event which I hosted at Bosch DIY square, sarjapur road, when I was working at BMOSC. This really has changed my entire outlook, and my personality transformed a lot. I met wonderful people and my learning process continued.
  • Getting shortlisted for SPJIMR, PGPM. This was something miraculous. I was totally down and out, and then, this came. This has given me a confidence that I also belong to the league of Ivy League B-schools, such as ISB and IIM. Let us see what's in store for the future, as I am not desperate to do MBA as my real love and passion are Science, Technology and Engineering.
  • A visit at my parent's place ShivGangai, by driving!!!! Yes, for the first time, I got a chance to drive on highway. I visited my parent's place, with my family, wife Pratima and daughter Prateeksha. Unfortunately, both of my brothers did not accompany us in this journey. But this time, my elder brother and sister in law is visiting this place, so we are again going to this place, and yes, Driving!!!!
  • My brother's short visit to the USA.
  • Visiting IISC Bangalore, an open day event at that place, where all the gadgets,machines,instruments, were displayed. Was a wonderful opportunity and I learned how to do Science.
  • Fitness, which I am still maintaining, but I think that my fitness levels have improved leaps and bounds, though, no compromises with fitness.

Now the LOWS:

  • This is the most depressing moment of my life, which unfortunately happened in the year 2014. I lost one of my aunt, whom we fondly used to call 'Atte', when we were kids and were staying in new delhi.She was diagnosed with cancer. Rama Atte, I Will Always Miss You. 
  • Lost job in the month of February 2014, due to downsizing and budget issues. This is third job loss which I have suffered, but then, it is fine, as I know that my skills level are very high, and, who knows, I may get an opportunity to work with my heroes in the field of software.
  • Separation from BMOSC. One of the toughest call which I had to make, probably, worse than losing the job, but then, I am fine with it. It is just that life has to move on. But hey, I don't have anything against anyone, because, whatever I am today, it is largely due to these people.Thanks for providing me the opportunity to work with this great organization BMOSC.
  • Not to able to convert the SPJIMR PGPM, beacuse, I could not score 600 in GMAT.
  • Not able to convert any of the job interview, I don't know where am I going wrong.  I hope that I quickly get back to the industry, but this time, with my dream job, well, I mean, it is ok, everyone has right to dream. ;)

Looking ahead for a great year. And, God, just be kind to me, as you always have been, never ever left me at any moment and never ever leave me in the future also.


                                               || JAI BHAGWANA PARASHURAMA ||

Monday, November 17, 2014

Successfully completed M101P: MongoDB for developers


I have successfully finished the course M101P:MongoDB for developers, offered by the MongoDB, available at the university.mongodb.com.

The course is taught by Mr Andrew Erlichson, who holds phd from the university of stanford and is currently the Vice President Education at MongoDB Inc.

This course gives us an idea of what MongoDB is, how to use CRUD, how to design and engineer applications using schema, how to optimize performance and how to use aggregation framework.

I have received a certificate of completion duly signed and attested by both, Mr Max Schireson, CEO, MongoDB and Andrew Erlichson. I have scored 70% marks, and the cut off score to get certified for this course is 65%.

I have enjoyed the course, the way it has been presented, challenging assignments which has made me hands on on MongoDB ,online discussion forum where people were really helpful. Also, the final exam was really tricky, and I am glad that I have managed 70% overall.

Thanks for thinking about teaching and sharing knowledge with others, the journey has been wonderful.





Tell Me About Yourself - The Most Important And The Most Neglected Question



Whenever we attend an interview, or even if we have a normal conversation, we are or will be often asked this question, 'TELL ME ABOUT YOURSELF'. This question is the most important question, yet neglected, not only by the recent college pass outs, but even by the experienced professionals as well as the veteran people. This question is asked everywhere, be it an interview for a job or a GD/PI for MBA or even for hi-tech courses.

But why this question is so important?

The reason that this question is usually asked first by the interviewer is that tell me about yourself is an ice breaker to initiate a conversation. Answering this question with readiness and in an articulated manner gives the confidence to the interviewer that the candidate has prepared for the interview and is serious about the job. Majority of the job interviews actually involves forming rapport with the interviewer. Candidates often think that by cramming the answers, they will get the job, where as the interviewer is checking whether the candidate has prepared for the interview, how well he/she handles the situation.

The purpose of the interviewer is to gauge whether the candidate has clear picture about the work he/she has done or still does, whether they understand the instructions,will they be able to understand and solve problems and how do they approach a problem or the work- meticulous, careful or carefree, always in hurry, are they good team player. Also, what do they do apart from their professional work. Here also, one should not say that they listen to music etc, but must tell that how does the candidate utilize the time. Tell me about yourself actually describes the candidate's true personality, both at the professional level as well as at the personal level, hence this question is the most important and must be prepared and articulated in a proper manner.

But  lot of people neglect this question. They think that tell me about yourself involves telling the entire history of their life. That's not the correct way to attack this important question. This question has to be finished in 2 minutes, and in 2 minutes, no person on this planet will be able to narrate their entire life history.

So how to tackle this question?

Well, I normally attend software engineering interviews, so my advice will be for software engineers.

First, tell from where you have graduated, in which year and the university name. Then, start with the first job designation with the firm's name, then the last designation with the firm's name. After that, tell them about the job responsibilities. Then, tell what have you done at the work, any leadership position etc.

After that, tell the interviewer  how do you update yourself and keep track about the latest technologies. And how do you achieve this? Do you listen to webinars, attend workshops and events?

Then come to the personal level. Here also, don't describe about the family details. Talk about learning, being updated with recent knowledge, any research kind of activities.

Since this is an important question, I have written my response to it. Here it is:

My name is Radhakrishna Rao L. After completing my bachelors of Technology from Guru gobind singh indraprastha  university in the year 2005 with IT as majors, I started my career as associate applications engineer with   Oracle Technologies Pvt Ltd and rose to the level of Senior Software Engineer  with PeopleTechGroup.My job responsibilities  included customizing Enterprise modules using Peoplesoft Technology. The work included communicating with team members and clients, gathering requirements, and creating solutions. I have designed and optimized application engines to automate and integrate processes of the HR systems  using sql and peoplesoft.
  
 I keep myself updated by learning new skills .I have finished a course on R and statistics from the coursera, an online MOOC platform, and also,have finished a course on MongoDB,a next geneartion of database from mongodb university.  I attend hackathons to meet new people and work in teams in order to solve problems out of my domain. I also attend seminars, and listen to online webinars which talk about new technologies and demonstrate workshops. I also write and maintain a blog.
  
Personally ,apart from spending time with my family, I like to learn languages, especially Sanskrit. I take keen interest in Indian politics, research on history of civilizations and empires, collect and store information from the newspaper articles and magazines, and like to keep myself fit. 


It is clear that I have covered everything, my education history, my job history, my work history, team player, how do I learn new things, and how I spend my personal time. Also, this answer will take less than 2 minutes to speak out.

I hope that this article will help the readers to achieve their goals.

Thanks for the read.

Saturday, November 15, 2014

Madhava Rao Peshwa Thorale -THE MAJESTIC AND THE UNPARALLELED


History, for some, especially government and politics, is a tool to promote vested interests and agenda. And for others, History is a tool to study about the past, their rich culture and heritage and learn the marvelous beauty of the ancient civilization. Also, history gives us an opportunity to learn about great men, those people who showed resilience, strength, courage, conviction, rose to the occasion and hence, have got their names written as great men of all times.

One such personality, who also happens to be my source of inspiration is Madhav Rao I (or Pradhanpant Shrimant Madhavrao (Ballal) Peshwa I aka Thorle Madhav Rao Peshwa )

The last 1000 years saw a battle where , all the forces, from middle east to saudi arab, western europe, eastern europe, central asians, engaged in battle to establish superiority. The world war-1 and 2 were again the repeat of the same 1000 years of battle, but for a new world order. And this is when, a certain group, called mohammedans, arrived in the land of vedas, where they started massacring the vedic people because they questioned these marauders that why shall we follow you, you are bringing the wrong methods. Unfortunately, even today, in modern India, we have slave of such people who want hindus to act like slaves of mohammedans, consider them good. Now, I really don't want to name or blame anyone, but this also include a prominent leader of modern indians, who is considered a mahatama by everyone.


Sanatnis created two great empires to attack and resist the force of alien powers, europe and mohammedan. One was the great vijaynagara empire, which was founded by swami vidyaranya, harihara and bukka whose capital was the city of hampi, which got plundered after the battle of talikota.


The second empire came when swami samartha ramdas inspired a great hindu king chatrapati shivaji and then formed a very strong state of maratha confederacy, whose capital was Pune City.


It was Shivaji who created the Peshwa, the titular equivalent of a modern Prime Minister designation in order to more effectively delegate administrative duties during the growth of the Maratha Empire. The Peshwas were all ministers who initially started as the chief executives to the king. Prior to 1749, Peshwas held office and controlled the Maratha army. They later became the de facto hereditary administrators of the Maratha Empire from 1749 till its end in 1818. 


The first Peshwa was  Moropant Trimbak Pingle.


The Peshwa became a hereditary administration after chattrapati Shahu  appointed  Baji Rao I, son of Balaji Vishwanath (Bhat), as Peshwa in 1719. Baji rao's son was Nanasaheb Peshwa, whose son is madhava rao peshwa.

The maratha empire incurred heavy losses after the third battle of panipat. In the Third Battle of Panipat, the Maratha Empire suffered a serious blow at the hands of combined forces of Durrani Empire, the Nawab of Awadh and Rohillas under Najib ad-Dawlah. Their power was virtually wiped out of the North India and the confederacy itself experienced fragmentation. The Bhonsles of Nagpur did not participate and tried to remain aloof of the aftermaths too.


It was at this time, that madhava rao peshwa, aged 16, was bestowed with the responsibility of the peshwaship of the empire which was in turmoil. And what an administration it was. Using all the entrepreneurial zeal, innovation, he again brought the empire back to its acensdancy. The sword of maratha again started bleeding the blood of the enemies, and this time, it was even more brutle. Enemy of the state were virtually wiped out. Corrupt officers were removed (There is a hint that corruption in India has been since long time and not after 1947 as proposed by baniya BJP).

One of his biggest achievement is the victory over haider ali, the islamic marauder, in the famous battle of nijagal. Even though, secularist praise and glorify tipu sultan, they never make a point about the brutality of haider ali and tipu sultan on the hindus.

Madhava Rao Peshwa, with the help of madikeri naya of chitradurga, made sure that haider ali gets defeated. At this point, peshwas became powerful, which meant hinduism goes strong. But destiny has something else written for hindus.

Not only was he an able administrator, he also possessed brilliant diplomatic skills. An English officer Mr. Mastin met Madhavrao. He requested that two ports, Vasai and Sashti be given to the East India company to set up a military base so that they can protect their trading ships. In exchange, he offered his assistance to fight against Madhavrao’s domestic enemies in the south. Madhavrao flatly told Mastin that even though he had domestic enemies, they were Indians first, but the British who came under the disguise of trade, had quickly thrown the scale and taken the sword. The gem of this conversation is that Madhavrao asked Mastin to give the Marathas two equally good ports in the British territory where the Marathas could keep their army, build base and conduct trading. No need to say, this meeting was not fruitful for the British. 

During this time, an interesting incident occurred. Madhavrao was busy managing the treasury of the kingdom and supervising the calculation of the expenses encountered during the war. One day he noticed a large crowd anxiously waiting at the entrance of Shaniwar Wada. Upon summoning the guards, he discovered that they were the aggrievated citizens of Pune who had lost their families, house, land and wealth in the war. They had been visiting his residence for the past few days with hopes of expressing their unbearable losses. However, the guards had not allowed them to meet the Peshwa by excusing that his health had deteriorated. When he heard this, Madhavrao became furious with the guards; he immediately left all his tasks aside and stepped out of Shaniwar Wada. He personally met with the poverished families and patiently listened to each one of them. He made a note of every family’s loss and personally saw to it that these losses were compensated from the empire’s revenue. This speaks volumes about why the citizens always looked up to him with tremendous faith and respect.

His own uncle kept conspiring against him, despite madhava rao showing immense respect to his uncle. He escaped many assassination attempt which his uncle used to hatch against him in order to gain the ascendacy of the throne. Unfortunately, he was diagnosed by tuberculosis, which eventually proved out to be the reason of his  demise.

Now days, the Indian B schools, who are supposed to produce Business leaders in the field of management and administration just teach about how to make corp orates more profitable. But none of our so called cream business school graduates take charge of a fallen businesses or empires and get them back on track, creating sustainable solution. All B-schools of India must teach about madhava rao peshwas work ethics, leadership abilities to prepare better administrators. I don't see anything wrong in this. Infact, if India can include chapters on tippu sultan, akbar etc, and is ready to teach german language instead of sanskrit, what's wrong in teaching about madhava rao peshwa the great, who made hinduism strong?

18 November 1772, early morning approximately at eight: Madhavrao died at the temple premises of Chintamani, Theur. Thousands of citizens visited the site and paid their last respects. His wife Ramabai performed sati during his cremation later that day. Madhavrao was cremated on the banks of the river which was about half a mile from the temple. A small memorial carved out of stone rests today at that place as a memorial.


Assessing the impact of the loss of Madhavrao, the writer James Grant Duff eulogised:
"And the plains of Panipat were not more fatal to the Maratha Empire than the early end of this excellent prince…" 


Saturday, October 18, 2014

MongoDB: Aggregation Framework


This blog post will give a basic introduction to MongoDB's aggregation framework.

What is Aggregation in MongoDB:
Aggregations are operations that process data records and return computed results. MongoDB provides a rich set of aggregation operations that examine and perform calculations on the data sets. Running data aggregation on the mongod instance simplifies application code and limits resource requirements.
Like queries, aggregation operations in MongoDB use collections of documents as an input and return results in the form of one or more documents.
This is similar to Group-By clause in RDBMS world of databases.
We use aggregation framework in MongoDB to compute the sum,averga,mean,median of the numerical type data in the documents of a collection.
Basic Syntax of aggregation:
The general aggregation framework is this:
                           db.collection.aggregate([{"aggregation operation"}])
Here, we have to pass the collection name and then use 'aggregate' command and then perform appropriate aggregation operation.
The following are the most commonly used aggregation operations which are used in MongoDB:
  • $project - Reshapes the document & brings at the top. Uses 1:1 mapping. Use this to pass                   the  fields which are needed in the next state of the pipleline. Also use this to filter                     the output of the aggregated dataset where certain fields are required.
  • $match -  Filters the documents to pass only the documents that match the specified                     condition(s) to the next pipeline stage. Best suited to optimize the                                 pipeline.Put the $match criteria in the beginning of the pipleline to minimize                   the amount of processing down the pipe.
  • $group - Groups documents by some specified expression and outputs to the                             next stage a document for each distinct grouping. The output documents                       contain an _id field which contains the distinct group by key. The output                       documents can also contain computed fields that hold the values of some                     accumulator expression grouped by the $group‘s _id field.                                            $group does not order its output documents.
  • $sort  -    Sorts all input documents and returns them to the pipeline in sorted order.

    Aggregation Pipeline framework:

   The aggregation pipeline is a framework for data aggregation modeled on the concept of      data processing pipelines. Documents enter a multi-stage pipeline that transforms the
   documents into an aggregated results.

   The MongoDB aggregation pipeline consists of stages. Each stage transforms the 
    documents as they pass through the pipeline. Pipeline stages do not need to produce
   one output document for every input document; e.g., some stages may generate new
   documents or filter out documents. Pipeline stages can appear multiple times in the 
   pipeline.

   Aggregation pipeline have some limitations on value types and result size, these limits
   are:
  
  •  Pipeline stages have a limit of 100 megabytes of RAM. If a stage exceeds       this limit,  MongoDB will produce an error. This is resolved by using  allowDiskUse option which enables aggregation pipeline stages to write data to temporary files.
  • If the size of document that contains the complet result set exceeds 16 MB size, then the aggregate commands produces an error. This can be solved if the command return a cursor or store the results to a collection.

  Aggregation Expressions:

  The following are the most commonly use aggregation expression in the MongoDB's aggregation  d  framework:

  • $sum: Calculates and returns the sum of all the numeric values that result                                 from applying a specified expression to each document in a group of                              documents that share the same group by key. This is an accumulator                            operator and is available in the $group stage only.
  • $avg:  Returns the average value of the numeric values that result from applying a                  specified expression to each document in a group of documents that share the              same group by key. $avg ignores non-numeric values. This is an accumulator              operator and is available in the $group stage only.
  • $min:  Returns the lowest value that results from applying an expression to each                     document in a group of documents that share the same group by key. This is               an accumulator operator and is available in the $group stage only.
  • $max: Specify a $max value to specify the exclusive upper bound for a specific index               in order to constrain the results of find(). The $max specifies the upper bound             for all keys of a specific index in order.
  • $push: The $push operator appends a specified value to an array. If the field is                        absent in the document to update, $push adds the array field with the value as              its element. If the field is not an array, the operation will fail.If the value is an                array, $push appends the whole array as a single element.
  • $addtoSet: The $addToSet operator adds a value to an array only if the value                                 is not already in the array. If the value is in the array, $addToSet does not                     modify the array. $addToSet only ensures that there are no                                           duplicate items added to the set and does not affect existing duplicate                           elements. $addToSet does not guarantee a particular ordering of                                   elements in the modified set. If the field is absent in the document to                             update, $addToSet creates the array field with the specified value as its                       element. If the field is not an array, the operation will fail.
  • $first:       Returns the value that results from applying an expression to the first                             document in a group of documents that share the same group by key.                           Documents must be in sorted order to work.Available only in the $group                       stage.
  • $last:     Returns the value that results from applying an expression to the last                            document in a group of documents that share the same group by key.                          Documents must be in sorted order to work. Available only in the $group                       stage.

   Special Pipleline Stage Aggregation Operator -  $unwind:


Applicable to those documents which are stored in an array.Deconstructs an array field from the input documents to output a document for each element.Each output document is the input document with the value of the array field replaced by the element.

The $unwind stage has the following prototype form:

                                         { $unwind: }
To specify a field path, prefix the field name with a dollar sign $ and enclose in quotes.

Behaviors

$unwind has the following behaviors:

  • If a value in the field specified by the field path is not an array, db.collection.aggregate() generates an error.

  • If you specify a path for a field that does not exist in an input document, the pipeline ignores the input document and will not output documents for that input document.

  • If the array holds an empty array ([]) in an input document, the pipeline ignores the input document and will not output documents for that input document.

In the next post, I will show how to write queries using aggregate operators and how to work on the dataset to sum,average, finding min and max from the documents of a collection.





Th