How to install specific MongoDB Version

Generally to install MongoDB we use the following command.

If you want to install specific version of mongodb, for example if you want install 3.4.0 version you can use the following command.

In the same way if we want to install any version of mongodb we can use this format.

Solution: zsh: command not found: mongod

If MongoDB is not installed properly in the system, then this error comes on command prompt. To fix this problem follow the below steps.

Try to install MongoDB by using Homebrew. Before that ensure Homebrew is installed or not by using the following command.

If Homebrew is not installed, install it. After completion of Homebrew installation, Add MongoDB to Homebrew’s list of packages by using the following command.

Install the latest version of MongoDB with the following command.

Now check with the command mongod in the command prompt. Now it won’t show the error message as command not found.

Javascript program to find the sum of elements in a sequence up to a given range.

  • From the above program we need to ensure that the range should not exceed the length of the array. If it is exceeding we will assign the range to the array length.
  • Given range is 5. So the sum of first five elements should calculate as 4 + 7 + 6 + 1 + 2 which is equal to 20.

We can also write this program by using slice and reduce methods as follows

  • Here arr.slice(0, range) extracts the elements from 0 to 5. i.e, [4, 7, 6, 1, 2];
  • reduce method starts with an initial value of 0 and adds each number to the accumulator and returns 20 as the output.

JavaScript code to find How many times the highest score and the lowest score record is broken

  • From the given scores initial score is 7 and the next highest score Record is 16 and this record is broken by the score 23 and this record is broken by 25. So total 3 times the highest score record broken.
  • In the same way the initial score is 6 and the next lowest record is 5 and this record is broken by the score 2. So total 2 times the lowest score record broken.

Find the largest and smallest numbers in an array in JavaScript using Math.max() and Math.min().

  • Here, spread operator converts an array into individual arguments.
  • So Math.max and Math.min expect a list of arguments, not an array directly.
  • For small and medium size arrays Math.max and Math.min are the simplest and most effective way.
  • For Large Arrays we need to use Array.reduce() for better performance.
  • And most importantly Math.max and Math.min works only for array of numbers.