MongoDB – How to Add Arbiter to Replica Set

This blog represents the instructions on how to add arbiter to existing Mongodb replica set. Arbiters are MongoDB instances whose primary role is to participate in replica set election in order to break ties and select PRIMARY.This instance do not hold any data and have minimal resource requirements. As a matter of fact, it does not need or require a dedicated hardware to run. However, it is advised to run arbiter on different server than the replica set. It can be any other server such as application server or monitoring server. Further details can be found on this page. Configure Arbiter Data Storage An arbiter does not store data. However, …

Continue reading

Posted in MongoDB, NoSQL. Tagged with , .

MongoDB – Top 10 Best Practices for AWS Production Deployments

The following are some of the best practices which should be considered for your MongoDB production deployments on AWS. File system: MongoDB recommends using either of XFS or EXT4 filesystem for greater performance. With WiredTiger storage engine, it is strongly recommended to go with XFS file system. Refer this page, MongoDB production notes for finer details. AWS EBS (Elastic Block Store) Configuration EBS-optimized instances: It is advisable to use EBS optimized instances to host MongoDB database. With EBS optimized instances, there are separate network interfaces for database, and, other traffic (application traffic). In case, the replica set is configured with ephemeral storage, at least one of the secondaries in the …

Continue reading

Posted in AWS, MongoDB, NoSQL. Tagged with , , .

MongoDB – Not Master and SlaveOk Error Message

When trying to access MongoDB database collection data using command such as show collections on one of the secondary member of the replica set, error message such as not master and slaveOk=false occurs. Following screenshot represents the same: Following command when executed on secondaries resolves the above shown error: rs.slaveOk();

Posted in MongoDB, NoSQL. Tagged with , .

MongoDB – How to Enable Replication (Replica Set)

This blog represents steps required to enable replication in MongoDB when access control is disabled. The related details can be found on the page, Deploy Replica Set. Following are some of the key aspects which need to be understood in relation with MongoDB replica set: MongoDB replicaset consists of odd number of servers. This is done to achieve quorum in order to select a master server when one of the existing master server does down. Following are some of the steps which needed to be done to enable replication with MongoDB: Check MongoDB replication status Install additional Mongodb instances Start each member of replica set Initiate the Replica set Add …

Continue reading

Posted in MongoDB, NoSQL. Tagged with , .

MongoDB – How to Reset Mongo Replica Set

The following instructions would help you to reset MongoDB replica set settings and start over with replication all over again. These are especially helpful for developers starting to learn MongoDB replication. Shut down the mongodb server Start the mongodb server in the standalone mode, e.g., without –replSet <replicaSetName>. Login to Mongodb; You can use admin database Make sure that user has readWrite permission to local database. In case, it is not, use following command to grant the role to the user. The following command gives readWrite permission on local database to admin user. Switch to local database Execute the command to make the cllection such as system.replset empty Make sure that …

Continue reading

Posted in MongoDB, NoSQL. Tagged with , .

MongoDB – How to Create Database Users

First and foremost, one would be required to enable authentication with MongoDB database. The details can be found on this page MongoDB Database – Create User Command Following steps can be used to create a database user: Switch to the desired database. This is same as creating a database. Create user using following command: Above command would create user with with role such as dbOwner. The details on creating users can be found on this page covering the description on creating users – db.createUser() The user with role such as dbOwner can perform any administrative action on the database. The role combines the privileges granted by the readWrite, dbAdmin and …

Continue reading

Posted in MongoDB, NoSQL. Tagged with , .

Angular – How to Create Your First Angular App

This blog represents concepts and commands which would help you setup development environment to build Angular apps. Introduction to Angular CLI Angular CLI is a command line interface for Angular. With Angular CLI commands, the following are some of the key functionality which can be achieved using Angular CLI commands: Create an application that follows best practices recommended by Angular. ng new command is used. Test the app locally as you develop. ng serve is used. Greater details can be found on this page, Angular CLI. The documentation in relation with Angular CLI can be found on this page, Angular CLI Documentation. Install the Angular CLI The following command can …

Continue reading

Posted in Javascript, Web. Tagged with , , , .

Setup Environment for Google AppEngine Java Project

This blog presents tips and techniques on how to set up environment for deploying Java web app on Google AppEngine using GCloud SDK. Same environment can as well be used for deploying Spring boot web app. Following steps are described later: Install Google Cloud SDK Install Cloud SDK Appengine Java component Create Appengine project in Google Cloud Console Authorize GCloud Configure Appengine project using GCloud Install Google Cloud SDK Download and install Google Cloud SDK. The instructions for downloading and installing Google Cloud SDK can be found on Installing Cloud SDK page. Unzip or Untar the downloaded file and go to the google-cloud-sdk folder. Execute install.sh or install.bat appropriately from …

Continue reading

Posted in Cloud, Google Cloud, Java, Web. Tagged with , , .

MongoDB – How to Enable Authentication on Mongo Database

