Sunday, October 6, 2019

How to solve : Ubuntu MongoNetworkError and to start MongoDB server on system start?

If you get en error such as:

(node:6468) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
Server is running on port 8000
(node:6468) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]

This is actually not an error... What happens here is that Mongo relies on a daemon in order to run the local database server, so in order to "fire up" the mongo server in your shell, you have to start the mongo service first.

1 sudo service mongod start
2 mongo
And there you have it! the server is going to run. Now, If you want Mongo service to Start when the system boots then you have to run:
systemctl enable mongodb.service

Best way to Install ROBOMONGO Program Into UBUNTU Using Command Line

1. Download tar.gz file from Official robomongo website(choose version you need to install and get it's tar.gz download file url)
wget https://download.robomongo.org/0.9.0/linux/robomongo-0.9.0-linux-x86_64-0786489.tar.gz
2. Extract tar.gz file
 tar -xvzf robomongo-0.9.0-linux-x86_64-0786489.tar.gz
3. Move files and folders into the result folder from extraction operation into folder robomongo under /usr/local/bin
sudo mkdir /usr/local/bin/robomongo
sudo mv  robomongo-0.9.0-linux-x86_64-0786489/* /usr/local/bin/robomongo
4. Make sure excute file for robomongo program which exists under/usr/local/bin/robomongo/bin folder is excutable file
cd /usr/local/bin/robomongo/bin
sudo chmod +x robomongo ## run command only if robomongo isn't excutable file
./robomongo

Monday, September 30, 2019

Javascript in 5 Minutes - My understanding


Types

Javascript has nine types. They are:

1. Null –’ is a keyword in JavaScript that signifies ‘no value’ or nonexistence of any value.
2. Undefined – undefined. What you get if you ask an object for something it doesn’t have.
3. Strings – e.g. ’Abc’, "Abc" (single vs. double quotation marks makes no difference). 
4. Numbers – JavaScript has only one type of number. Numbers can be
written with or without decimals.
5. Booleans – represents one of two values: true or false. ex:Boolean(10 > 9)   
    // returns true
(10 > 9)              // also returns true
10 > 9                // also returns true
6. Arrays – JavaScript arrays are used to store multiple values in a
single variable e.g. var arr = [1, 2, 3, 4];
7. Objects – Objects are variables too. But objects can contain many values.
This code assigns many values (Fiat, 500, white) to a variable named car:
var car = {type:"Fiat", model:"500", color:"white"};
8. Regular expressions – Regular expressions are patterns used to match character
combinations in strings. 
Ex: var regex = /ca[kf]e/;
    var str = "He was eating cake in the cafe.";
            if(regex.test(str)) {
        document.write("Match found!");
    } else {
        document.write("Match not found.");
    }

9. Functions – function is defined with the function keyword, followed by a name,
followed by parentheses ().
e.g. var x = myFunction(4, 3);
function myFunction(a, b) {
  return a * b;
}

null

The value null is actually almost never produced by Javascript. The only case you’re likely to run across null is if you assign it somewhere (most of the time you’ll get undefined instead – one notable exception is document.getElementById, which returns null if it can’t find an element). Making sparing use of undefined and instead using null can make bugs much easier to track down.

Case Sensitivity

JavaScript is a case-sensitive language. This means that the language keywords,
variables, function names, and any other identifiers must always be typed with a
consistent capitalization of letters

Variables

Variables can be thought of as named containers. You can place data into these containers
and then refer to the data simply by naming the container. Before you use a variable in
a JavaScript program, you must declare it. Variables are declared with the var keyword.
Global Variables: A global variable has global scope which means it can be defined
anywhere in your JavaScript code.  Local Variables: A local variable will be visible
only within a function where it is defined. Function parameters are always
local to that function.

Reserved Words

A list of all the reserved words in JavaScript are given in the following table.
They cannot be used as JavaScript variables, functions, methods, loop labels, or
any object names

 OPERATORS

  • JavaScript supports the following types of operators.
  • Arithmetic Operators
  • Comparison Operators
  • Logical (or Relational) Operators
  • Assignment Operators
  • Conditional (or ternary) Operators

 Arithmetic Operators

Assume variable A holds 10 and variable B holds 20, then: 
+ (Addition) Adds two operands 
Ex: A + B will give 30
- (Subtraction) Subtracts the second operand from the first Ex: A - B will give -10
* (Multiplication) Multiply both operands 
Ex: A * B will give 200
/ (Division) Divide the numerator by the denominator
Ex: B / A will give 2
% (Modulus) Outputs the remainder of an integer division
Ex: B % A will give 0
++ (Increment) Increases an integer value by one
 Ex: A++ will give 11
-- (Decrement) Decreases an integer value by one Ex: A-- will give 9
/ (Division) Divide the numerator by the denominator
Ex: B / A will give 2
% (Modulus) Outputs the remainder of an integer division
Ex: B % A will give 0
++ (Increment) Increases an integer value by one
 Ex: A++ will give 11
-- (Decrement) Decreases an integer value by one Ex: A-- will give 9

Comparison Operators

Assume variable A holds 10 and variable B holds 20, then:

== (Equal) Checks if the value of two operands are equal or not, if yes,
then the condition becomes true.
Ex: (A == B) is not true.
!= (Not Equal) Checks if the value of two operands are equal or not,
if the values are not equal, then the condition becomes true. 
Ex: (A != B) is true.
> (Greater than) Checks if the value of the left operand is greater than
the value of the right operand, if yes, then the condition becomes true. 
Ex: (A > B) is not true.
< (Less than) Checks if the value of the left operand is less than the
value of the right operand, if yes, then the condition becomes true. 
Ex: (A < B) is true.
>= (Greater than or Equal to) Checks if the value of the left operand
is greater than or equal to the value of the right operand, if yes,
then the condition becomes true. 
Ex: (A >= B) is not true.
<= (Less than or Equal to) Checks if the value of the left operand is
less than or equal to the value of the right operand, if yes, then the condition
becomes true. 
Ex: (A <= B) is true.

Logical Operators

&& (Logical AND)
If both the operands are non-zero, then the condition becomes true.
Ex: (A && B) is true.
|| (Logical OR) If any of the two operands are non-zero, then the condition becomes true. 
Ex: (A || B) is true.
! (Logical NOT) Reverses the logical state of its operand. If a condition is true,
then the Logical NOT operator will make it false. 
Ex: ! (A && B) is false.

Conditional Operator (? :)

The conditional operator first evaluates an expression for a true or false value and then
executes one of the two given statements depending upon the result of the evaluation
? : (Conditional ) If Condition is true? Then value X : Otherwise value Y

if-else

JavaScript supports the following forms of if..else statement −

  •  if statement
  •  if...else statement
  •  if...else if... statement.
 if statement The if statement is the fundamental control statement that allows
JavaScript to make decisions and execute statements conditionally.
var age = 20;
if( age > 18 ){
document.write("<b>Qualifies for driving</b>");
}
if..else statement: The 'if...else' statement is the next form of control statement that allows JavaScript to execute statements in a more controlled way
var age = 15;
if( age > 18 ){
document.write("<b>Qualifies for driving</b>");
}
else{
document.write("<b>Does not qualify for driving</b>");
}


if...else if... statement

The if...else if... statement is an advanced form of if…else that allows JavaScript
to make a correct decision out of several conditions.
var book = "maths";
if( book == "history" ){
document.write("<b>History Book</b>");
}
else if( book == "maths" ){
document.write("<b>Maths Book</b>");
}
else if( book == "economics" ){
document.write("<b>Economics Book</b>");
}
else{
document.write("<b>Unknown Book</b>");
}

How to solve : Ubuntu MongoNetworkError and to start MongoDB server on system start?

If you get en error such as: (node:6468) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be re...