[FSF Associate Member] View Annang Sowah's profile on LinkedIn
Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Monday, 25 July 2016

MongoDB, BigData and Mungo Park :)
Setup, Start, Query and Stop MongoDB

Hello Folks,
Per my exposure and excitement in relation to Big Data and its utilization in industry and programming especially, I have decided to share a couple of blog postings about same. 

I will focus on MongoDB considering its amazing prospect as one of the leading NoSQL databases in recent years in the Big Data stack of "databases".
The NoSQL regime of data storage has enjoyed massive adoption as a result of its scalability, speedy data retrieval and cloud-ready features it has on offer.
MongoDB, to start with, is a document-based database. It stores data modeled textually according to a format which doesn't even need to be pre-defined.

Dont forget to download  and install your mondgo db binaries from the mongo folks online.

I will start today with the basic setup of the MongoDB in a Windows 10 environment.

First of all, lets create a Windows Service that will enable us start the MongoDB daemon processes with ease.

1. Create a configuration file to host your data and log files. 
You can label the file mongod.cfg and put the content below therein

systemLog:
    destination: file
    path: D:\Tech\DB\mongodb\data\log\mongod.log
storage:
    dbPath: D:\Tech\DB\mongodb\data\db

2. We will now proceed to create the windows service called MongoDB.
Take note of the location of your mongod.cfg file and also your install location of MongoDB - mine is C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe.

The syntax for the service creation is 

sc.exe create SERVICE_NAME binPath= "MONGOD_LOCATION --service --config=\"CONFIG_FILE_LOCATION\"" DisplayName= "SERVICE_NAME_ALIAS" start= "auto"

The actual command, as executed on my PC, is as shown below. Note: Run this command as an administrator(open cmd prompt as an administrator)

sc.exe create MongoDB binPath= "C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe --service --config=\"D:\Tech\DB\mongodb\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"

3. You are now be ready to start the MongoDB service.

Run net start MongoDB on command line.













4. Start the MongoDB shell to kickstart your running of  "nosql" queries.

Note: Please put the Mongo bin folder(C:\Program Files\MongoDB\Server\3.2\bin) on the system path or as an environment variable for Windows OS. This enables you to access the various executable files easily on the command line with no need of typing the full path.

Run mongo













The mongo shell should be ready to accept your queries.

5. Now query the mongo database.
  • to display the available databases (only ones with data get shown ), type show dbs
  • to use a particular database, type use database_name
  • to see the current database in use, type db
     









Lets try some data manipulation: Insert my name in the new database sampledb. 
type  db.sampledb.insert({"name":"Joseph Annang Sowah"}).
This creates a new collection to contain my name ;)
   

6. Lets create a database called softwareSolutions and insert the details of software creators in a collection(pseudo table) called creators. 


NB. databases and collections are created automatically with the use of the use and insert statements

7. Multiple sets of data can be inserted by separating brackets({}) with commas(,) as shown below

8. Lets display the data we have so far in our softwareSolutions mongo database.
This can be done crudely using the find() function.

To have the display formatted, one can attach pretty() to the earlier command
9. Since we have a duplication of Cagatay Civici, let have one deleted. This done by specifically removing the objectId of one of the Cagatay Civici entries.

Now lets re-display the content of the creators collection.

10. Lets quit the mongo shell. To quit the shell, type exit

11. Finally, after quiting the mongo shell, lets stop the MongoDB windows service.
    Command is net stop MongoDB


Bye, thanks for your time.

...and take note, the good old Mungo Park has nothing to to with MongoDB, but about his adventures and exploits you can follow this link :)



Friday, 21 March 2014

[SOLVED] NTFS Disk Mount Issues on Linux on a "Dual-Booted" Computer.

Good day, Fellas!

Background: I made an installation of Windows Server 2012 on an NTFS partition I originally allocated from an existing Ubuntu Linux 13.10 disk (dual-booting means getting a computer host 2 Operating Systems).
Upon accessing the NTFS disk from  the Ubuntu Linux OS I had an error message that implied that the disk has an unclean file system or is in an unsafe state.Below is the error thrown when the host Ubuntu Linux OS attempts to mount the NTFS partition.
















Fig.1  Error encountered whiles accessing NTFS partition

Cause: This is caused by a recent tweak of the Microsoft OS(Windows 8, Windows Server 2012) simply called Fast-Startup ( which involved the saving of device(RAM, CPU, Disk) boot metadata(e.g. registry boot parameters) on files during shutdown, to be accessed at the next startup to shorten boot-time) which puts a "lock" on the NTFS partitioning hence posing a difficulty when opening disk.

Solution: 
FROM WINDOWS:  From your windows OS environment,  access the Power Options under control panel. Move down to the shutdown settings panel where you can disable the Fast-Startup by dis-selecting the "Turn on Fast startup".

FROM LINUX: We would use the software package called ntfs-3g which has a powerful binary called ntfsfix. Lets first install the package using the super-user priviledge and command below.

# sudo apt-get install ntfs-3g

Lets next confirm if the installation has been successful by checking the man pages(i.e. utility  manual pages) for ntfsfix 

# man ntfsfix













Fig.2  NTFSFIX utility manual on Linux.

Now, lets proceed to run the utility to fix the issue snapped above by simply :) running

# sudo ntfsfix /dev/sda3
Where sda3 is the ntfs partition of the disk that you have difficulties opening.
















Fig.3  NTFSFIX utility run  on Linux without errors.

Verify if the partition is accessible - as I have done below.










Fig.4  Partition is now fully accessible.


Issue solved, hopefully :)