How to deal with MongoDB shell output in your shell scripts – Part 2/2: parsing JSON with jq

If you read my last post, you now know how to get a valid JSON output from your MongoDB shell.

But raw JSON is often useless in your scripts because you have to manipulate it to extract only the information you need.

For this purpose, I personalty use a free tool called “jq“. It is very powerful and has many advanced features. I will only show you some basic concepts that will allow you to simply deal with JSON data in your scripts.

Continue reading “How to deal with MongoDB shell output in your shell scripts – Part 2/2: parsing JSON with jq”

How to deal with MongoDB shell output in your shell scripts – Part 1/2: produce valid JSON output

Today, I will show you how to easily deal with MongoDB shell output in your shell (bash, ksh, …) scripts.

For readybility purpose, this topic will be divided into 2 posts. This part will focus on how to produce valid JSON output from your MongoDB shell using the “–eval” option. Second part will focus on how to use “jq” to manipulate JSON data.

Continue reading “How to deal with MongoDB shell output in your shell scripts – Part 1/2: produce valid JSON output”

COUNT and “GROUP BY” with awk

I want to share with you a small shell script that I often use for reporting purposes, which allows you to simulate the famous “count and group by” well known from DBAs. No database is required. It only use “awk” which is installed with each Linux / Unix distribution (I think?), so you can use it “out of the box”.

In other words: the script allows you to count the number of time a word appears in a text file and display a formatted result.

Continue reading “COUNT and “GROUP BY” with awk”