Friday, January 20, 2012

Spring MVC 3.1 - Implement CRUD with Spring Data MongoDB (Part 2)

Review

In the previous section, we have laid down the functional specs of the application. In this section, we will learn how to setup a MongoDB server both in Windows and Ubuntu.


MongoDB Setup

We will first tackle how to setup MongoDB in Windows, in particular Windows 7; then we will focus on Ubuntu, in particular Ubuntu 10.04.

Windows 7

To setup a MongoDB server in Windows, follow these steps:

1. Open a browser and visit the MongoDB download section at http://www.mongodb.org/downloads

2. Under the Production Release, choose the file that matches your operating system. In our case, it's Windows 32-bit.

3. Once downloaded, extract the contents of the zip file

4. Open the extracted folder and browse under the bin directory. You should see the following executables

5. Select and run mongod.exe application.

6. You should see a command prompt with a similar output:

Do not close the command prompt. Your MongoDB server is now running.

Note: If the command prompt abruptly appears and then disappears, it's possible that the data/db path is missing in your file system.

To verify this,
  1. Open a new command prompt
  2. Run mongod.exe (either by dragging the executable or typing manually the full path)
  3. Read the error and check if it's similar with the following:
    [initandlisten] exception in initAndListen: 10296 dbpath (/d
    ata/db) does not exist, terminating
    dbexit:
    [initandlisten] shutdown: going to close listening sockets...
    [initandlisten] shutdown: going to flush diaglog...
    [initandlisten] shutdown: going to close sockets...
    [initandlisten] shutdown: waiting for fs preallocator...
    [initandlisten] shutdown: closing all files...
    [initandlisten] closeAllFiles() finished
    dbexit: really exiting now
    
  4. If it's the same message, please proceed below to resolve the issue.

To resolve this issue, follow these steps:
  1. Go to C:\ drive
  2. Create a new folder data
  3. Open data
  4. Create a new folder db
  5. Then run mongod.exe again. You should see MongoDB running now.

Ubuntu 10.04

To setup a MongoDB server in Ubuntu, follow these steps:

1. Open a browser and visit the MongoDB download section at http://www.mongodb.org/downloads

2. Under the Production Release, choose the file that matches your operating system. In our case, it's Linux 32-bit.

3. Once downloaded, extract the contents of the compressed file

4. Open the extracted folder and browse under the bin directory. You should see the following executables. Pay attention to mongod.

5. Let's make mongod executable. There are two ways: GUI and terminal-based

GUI-based:
  1. Right-click on the mongod application
  2. Open the "Permissions" tab.
  3. Ensure that "Allow executing file as program" is checked

Terminal-based:
  1. Open a terminal
  2. Run the following command:
    sudo chmod +x PATH/TO/YOUR/MONGO/bin/mongod
    
    
    Make sure to change the path to your Mongo directory.

6. Open a terminal and run the following command:
PATH/TO/YOUR/MONGO/bin/mongod


7. You should see a similar output indicating that your MongoDB server is now running:

Note: If in case there's an error, make sure that /data/db directory exists in the file system. This is similar with the Windows error above.

Next

In the next section, we will discuss the project's structure and start writing the Java classes. Click here to proceed.
StumpleUpon DiggIt! Del.icio.us Blinklist Yahoo Furl Technorati Simpy Spurl Reddit Google I'm reading: Spring MVC 3.1 - Implement CRUD with Spring Data MongoDB (Part 2) ~ Twitter FaceBook

Subscribe by reader Subscribe by email Share

1 comment: