Mongodb - NoSql Database
-
Upload
prashant-gupta -
Category
Software
-
view
151 -
download
1
Transcript of Mongodb - NoSql Database
Prashant Gupta
Introduction to NoSQL
What is NoSQL? It’s a whole new way of thinking about a database and encompasses a wide variety of
different database technologies.
A non-relational and largely distributed database system that enables rapid and analysis of extremely high-volume, disparate (different) data types.
Why NoSQL? The Benefits of NoSQL : A very flexible and schema-less data model, horizontal
scalability, distributed architectures.
• Dynamic Schemas
• Auto-sharding
• Replication
• Integrated Caching
Document databases pair each key with a complex data structure known as a document. Documents can contain many different key-value pairs, or key-array pairs, or even nested documents.
Graph stores are used to store information about networks, such as social connections. Graph stores include Neo4J and HyperGraphDB.
Key-value stores are the simplest NoSQL databases. Every single item in the database is stored as an attribute name (or "key"), together with its value. Examples of key-value stores are Riak and Voldemort. Some key-value stores, such as Redis, allow each value to have a type, such as "integer", which adds functionality.
Wide-column stores such as Cassandra and HBase are optimized for queries over large datasets, and store columns of data together, instead of rows
SQL Database NoSQL Database
Types One type (SQL database) with minor variations
Many different types including key-value stores, document databases, wide-column stores, and graph databases
Development History Developed in 1970s to deal with first wave of data storage applications.
Developed in 2000s to deal with limitations of SQL databases, particularly concerning scale, replication and unstructured data storage.
Examples MySQL, Postgres, Oracle Database
MongoDB, Cassandra, HBase, Neo4j ,Riak, Voldemort, CouchDB ,DynamoDB
Schemas Structure and data types are fixed in advance.
Typically dynamic. Records can add new information on the fly, and unlike SQL table
Scaling Vertically Horizontally
Data Manipulation Specific language using Select, Insert, and Update statements, e.g. SELECT fields FROM table WHERE…
Through object-oriented APIs
Relational and NoSQL data models are very different. The relational model takes data and separates it into many interrelated tables that contain rows and columns. Tables reference each other through foreign keys that are stored in columns as well.
NoSQL databases have a very different model. For example, a document-oriented NoSQL database takes the data you want to store and aggregates it into documents using the JSON format.
History :
Development of MongoDB began in October 2007 by 10gen. The first public release was in February 2009.
What is MongoDB MongoDB is an open-source document database that provides
• High performance
• High availability
• Automatic scaling and sharding
MongoDb is a Open Source database written in C++.
Drivers and client libraries are typically written in their respective languages, although some drivers use C extensions for better performance.
MongoDB does not support SQL It supports a rich, ad-hoc query language of its own.
MongoDb stores data as documents. So it is a document oriented database.
Document Database A record in MongoDB is a document, which is a data structure composed of field and
value pairs. MongoDB documents are similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents.
Licensing and supportMongoDB is available for free under the GNU Affero General Public License.
he language drivers are available under an Apache License. In addition, MongoDB Inc. offers commercial licenses for MongoDB.
Installation :To install the MongoDB on windows or Linux , first download the latest release of MongoDB from
http://www.mongodb.org/downloads
Create Database
MongoDB use DATABASE_NAME is used to create database. The command will create a new database, if it doesn't exist otherwise it will return the existing database.
To check your currently selected database use the command- db
If you want to check your databases list, then use the command- show dbs.
MongoDB db.dropDatabase() command is used to drop a existing database.
Create Collection MongoDB db.createCollection(name, options) is used to create collection.
In the command, name is name of collection to be created. Options is a document and used to specify configuration of collection
INSERT & FIND OPERATION To insert data into MongoDB collection, you need to use MongoDB's insert() method.
Syntex :db.COLLECTION_NAME.insert(document)
$set operator to insert or update the document
Syntex :db.COLLECTION_NAME.update(SELECTIOIN_CRITERIA, UPDATED_DATA)
db.mycol.update({'title':'MongoDB Overview'},{$set:{'title':'New MongoDB Tutorial'}
db.mycol.update({'title':'MongoDB Overview'},{$set:{'title':'New MongoDB Tutorial'}},{multi:true})
The remove() Method MongoDB's remove() method is used to remove document from the
collection. remove() method accepts two parameters. One is deletion criteria and second is justOne flag
Syntex:
db.COLLECTION_NAME.remove(DELLETION_CRITTERIA)
db.mycol.remove({'title':'MongoDB Overview'})