Total Visitors

Sunday, January 21, 2018

MongoDB : Basic Information

This is a small tutorial to learn the basics of MongoDB. The market for nosql is booming a lot! 
Its always good to have a basic idea about various nosql databases.

Installation with macOS:


  1. Try to install mongoDB through brew (software package management system that simplifies the installation of software on Apple MacOS)
  2. Go to https://brew.sh/ , copy paste the Terminal prompt command and run it on the mac terminal.
  3. Run command: "brew install mongodb" on your terminal.
  4. Make the data directory "mkdir -p /data/db"
  5. Change the Owner "sudo chown nelson /data/db"
  6. To see the databases created, type the command "show dbs"
  7. In order to create a new db and/or to switch to another db, type in the terminal "use test_1" (here while typing this for the first time, the 'test_1' db is created as well as it will switch the db to 'test_1')
Now these are few basic operations:

1.     Show the document with db.test_1.find()
2.     Update the database to allow a list of references
          nelsonDB.references = [ ]
              db.test_1.update({"name" : "Nelson"}, nelsonDB)
              db.test_1.find() // Will show the updated document

3.     Show the document with db.test_1.find()

4.     Update the database to allow a list of references

nelsonDB.references = [ ]
db.test_1.update({"name" : "Nelson"}, nelsonDB)

db.test_1.find() // Will show the updated document

5.     Use remove to delete the documents or with a parameter to delete just the one that matches

db.test_1.remove({"name" : "Nelson"})

db.test_1.find() // Will not show any result

6.     Data Types

a. null : {"name" : null}
b. boolean : {"currentEmp" : true}
c. number : (64 bit float) : {"height" : 6.25}
                  1. 4 byte Int : {"bigint" : 92949455}
                  2. 8 byte Long : {"bigLong" : 78443435227370955145644}
