Showing posts with label MongoDB DBA. Show all posts
Showing posts with label MongoDB DBA. Show all posts

Monday, 10 June 2013

Brief Overivew of MongoDB (NoSQL)

MongoDB is very powerful document oriented database; Discuss some of the basic concepts.

• A document is the basic unit of data for MongoDB, roughly equivalent to a row in
 a relational database management system like oracle or mysql.

• Similarly, a collection can be thought of as the schema-free equal to a table.

• A single instance of MongoDB can host multiple independent databases, each of
 which can have its own collections and permissions.

• MongoDB comes with a simple but powerful JavaScript shell, which is useful for
 the administration of MongoDB instances and data manipulation.

• Every document has a special key, "_id", that is unique across the document’s
 collection.

Collections
A collection is a group of documents. If a document is the MongoDB same as of a row
in a relational database, then a collection can be like a table in oracle or mysql.

Documents
MongoDB is the concept of a document: an ordered set of keys with associated values.

A document differs by programming language, means row in a table(rdbms)
but most languages have a data structure that is a natural fit, such as a map, hash, or
dictionary.

In JavaScript, for example, documents are represented as objects:
{"Welcome" : "Good morning!!"}

This simple document contains a single key, "welcome", with a value of " Good morning!!".

Most documents will be more complex than this simple one and often will
contain multiple key/value pairs:

{" Welcome " : " Good morning!!", "Header" : 1}

