mongoDB Aggregations: Query and Make developers' life easier...

When working with mongoDB aggregations, there will be some situations that you have to write lengthy and complex aggregations.
As an example I wrote following aggregation:


Which is bit complex, lengthy and time consumed to write.
And when this convert to C# it is another time consuming task.

The above Aggregation query was write in C# as bellow:


As you can see it is very lengthy.
So what is the problem now ?

Problem... 

Think there is a requirement to modify this query to get some other data, or what if there is a bug ?
Debugging and modifying this type of code is really gives you a headache; if you DON'T HAVE the mongoDB Aggregation query script saved!

If you don't have the script saved you have to convert the C# query to mongoDB Aggregation which is can do but which consumes too much time !

Solution

In order to save time and make life easier save the query when you write this kind of complex query follow the easy steps bellow:

1. Save your query
I use 'MongoChef' (https://studio3t.com/) as the mongoDB Database Management Tool.
From there I can save whatever the queries that I write as .json file.



2. Attach your saved query to the Task or Ticket.
I use Visual Studio Team Services (https://www.visualstudio.com/team-services/) to manage our work at office.
So for every Task, Bug or Feature I have a Ticket Number.
So, go to your Ticket Management system, in my case VS Team Services and attach the saved query to that ticket.



3. Comment the Ticket Number 
In your Code write the Ticket Number within comments.
So later you or any other developer can easily find the saved script from the Ticket management tool.



4. Maintain the saved query
This is really important.
When you download the script and do any changes to the script don't forget to do the above steps.
Update the script with the changes if you have done any.

IF you follow those steps I'll pretty sure you will be able save additional development time.

Happy Coding... :)









Comments

Popular posts from this blog

Deploy Angular 8 app to Azure with Azure DevOps

Apache ActiveMQ 5 with .Net Core 3.1 and C#

Firebase with.Net Core and C#