MongoDB find match in array of objects || MongoDB where condition with array of objects | $elemMatch or dot notation match

In MongoDB, $elemMatch and dot notation are used to find the match in the array of objects. But both have some difference.
Let me explain this with an example. Let say we have a document like:

Now let me find the class name whose students has scored greater than 86.

If using the dot notation then here is the example:

The result will be :

Now If I find the class name whose students has scored greater than 86 and their section is A by using dot notation.

The result will be:

Hence if we are using dot notation, Any condition match in students array, like score or section will be returning document.

But what if we wanted to match every condition?  The answer is: We use $elemMatch for that. ...  Read More

Share This:

TypeScript Interfaces | Why use interfaces in angular typescript

  • An interface defines the syntax that an entity must have to follow.
  • Interfaces are only at compile time.
  • Interfaces contain only the declarations of the members.
  • A deriving class must define the required members.
  • It is also helpful in providing a structure.

Let me give you an example with users interface: i-users.ts

And now let say we have a users service and inside that, we have a function 'updateUser' to update the user info.


Here in the above code snippet, we are passing a parameter userData of type IUsers. This means we can not pass any other format except the IUsers.
But did you notice we have a question mark (?) at property phone and which means phone is optional.

So I can pass data something like:

Here above userData is valid data to pass the API.
Now let's have another example of invalid parameters:

Here this is invalid data because we have not declared the city in our interface and that's why this will result in an error at compile time.

Interfaces are also helpful when sometime we forgot to pass a required parameter and this will help you at the compile time by telling that a particular member is not defined. ...  Read More

Share This:

Angular 8 feature | Using loadChildren to Lazy-Load your Module | Angular 8 dynamic EcmaScript imports

Lazy loading is the beautiful feature which Angular provides. We can load the modules only when the user navigates to their routes for the
first time. It will increase the application performance and also will reduce the initial bundle size.
The Angular Router has always supported lazy loading but now in Angular 8, we can dynamically import the lazy-loaded module only when it is needed.
It is promise based and gives you access to the module whenever the module is called.

Let's create a transaction module for demonstrating the angular 8 dynamic EcmaScript imports:

This will create a transaction list, detail and create components. ...  Read More

Share This:

Push multiple objects into MongoDB array document | Append Multiple Objects to an Array in MongoDB

Normally we use $push to push or append the element or object into an array in mongoDB. But sometime we may need to push the multiple objects into mongoDB array document. Here below I'll try to explain how we can do that.

Let say I have a collection of favorite products and the collection name is favorite_products.

Now in the above document, I wanted to push/append the multiple user objects into the users array whose product id is 124.

 ...  Read More

Share This:

MongoDB distinct with array of objects | Getting distinct values from object array MongoDB

Let say we have a collection transactions which contains some document and documents contain payments which is array of objects.
Now my task is to get the unique types in payments array of every document.

Expected Result: Debit Card, Internet Banking, Credit Card, UPI

which is unique values of payment types in transctions collection and the MongoDB query for that is given below:

Here we first unwind the data so that every payments array can be converted to objects and then we are grouping the type of payments document in transctions collection. ...  Read More

Share This:

FFMPEG installation on centos 6 and centos 7 | How to install FFMPEG on centos | FFMPEG merge videos

As we know FFMPEG is a great tool to deal with multimedia data like video, audio and images. Usually I use FFMPEG on ubuntu servers but somehow I got a project which was already developed and was running on centos server.

My task was to combine them multiple .webm video files into a single video file.

In first attempt I generally installed the FFMPEG by using the following command "yum install ffmpeg". Definitely I was having root user access. But I was getting libvpx encoder error and VP8 and VP9 not supported errors. ...  Read More

Share This:

JavaScript Promise Example | JavaScript Promises | Promise.all() | Promise.race()

In JavaScript we uses promises for handling async API calls.  In JavaScript the  Promise takes one argument as a callback containing 2 parameters resolve and reject.

If promise is fulfilled the resolve function will be called and if promise is not fulfilled  reject function will be called.

Let me explain with some example:

Here in this example I have defined 2 promises one is classResult and other is gotMedal. classResult and gotMedal returns promises. If promise resolved then code block executes else catch code block executes. ...  Read More

Share This:

React application setup with webpack 4 and babel 7 | React setup from scratch | React setup tutorial


Now a days React.js is very popular library for the front end developers. Today I'm going to discuss a very important topic to start the react.js development.

Just to start with React.js we should know how to setup react js application.

I'm assuming you have installed node.js and NPM in your system.

Actually there are 2 ways to setup the react.js application at your system.

  1. React.js provides you facility to create the react application through the CLI (command line interface). Let me tell you how ? You know you just need to run only 2 command and you are ready for development.

    You'll can install create-react-app globally to your system so that in future you will not need to install it again. What you will need is just type create-react-app your-app-name .Here my-app is your application name. You can change it whatever name you wanted to your application.
  2. You can setup the react application with your custom configuration with the help of webpack and babel. Without going more theoretical let me explain the steps to setup the react application using webpack and babel.


Let suppose I have a directory react-setup and I'm into this directory.

Create a file named as package.json and inside package.json I have added all the dependencies which I need to run a react application. I also have setup the script commands for running project in development and to create the production build.

Now go to project directory which is react-setup. And run the command

This will install all the dependencies inside node_modules folder. All the dependencies has been added in package.json ...  Read More

Share This:

Switch PHP Versions on Ubuntu | How can I downgrade from PHP 7 to PHP 5.6 on Ubuntu 16.04? | How to install PHP on Ubuntu?

We often work on multiple projects and there might be possibility the you are working on a project which has been developed in latest PHP version and another project has been developed in older PHP version.

I faced the same challenge in my projects and here in this article I'll explain the installation of PHP version 7.0 and 5.6.

We also will be upgrading and downgrading PHP versions. We will not uninstall and PHP version we will keep both versions of PHP but we will switch PHP version according to our need. ...  Read More

Share This:

Securely Hash Passwords with PHP | How to work with users' passwords and how to securely hash passwords in PHP?

Hashing passwords with md5 (or sha1, or even sha256) is not safe anymore, because these hashes can be decrypted very easily.This is still not good enough though (rainbow tables). PHP 5.5+ came with a password_hash function to generate secure, one-way hashing along with a password_verify function to match a hashed password with the given password. For a developer security is always a priority so you should always be securely storing user passwords. We has passwords due to security concern and information leakage concern. If we store passwords in plain text then it can be compromised of information very easily. ...  Read More

Share This: