What is NoSQL?
NoSQL is a kind of database that, unlike most relational databases, does not provide a SQL interface to manipulate data. NoSQL databases usually organize the data in a different way other than tables.
NoSQL databases are divided into three categories: column-oriented, key-value pairs, and document-oriented databases.
SQL based relational databases do not scale well when they are distributed over multiple cluster nodes. Data partition is not an easy to implement solution when the applications use join queries and transactions.
NoSQL databases are not new. Actually, there were key-value pair based databases before relational database became popular.
What is a document-oriented database?
For document-oriented databases, a document is a data structure that has variable number of properties. Each property has a value that can be scalar (number, string, etc.) or a vector (arrays or objects).
You can see a document as an object or associative array like in PHP. To understand better this concept, here is the definition of a "person" document:
$person = array( "name" => "Cesar Rodas", "country" => "Paraguay", "languages" => array("Spanish", "English", "Guarani"), );Documents do not have a predefined schema like relational database tables. Documents can have multiple properties. Documents can also be grouped in collections. The term collection is used from now on distinguish from the tables used by relational databases to store records with a fixed number of fields.
Another important characteristic of documents is that they can have sub-documents. Sub-documents are used in the place parent-child tables used with relational databases.
MongoDB (from “humongous”) is a scalable, high-performance, open source NoSQL database. MongoDB is non-relational (no joins) so references (“foreign keys”) between documents are generally resolved client-side by additional queries to the server (“linking”).
MongoDB is a very interesting document-oriented database implementation for several reasons:
- - It uses JSON, instead of XML
- - It is fast, as it is written in C++
- - Supports index definitions
- - Provides an easy to use query interface, very similar to some database abstraction layers
- - Supports operations with sub-documents
- - Provides a native PHP extension
- - Supports auto-sharding
- - Supports map-reduce for data transformation
There is one library out there - Alex Bilbi has a lib that works just fine and YES you can go almost like ActiveRecord. You can view by clicking below link.
CodeIgniter MongoDB Library
This is an active record inspired CodeIgniter library to integrate a MongoDB database into your application.
Installing this library is as simple and painless as installing MongoDB - really a piece of cake.