2. What is MongoDB?
It is a NoSQL database
Data is stored in documents, not tables / relations
(Schema free). It uses BSON (binary JSON) format
MongoDB is Implemented in C++ for best performance
Scalable with high-performance (scales horizontally)
Platforms 32/64 bit Windows, Linux, Mac OS-X, FreeBSD,
Solaris
Language drivers for :- PHP, Ruby/Ruby-on-Rails, Java,
C#, JavaScript, C / C++, Python, Perl and much more ! ..
3. Why ?
Cost - MongoDB is free
MongoDb is easily installable.
Super low latency access to your data
− Very little CPU overhead
No Additional caching layer required
Auto Sharding
− Automatic balancing for changes in load and data
distributed
− Easy addition of new machines
− Scaling out to one thousand nodes
− No single points of failure, Automatic fail-over
Built in Replication and Horizontal Scaling support
9. MongoDB Installation
1. Add 10gen package to source.list
sudo gedit /etc/apt/sources.list
Add : deb
http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist
10gen
2. sudo apt-get update
3. 10gen package required GPG key, import it :
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv
7F0CEB10
4. sudo apt-get install mongodb-10gen ---- Done
5. Test : tito@tito:~$ mongo
MongoDB shell version: 2.0.6
connecting to: test
10. PHP Driver Installation
Check that the PEAR and PECL are working with the following
commands:
$ PECL version
If not found, install it to following commands:
sudo apt-get install php-pear
Then, sudo pecl install mongo
Add the following line to your php.ini file:
sudo gedit /etc/php5/apache2/php.ini
extension=mongo.so
Then Restart Web Server
/etc/init.d/apache2 restart ---- DONE
11. Using from Terminal
$ mongo
> show dbs – Get list of all databases
> use microfin – creating DB
> db.users.insert( { _id : "alex", name: { first:"Alex",
last:"Benisson" }, karma : 1.0 } )
> db.users.insert( { name: { first:"Kamal", last:"Khan" }, address
: '33,Dhaka' } )
> show collections – Get collections list
> db.users.find()