Schema-Free
Collections are schema-free. This means that the documents within a single collection
can have any number of different “shapes.”
For example, both of the following documents could be stored in a single collection:
{" Welcome " : “Good morning!!"}
{" Header" : 1}

Naming
A collection is identified by its name. Collection names can be any UTF-8 string, with a few restrictions:

The empty string (" ") is not a valid collection name.
• Collection names may not contain the character \0 (the null character) because this   
 delineates the end of a collection name.

Note:- Not recommendable create any collections that start with system., a prefix reserved for system collections. For example, the system.users collection contains the database’s users and the system.namespaces collection contains information about all of the database’s collections.

• User-created collections should not contain the reserved character $ in the name.
 The various drivers available for the database do support using $ in collection
 names because some system-generated collections contain it. You should not use
 $ in a name unless you are accessing one of these collections.

Subcollections

One convention for organizing collections is to use namespaced subcollections separated by the character.

For example, an application containing a blog might have a
collection named blog.posts and a separate collection named blog.authors.
This is for organizational purposes only—there is no relationship between the blog.

• GridFS, a protocol for storing large files, uses subcollections to store file metadata
separately from content chunks.
• The MongoDB web console organizes the data in its DBTOP section by
subcollection
• Most drivers provide some syntactic sugar for accessing a subcollection of a given
collection. For example, in the database shell, db.blog will give you the blog collection,
and db.blog.posts will give you the blog.posts collection.


Subcollections are very good way to organize data in MongoDB, and their use is highly
recommended.

This is good for Social network, blogs and game related applications.

Databases

Set of documents is grouped by collection and groups collections into
databases.A single instance of MongoDB can host several databases, each of which can be thought of as completely independent.

A database has its own permissions, and each database is stored in separate files on disk. A good rule of thumb is to store all data for a single application in the same database.
Separate databases are useful when storing data for several application or users on the same MongoDB server.
Like collections, databases are identified by name. Database names can be any UTF-8
string,

with the following restrictions:
• The empty string (" ") is not a valid database name.
• A database name cannot contain any of these characters: ' ' (a single space), ., $, /,
  \, or \0 (the null character).
• Database names should be all lowercase recommended.
• Database names are limited to a maximum of 64 bytes.

There are also several reserved database names, which you can access directly but have special rules.

These are as follows:
admin
This is the “root” database, in terms of authentication. If a user is added to the
admin database, the user automatically inherits permissions for all databases.
There are also certain server-wide commands that can be run only from the admin
database, such as listing all of the databases or shutting down the server.

local
This database will never be replicated and can be used to store any collections that
should be local to a single server.

config
When Mongo is being used in a sharded setup , the config database
is used internally to store information about the shards.

By prepending a collection’s name with its containing database, you can get a fully
qualified collection name called a namespace.
For instance, if you are using the blog.posts collection in the dev database, the namespace of that collection would be dev.blog.posts. Namespaces are limited to 121 bytes in length and, in practice, should be less than 100 bytes long.

MongoDB Installation Step by Step on Windows

Installation of MongoDB
Download the latest production release of MongoDB from the
There are three builds of MongoDB for Windows:

MongoDB Steps
• MongoDB for Windows Server 2008 R2 edition only runs on Windows Server 2008 R2,Windows 7 64-bit, and newer versions of Windows. This build takes advantage of recent enhancements to the Windows Platform and cannot operate on older versions of
Windows.

• MongoDB for Windows 64-bit runs on any 64-bit version of Windows newer than
Windows XP, including Windows Server 2008 R2 and Windows 7 64-bit.
• MongoDB for Windows 32-bit runs on any 32-bit version of Windows newer than
Windows XP. 32-bit versions of MongoDB are only intended for older systems and for use in testing and development systems.

Note:-
MongoDB Version 2.2: MongoDB does not support Windows XP.
Prefer recent version of Windows to use more recent releases of MongoDB.
Note:-  Always download the correct version of MongoDB for your Windows system.
64-bit versions of MongoDB will not work with 32-bit Windows.
32-bit versions of MongoDB are suitable only for testing and evaluation purposes and only support databases smaller than 2GB.

You can find the architecture of your version of Windows platform using the following
command in the Command Prompt
runprompt>wmic os get osarchitecture

Extract the archive to C:\ by right clicking on the archive and selecting Extract All and browsing to C:\

Note: The folder name will be either:

C:\mongodb-win32-i386-[version] Or C:\mongodb-win32-x86_64-[version]
In both examples, replace [version] with the version of MongoDB downloaded.
Set up the Environment Start the Command Prompt by selecting the Start Menu,
then All Programs, then Accessories, then   right   click   Command Prompt, and select Run as Administrator from the popup menu. In the Command Prompt,                                                                                        issue  the following commands:
cd \
move C:\mongodb-win32-* C:\mongodb
Note:   MongoDB is self-contained and does not have any other system dependencies.
You can run MongoDB from any folder you choose. You may install MongoDB in any
directory (e.g. D:\test\mongodb)
MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is C:\data\db.

Create this folder using the run prompt. Issue the following sequence:
md data
md data\db

Note:   You may specify an alternate path for \data\db with the dbpath
setting for mongod.exe as in the following example:
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data
If your path includes spaces, enclose the entire path in double quotations, for example:
C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"
Start MongoDB
To start MongoDB, execute from the Command Prompt:
C:\mongodb\bin\mongod.exe

This will start the main MongoDB database process. The waiting for connections
message in the console output indicates that the mongod.exe process is running successfully.
Note: Depending on the security level of your system, Windows will issue a Security Alert dialog box about blocking "some features" of C:\mongodb\bin\mongod.exe from communicating on networks.
All users should select Private Networks, such as my home or work network and click allow access.                                                                                        
For additional
information on security and MongoDB, please read the Security Practices and Management
Warning: Do not allow mongod.exe to be accessible to public networks
without running in "Secure Mode" MongoDB is designed to be run in "trusted environments" and the database does not enable authentication or "Secure Mode" by default.
Connect to MongoDB using the mongo.exe shell. Open another Command Prompt and
issue  the following command:
C:\mongodb\bin\mongo.exe

Note: Executing the command start C:\mongodb\bin\mongo.exe will automatically
start the mongo.exe shell in a separate Command Prompt window.
The mongo.exe shell will connect to mongod.exe running on the localhost
interface and port 27017 by default.

Connected test default database and inserting test records and retrieve the records.
> db.test1.save( { qateam: 1 } )
> db.test1.save( { devteam: 2 } )
> db.test1.save( { BIteam: 3 } )
> db.test1.find()


Installation and testing completed.


Popular Posts