Playing around with MongoDB – Part 1: setup

This is just a pointer blog to the mongoDB documentation and a basic guide to getting started with using MongoDB on the local system and playing around with it.

Lets first install MongoDB on the Mac and then make a sample app using it.

1.) Installation :
We can use brew to install mongoDB on the mac. Installation instructions can be found here.

Anirudhs-MacBook-Pro:~ anirudh$ brew install mongodb

By default mongodb uses the folder /data/db for the database, so make sure that the directory exists and has all the permissions required.

Once db folder is set, we can run mongodb by the command :

Anirudhs-MacBook-Pro:~ anirudh$ mongod

This will start the mongodb server listening at port 27017.

Once the server is up, we can open a mongo shell to perform the db operations just like using a mysql client.

Login to mongo shell

Anirudhs-MacBook-Pro:~ anirudh$ mongo
MongoDB shell version: 2.6.3
connecting to: test
Welcome to the MongoDB shell.

We can use the help command to see all the operations like create databases, indexes, insert rows, etc.

Lets see few basic examples which can be helpful for our stint with mongo:

To display the database we are using:

 db

To use the database

use <database>

To view all the collections in the db

db.getCollectionNames()

To find

db.collection.find()

More details of getting started are well documented at the mongodb site here.

In the next blog we will make a spring application talk to mongo DB.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s