softwaremom

Just another WordPress.com site

Started to learn MongoDB

I temporarily put aside my quest on Hadoop and dabbled in MongoDB a little this week, just because I wanted something less frustrating.

MongoDB is relatively easy to get into.   You download the file, unzip it, created a directory dedicated as the data folder and another for the log folder.  You can setup a mongod.cfg file for basic configuration for the MongoD.exe, the services engine listening on the port.

MongoD runs as a Windows service.  To install it, open a cmd prompt window, run as Administrator and type

  • Bin\mongod.exe –config c:\learn\mongoDb\mongod.cfg –install

The config file needs to be in absolute path.  If not, it needs to be set that way in the registry.

Open a command line prompt.  Run Mongo.  That’s the client.  It present you with a console to write your command.  The code is in Java.  Will find out whether it supports C#.

Default to test as database.

  • db for show the current opened database.
  • Dbs shows all the databases
  • Use <database> to create and open a new database

Instead of table, MongiDb has collections.

  •  db.<collection>.insert(<something>)

Generate data in a loop

  • for (var i = 1; i <= 25; i++) db.testData.insert( { x : i } )

Show data with

  • db.testData.find()

It will show all the objects in testData.  It does by pages.  Need to type “it” to go to another page

That’s it so far.

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

%d bloggers like this: