How to install MongoDB on Ubuntu 20.04

In this article, We will learn how to install MongoDB on Ubuntu 20.04 LTS step by step.

MongoDB is one of the most popular NoSQL databases, it is open source and freely available to download. It stores data in the form of flexible documents like JSON rather than the usual table style method found in SQL databases.

Continue reading How to install MongoDB on Ubuntu 20.04

How to install Apache Cassandra on CentOS or Redhat

In this article, we will see how to install Apache Cassandra on CentOS or Redhat.

1. Java should be there on Linux machine to install Apache Cassandra. Lets verify java installed or not.

java -version

How to install Apache Cassandra on Redhat or CentOS
Continue reading How to install Apache Cassandra on CentOS or Redhat

What is the difference between Stored Procedure and Trigger in SQL

In this article, we will see the difference between Stored Procedure and Trigger in SQL. Following are the main differences between Stored Procedure and Trigger:

Continue reading What is the difference between Stored Procedure and Trigger in SQL

Stored Procedure Trigger
Store Procedures are invoked explicitly Triggers are invoked implicitly
Stored procedure is a user defined piece of code which may return a value (making it a function) that is invoked by calling it explicitly. A trigger is a stored procedure that runs automatically when various events happen (eg update, insert, delete).

What is the difference between synchronous and asynchronous Replication

Following are the difference between synchronous and asynchronous Replication.

1. Asynchronous Replication: There is delay between Master and Slave(Secondary). In this data can be replicated after the transaction has been committed on the master. Which means the slave is never ahead of the master. So, in the case of writing it is usually a little behind the master. This delay also called lag.

2. Synchronous Replication: Continue reading What is the difference between synchronous and asynchronous Replication

What is the difference between union and join

Following are the differences between union and join in relational database engines.
A union returns the results of two different queries as a single recordset and A join allows you to relate similar data in different tables.

UNION JOIN
UNION puts lines from queries after each other, JOIN makes a cartesian product and subsets it
Union Operation is combined result of the Vertical Aggregate of the rows JOIN Operation is combined result of the Horizontal Aggregate of the Columns
Union combines rows JOIN links the rows
Performed only on two similar structures Performed only on two dissimilar structures also
A union returns the results of two different queries as a single recordset. A join allows you to relate similar data in different tables.

Visual depiction of a join. Table A and B’s columns are combined into a single result:

Continue reading What is the difference between union and join

How to get all collections from all databases in MongoDB

In this article, we will see how to get all collections from all databases in in MongoDB Server. We can get all databases and the collections in them by using db.getMongo() and db.getDBNames() methods with forEach method.

1. Run the following command from mongo shell.
Continue reading How to get all collections from all databases in MongoDB

How to copy a collection from one database to another in MongoDB

In this article, we will see how to copy a collection from one database to another in MongoDB. As a maintenance activity its routine task to copy a collection from one database to another database in MongoDB Server.

Syntax to copy a collection from one database to another in MongoDB:

db.collection_name.find().forEach(function(d){ db.getSiblingDB('target_db')['collection_in_target'].insert(d); });

Continue reading How to copy a collection from one database to another in MongoDB

How to move a collection from one database to another in MongoDB

In this article, we will see how to move a collection from one database to another in MongoDB. As a maintenance activity its routine task to move a collection from one database to another database in MongoDB Server.

Move a collection from one database to another in MongoDB Syntax:

We must run the below command in admin database only.

db.runCommand({renameCollection: 'db1.source_collection', to: 'db2.target_collection'})

Continue reading How to move a collection from one database to another in MongoDB

How to Backup and Restore MongoDB database

In this article, we will see the steps to Backup and Restore MongoDB database. It is important to take regular backups of our system. Backups are good protection against most types of failures.

mongodump tool is used to take backup of MongoDB database or collection or subset of collection.
mongorestore tool is used to restore database or collection on the target database.

mongodump Syntax:

mongodump [options]

Few options are:

–authenticationDatabase
–db
–username
–password
–out
–host
–uri
–collection
–query
–archive
–oplog
–dumpDbUsersAndRoles
–excludeCollection

MongoDB backup examples:

Continue reading How to Backup and Restore MongoDB database

MongoDB error connecting to host: could not connect to server: server selection error: server selection timeout

In this article, we will see to troubleshoot the problem for connectivity between different MongoDB servers. I got below error when tried to restore database from local to remote host.

2019-11-20T15:56:59.536-0800 error connecting to host: could not connect to server: server selection error: server selection timeout current topology: Type: Single Servers: Addr: 192.168.152.141:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection(192.168.152.141:27017[-121]) connection is closed

Continue reading MongoDB error connecting to host: could not connect to server: server selection error: server selection timeout