d. string : {"address" : "N Avenue"}
e. Array containing multiple datatypes : array : {"grades" : ["a", "b", "c", "d"]}
f.  Date object : {"hiredate" : new Date()}
g. Regular expression : {"addressregex" : /^[A-Za-z0-9\.\' \-]{4,33}$/}
h. Embedded document : {"info" : {"name" : "Baker Smith"}}
i. Object id (Unique for every document) : 12 Byte ID for documents

j. Randomdata = {"name" : null, "over20" : true, "height" : 6.25,
"bigint" : 92949455, "bigLong" : 78443435227370955145644,
"address" : "N Avenue", "grades" : ["a", "b", "c", "d"],
"hiredate" : new Date(), "streetregex" : '/^[A-Za-z0-9\.\' \-]{5,30}$/',
"info" : {"name" : "Baker Smith"}}

More about MongoDB


Create a User with Roles:

db.createUser ({
                  user: "Nelson",
                  pwd: "1234"
                  roles: ["readWrite”""dbAdmin"]

});

Create a User without Roles:

db.createUser ({
                  user: "Nelson",
                  pwd: "1234",
                  roles: []

});

Note*: If you type pass instead of pwd, it will throw the following error:
Error: couldn't add user: "pass" is not a valid argument to createUser 

Collections are very similar to tables in database:

Create a collection:
db.createCollection('customers');
show collections

And insert few values:
db.customers.insert({"firstName":"John", "lastName":"Baker"})

db.customers.find()

If we need to add multiple row, use array
db.customers.insert([{"firstName":"Sarah", "lastName":"Anderson"},{"firstName":"Steve", "lastName":"Joseph",gender:"Male"}])

Output:
db.customers.find().pretty()

{
"_id" : ObjectId("5a668d7608220527b462d543"),
"firstName" : "John",
"lastName" : "Baker"
}
{
"_id" : ObjectId("5a668ebc08220527b462d544"),
"firstName" : "Sarah",
"lastName" : "Anderson"
}
{
"_id" : ObjectId("5a668ebc08220527b462d545"),
"firstName" : "Steve",
"lastName" : "Joseph",
 "gender" : "Male"

}


Note*: Here we can see that we can add one more field called "gender" into the document.


Now to update it always try to use the objectId instead of any first_name as reference. Just for understanding purpose I have taken first_name as a reference.

db.customers.update({"firstName":"Steve"}, {"firstName":"Steve", "lastName":"Joseph",gender:"Female"})


Note*: If we just use db.customers.insert({"firstName":"Steve"}, {gender:"Female"}) , it will replace the whole thing with just {gender:"Female"}

SET:

There is a way where this situation can be avoided, that is by using SET 

db.customers.update({"firstName":"Steve"}, {$set:{gender:"Female"}})

We can update a new field into it:

db.customers.update({"firstName":"Steve"}, {$set:{age:49}})

Increment age by 1:
db.customers.update({"firstName":"Steve"}, {$inc:{age:1}})


{
"_id" : ObjectId("5a668d7608220527b462d543"),
"firstName" : "John",
"lastName" : "Baker"
}
{
"_id" : ObjectId("5a668ebc08220527b462d544"),
"firstName" : "Sarah",
"lastName" : "Anderson"
}
{
"_id" : ObjectId("5a668ebc08220527b462d545"),
"firstName" : "Steve",
"lastName" : "Joseph",
"gender" : "Male",
"age":50
}

UNSET:
db.customers.update({"firstName":"Steve"}, {$unset:{age:1}})
Age will be deleted from the document.

UPSERT:
If the item is not found during the update then by using UPSERT it will add the items if matching items is not available.

db.customers.update({"firstName":"Job"}, {"firstName":"Job", "lastName":"Martin"},{upsert:true});

After executing this a new document will be added.

RENAME:
db.customers.update({"firstName":"Steve"}, {$rename:{gender:"sex"}})

output:
{
"_id" : ObjectId("5a668d7608220527b462d543"),
"firstName" : "John",
"lastName" : "Baker"
}
{
"_id" : ObjectId("5a668ebc08220527b462d544"),
"firstName" : "Sarah",
"lastName" : "Anderson"
}
{
"_id" : ObjectId("5a668ebc08220527b462d545"),
"firstName" : "Steve",
"lastName" : "Joseph",
"sex" : "Female"
}
{
"_id" : ObjectId("5a668f1108220527b462d547"),
"firstName" : "Steve",
"lastName" : "Joseph",
"gender" : "Male"
}
{ "_id" : ObjectId("5a66911708220527b462d548"), "firstName" : "Steve" }
{
"_id" : ObjectId("5a66b4b404b58ba782f4043a"),
"firstName" : "Job",
"lastName" : "Martin"

}

REMOVE:
To remove the document
db.customers.remove({"firstName":"Steve"});

Note*: If the above statement is executed, all the document related to firstName = 'Steve' will be deleted.
So use justOne
db.customers.remove({"firstName":"Steve"},{justOne:true});
This is a kind of safety option which only deletes the first document.

QUERYING the Document:

db.customers.find({firstName:"Sarah"})

OR db.customers.find({$or: [{"firstName":"Steve"},{"firstName":"John"}]});
Greater Than / Less Than


db.customers.find({"age": [{lt:60}]}); // replace lt with gt for finding greater than.

also,
lte - less than or equal to
gte - greater than or equal to

Insert Object
db.customers.update({"firstName":"TinTin"}, {"address":{"street":"S Avenue","city":"tempe","state":"AZ"}},{upsert:true});

find value from inside the object:
db.customers.find({"address.city":"tempe"})

Sort
Sorting the component by lastName.
db.customers.find().sort({lastName:1});

Note*: Here 1 means it is sorted in the ascending order, -1 means descending order.

Count
db.customers.find().count()
specific search:
db.customers.find({gender:"male"}).count()

Limit
db.customers.find({gender:"Male"}).limit(4)

db.customers.find().limit(4).sort({lastName:1})

ForEach
db.customers.find().forEach(function(doc){print("Customer Name: "+doc.firstName)})


output:
Customer Name: John
Customer Name: Steve
Customer Name: Sarah
Customer Name: Steve
Customer Name: Steve
Customer Name: Job



Thursday, January 11, 2018

Sprint Planning Template

Sprint Goals

  • <A successful sprint requires sprint goals. Add them here. Goals may be inspired by retrospective items from the previous sprint, or by milestones that will be completed in this sprint>

Sprint Planning

  • Finalize next sprint backlog.
    • Add project issues.
    • Add ad hoc/sustaining issues (BRING IN PERCENTAGE OF SUSTAINING).
  • Planning with other teams
    • Syseng
      • Any planned events?
  • Validate commitment.
    • Any DTO or other commitments that will lower velocity for the upcoming sprint?
    • Any DTO on or around the next sprint planning (sprint after upcoming one)?
      • If so, it is that person’s responsibility to plan for the next sprint with the scrummaster BEFORE the sprint ends.
    • Any known unplanned work upcoming?
    • How much unplanned work is anticipated. Use “yesterday’s weather”; how much unplanned work came up in the last sprint?
  • Review and update release plan for current projects.
  • Production support for this sprint is ____  (____  to shadow). Production support person accepts unplanned production blocking bugs during the sprint.
    • Production support for last sprint was __% time.
  • Scrummaster for this sprint is _____.

Backlog grooming

  • The team performs backlog grooming continuously through the sprint.
    • All issues for each project in progress have an estimation. Each project’s issues and release schedule are estimated.
    • All issues that will come into the next sprint have requirements and acceptance criteria.
    • All issues have non-functional requirements, such as performance profiling and logging, considered.
    • All projects should have complete user stories for the next sprint.
  • Additionally, there is a team backlog grooming meeting to ensure the top of backlog is in shape for the next sprint.
    • All issues likely to begin work in the next few sprints are moved from LABENG to LABENGDTC.
    • Review ad hoc/sustaining epic report to make sure time spent in this area is as expected.
    • Team understands all stories for the upcoming sprint. Team is OK committing to the work in the stories.

Pencils down

  • The beginning of the sprint review/demo is “pencils down”.
  • Only code that is reviewed, committed/merged to master is demoed and called “done”.
  • For all finished issue
    • Data and code is updated in all environments.
    • Code review is done
    • Code is committed to version control.
  • Issues in any other state are unfinished and move to the next sprint or backlog.

Sprint review/demo

  • For each finished issues, demonstrate all acceptance criteria.
    • What is demoed is releasable--could be released to production immediately if desired.
    • Capture feedback and enter into backlog.
  • For production issues
    • To mark a production issue “done”, there should be a set of bugs or stories that improve or resolve the issue. These issues should be reviewed as the demo.
  • Close all finished issues in last sprint.
  • Move unfinished issues to new sprint or backlog.
  • Observe velocity of last sprint.
  • Update release tags
    • For issues done during this sprint, update the release tag with the planned release date.
    • For the current week’s release, update the release tags for all issues (did we release what we thought we would?). “Release” the release in jira.
    • For issues that will move to the next sprint, update the release tag with the new projected release date.
  • Identify the scrummaster for the following sprint.
  • Close sprint, moving unfinished issues to the next sprint or backlog.

Retrospective

The sprint retrospective is an opportunity to improve the development experience for the team. There are three goals for the retrospective:
  1. Celebrate successes.
  2. Identify opportunities to improve.
  3. Commit to action to improve on the opportunities during the next sprint.
  • What went well?
  • How did we take advantage of opportunities identified in previous sprint’s retrospective?
  • What are opportunities for improvement?
  • Based on those opportunities, what are we committing to do in the next sprint to improve the experience?
  • Scrummaster for the next sprint is ____ .

Saturday, August 5, 2017

The Rise of Cloud Computing and Its Impact on Business and Technology

Cloud computing is a technology that has been rapidly growing in popularity over the past decade. It is a model for delivering computing resources such as servers, storage, and applications over the internet. Instead of owning and maintaining physical hardware and software on-premises, businesses can rent access to these resources from cloud providers, paying only for what they use.

One of the main benefits of cloud computing is its scalability. Businesses can quickly and easily scale up or down their computing resources as their needs change, without the need to invest in additional hardware or software. This makes cloud computing particularly attractive to small and medium-sized businesses, which may not have the resources to invest in expensive IT infrastructure.

Another key advantage of cloud computing is its flexibility. Users can access cloud resources from anywhere with an internet connection, using a variety of devices such as desktop computers, laptops, tablets, and smartphones. This enables remote work and collaboration, making it easier for businesses to work with employees and partners around the world.

Cloud computing has had a significant impact on both business and technology. Here are some of the ways it has changed the landscape:

Cost savings: By renting computing resources instead of owning them, businesses can save significant amounts of money on hardware and software costs, as well as maintenance and support.

Increased agility: Cloud computing allows businesses to quickly and easily adapt to changing market conditions, scaling up or down their resources as needed to meet demand.

Improved collaboration: Cloud computing enables remote work and collaboration, making it easier for teams to work together across locations and time zones.

Greater innovation: By removing the need to invest in expensive IT infrastructure, cloud computing allows businesses to focus on innovation and growth, developing new products and services and bringing them to market more quickly.

Enhanced security: Cloud providers invest heavily in security measures to protect their customers' data, often providing more robust security than businesses can achieve on their own.

Green computing: Cloud providers can achieve economies of scale by consolidating computing resources, and reducing energy consumption and carbon emissions.

However, cloud computing also presents some challenges and risks. One of the biggest concerns for businesses is the security of their data. While cloud providers generally invest heavily in security measures, businesses must also take steps to ensure the security of their own data, such as encrypting sensitive information and using strong authentication methods.

Another challenge is the complexity of managing cloud resources. As businesses adopt multiple cloud providers and services, it can be difficult to manage and monitor all of these resources effectively. This has led to the rise of cloud management platforms and tools that help businesses to manage their cloud resources more easily.

Overall, cloud computing has had a significant impact on both business and technology, enabling businesses to be more agile, innovative, and collaborative, while reducing costs and improving security. As cloud computing continues to evolve and mature, it is likely to play an even greater role in shaping the future of business and technology. 

Sunday, March 16, 2014

Spring 4.0 MVC Example

Here I will show you how to create a simple example by using Spring MVC.
I will be creating this example without the help of xml, i.e whole configuration is done using pure Java.
Just copy paste the content and you yourself google it out to understand the code.
Note* this application is working fine with GlassFish applicaiton server.

1) Instead of web.xml write the class Initializer.java 

package com.spring.init;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class Initializer implements WebApplicationInitializer {

@Override
public void onStartup(ServletContext servletContext) throws ServletException {

AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(WebAppConfig.class);

ctx.setServletContext(servletContext);

Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
servlet.addMapping("/");
servlet.setLoadOnStartup(1);
}
}

2) Instead of servlet-context.xml

package com.spring.init;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.JstlView;
import org.springframework.web.servlet.view.UrlBasedViewResolver;

@Configuration //Specifies the class as configuration
@ComponentScan("com.spring") //Specifies which package to scan
@EnableWebMvc //Enables to use Spring's annotations in the code
public class WebAppConfig {
@Bean
public UrlBasedViewResolver setupViewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setPrefix("/WEB-INF/pages/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
return resolver;
}
}

3) Define your controller class.

package com.spring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class SpringController {
@RequestMapping(value="/hello-page")
public ModelAndView goToHelloPage() {
ModelAndView view = new ModelAndView();
view.setViewName("hello"); //name of the jsp-file in the 'page' folder

String str = "Finally Spring 4.0 Working !";
view.addObject("message", str); //adding of str object as 'message' parameter

return view;
    }
}

4) hello.jsp 

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

    <p>Hello world: ${message}</p>
    <p>Nice!</p>

5) index.jsp (Run this and Enjoy!)

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<h1>Home page</h1>
<p>This is a Home Page.</p>
<p><a href="hello-page.htm">Hello world link</a></p>