Friday, October 10, 2014

Windows 8 MongoDB in secure mode

  • add auth=true in mongo.cfg file
  • Start mongod.exe in console or use windows service configured in (
  • Start mongo.exe in another console
  • use admin
  • db.addUser("user","password")
  • use test
  • db.auth("user","password")
  • db.addUser("testuser","testpassword")
  • Now test db is accessible using username/password only

Thursday, October 9, 2014

Java code to generate BigDecimal Random value

To generrate BigDecimal between 0 to defined range use following code:

private BigDecimal randomNo(int range) {

        BigDecimal rangeInBD = new BigDecimal(range);
        BigDecimal randomNoGeneration = new BigDecimal(Math.random()); // between 0 to < 1.0
        BigDecimal actualRandonNo = randomNoGeneration.multiply(rangeInBD);
        return actualRandonNo.setScale(2, BigDecimal.ROUND_HALF_UP);


Wednesday, October 8, 2014

MongoDB windows 8 installation

  • Download from
  • Install downloaded msi
  • Move installed directory from default location C:\Program Files\MongoDB 2.6 Standard to your user defined location, something without space in naming convention, this is a good practice. Copying the installed folder to another location will not create any issue as MongoDB is self-contained and does not have any other system dependencies. For example: C:\poc\mdb\MongoDB_2.6_Standard
  • Create a  mongo.cfg file with content:
##store data here (make sure you have manually created following directory)

##all output go here (make sure you have manually created following directory)
  • Open command prompt (WIN +X ) and open Comman Prompt (Admin)
  • Type following:
sc.exe create MongoDB binPath= "\"C:\poc\mdb\MongoDB_2.6_Standard\bin\mongod.exe\" --service --config=\"C:\poc\mdb\mongod.cfg\"" DisplayName= "MongoDB_2.6_Standard" start= "auto" 
  • MongoDB service is successfully installed if you see following msg:
[SC] CreateService SUCCESS
  • Start MongoDB service:
net start MongoDB
  • To stop MongoDB service:
net stop MongoDB
  • To delete MongoDB service
sc.exe delete MongoDB