Beginners starting with MongoDB would come across the requirement of enabling authentication on MongoDB database. This blog presents tips and code sample on how to enable login on MongoDB database such that one would require to pass their user credentials in order to access the database. In order to enable authentication for MongoDB databases, following can be done. This would essentially mean that users would have to provide user credentials in order to access a specific database. Otherwise, anyone can access any database using command such as mongo. Apply following changes in /etc/mongod.conf file. Note that mongod.conf is configuration file where other details such as data path can also be found. Start mongodb with –auth option. As …

Continue reading

Posted in MongoDB, NoSQL. Tagged with , .

MongoDB Command to Evaluate Query Performance

Following command can be used to evaluate query performance of a MongoDB Collection: The above command would print result such as following. COLLSCAN represents the collection scan. Query Performance Metrics Following are some of the metrics to watchout for when evaluating query performance: totalKeysExamined: Total number of index entries scanned totalDocsExamined: Total number of documents scanned to find the results. executionTimeMillis: Time required to excute the query

Posted in MongoDB, NoSQL. Tagged with , .

Spring Boot with JSP Pages – Code Example

Following needs to be done to setup Spring boot web app with JSP pages Create a Spring Starter Project Create a Spring Starter Project by selecting “Web” as one of the dependencies. This will create a Springboot project. POM.xml Entries Place following entries in pom.xml for processing JSP pages Configuration in application.properties Place following configuration in application.properties Create Controller class Create a sample controller class such as following: Create JSP pages Create a folder src/main/webapp/WEB-INF/views Create a file index.jsp. Place the content such as following: Run Project as Spring Boot App Access URL such as http://localhost:8080/ in browser. Following would be displayed.

Posted in Java, Web. Tagged with , , .

MongoDB – Evaluate Query Performance using Indexes

This blog represents commands used to manage MongoDB indexes on a particular collection and tips on how to evaluate query performance with or without indexes. Please feel free to suggest. Sorry for typos. Why create indexes? Indexes can significantly improve the read query performance for MongoDB collections. In absence of indexes, when searching for documents based on filter criteria, MongoDB performs collection scan, i.e., scan every document and returns the documents matching the filter criteria. This is not very efficient way of searching the document. In case of one or more fields which are frequently used for filtering out the document, it is recommended to create indexes on those fields. …

Continue reading

Posted in MongoDB, NoSQL. Tagged with , .

Springboot MongoDB Repository – Code Example

This blog represents code required to create a Spring boot application that uses Spring Data MongoRepository interface to connect with MongoDB database. Step 1: Create a Springboot Maven project Create a new Spring Starter Project using Eclipse IDE. This would create a class annotated with @SpringBootAnnotation. Step 2: Include Spring Data Mongo support in pom.xml Step 3: Configure Mongoclient for database connectivity Create a Configuration class which is used to instantiate a MongoClient for connecting with MongoDB database. Step 3: Define MongoDB details in application.properties Step 4: Invoke MongoRepository instance Place following code in SpringBootAnnotation class for invoking MongoRepository instance (UserDAO in the code given below). In ideal scenario, you would want …

Continue reading

Posted in Java, MongoDB, NoSQL. Tagged with , , .

MongoDB – Top 10 Most Common Commands for Beginners

This article represents top 10 most commonly used commands for MongoDB beginners. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Following is the list of these commands: Following is the list of these commands: Login into MongoDB: Following command can be used to login into MongoDB database for a particular database. Make sure that the user with credentials such as username and password exists in the database mentioned in place of dbname. Show all databases: Once logged in as a user with appropriate role as userAdmin or userAdminAnyDatabase, one can see all the databases using command such as …

Continue reading

Posted in MongoDB, NoSQL. Tagged with , .

Configure Bitbucket Webhook to Trigger Jenkins Builds on AWS EC2

This article represents steps required to configure BitBucket Webhook to trigger Jenkins Builds on AWS EC2 based on code committed in the repository. This essentially means that a code commit in the BitBucket code repository would trigger a build in Jenkins server running on AWS EC2 machine. This forms the starting point of continuous delivery pipeline. The jenkins build, when triggered as a result of code push, could perform tasks such as some of the following: Run the build, Run tests Publish build artifacts in artifactory Deploying the build artifacts in different environments including QA, UAT and production. Please feel free to comment/suggest if I missed to mention one or …

Continue reading

Posted in AWS, DevOps, IT Automation. Tagged with , , .

How to Setup Jenkins & GitLab using Docker Containers

This article represents code sample on how to setup Jenkins & GitLab using Docker containers. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Create a docker compose file such as docker-compose.yml with the code given below. Executing command such as “docker-compose up” would lead to creation of two containers, one of which hosts the Jenkins and another one hosts GitLab. The Jenkins can be accessed with URL such as http://localhost:28080. The GitLab can be accessed using URL such as http://localhost. In case of running this docker-compose file on Linux/Ubuntu, change the volume under jenkins from “- /usr/local/bin/docker:/usr/bin/docker” to “- …

Continue reading

Posted in Dockers. Tagged with .