Skip to main content


Showing posts from January 18, 2019

MongoDB - Basic Commands


These are the basic MongoDB commands we use in our day-today work. Adding as a reference to myself :)

Create database use DATABASE_NAME
$ use my_database

Show databases $ show dbs

Connect to database use DATABASE_NAME
$ use my_database

Drop database db.dropDatabase()

$ db.products.({ name: "Fruit Juice" })

Show collections $ show collections

Drop collection db.COLLECTION_NAME.drop()
$ db.products.drop()

Insert document db.COLLECTION_NAME.insert(DOCUMENT)
$ db.products.insert({
item_name: "Frui Juice",
item_description: "sdfsdklf",
price: "100"

Read document db.COLLECTION_NAME.find()
$ db.products.find().pretty()
$ db.products.find({ item_name: "Fruit Juice" }).pretty()

Like statement - we have to use regex
$ db.products.find( { item_name: { $regex: /789$/ } } )

      $and: [
         { key1: value1 }, { key2:value2…

Java Concurrency - Executor Framework


What is the basic abstraction for creating threads in Java? Is it new Thread(new Runnable()) ? NO. It is Executors!
Decoupling is a good programming practice and it is better to separate thread creation from the application. Java's way of encapsulating these functions are known as executors. (Executors)

Executor InterfacesExecutor - simple interface used to submit new tasksExecutorService - sub interface of Executor which supports life cycle management of both of the tasks and Executor itself.ScheduledExecutorService - sub interface of ExcecutorService which supports task scheduling.
ExecutorService This has more features than Executor interface. Mainly it support thread pooling, return the result via Callable, shutting down the service.
This has following implementations in java.util.concurrent package.
Creating a ExecutorService can be done using Executors factory c…