MongoDB
Basics
Kazi Ataul Bari
What is MongoDB
MongoDB is an open-source document database
Purpose to build MongoDB
Scalability
Performance
High Availability
History of MongoDB
MongoDB began in 2007 Thanks: http://www.javatpoint.com
Terminology and Concepts
MySQL MongoDB
1. MongoDB is an open-source database developed by
MongoDB, Inc.
2. MongoDB stores data in JSON-like documents that
can vary in structure.
3. MongoDB uses dynamic schemas, meaning that
you can create records without first defining the
structure, such as the fields or the types of their
values.
1. MySQL is a popular open-source relational database
management system (RDBMS).
2. MySQL stores data in tables and uses structured
query language (SQL) for database access.
3. In MySQL, related information may be stored in
separate tables, but associated through the use of
joins.
Sources: https://www.mongodb.com/compare/mongodb-mysql
Compare
MySQL MongoDB
Sources: https://www.mongodb.com/compare/mongodb-mysql
Table Collection
Row Document
Column Field
Joins Embedded documents, linking
Are MongoDB and MySQL used together?
Many e-commerce applications use a combination of MongoDB and MySQL.
The product catalog, which includes multiple products with different attributes, is a good fit for MongoDB’s
flexible data model.
On the other hand, the checkout system, which requires complex transactions, would likely be built on
MySQL or another relational technology.
How to install MongoDB on Windows
MongoDB folder
Sources: https://www.mongodb.com/compare/mongodb-mysql
Create a Database
There is no create database command in MongoDB. Actually, MongoDB do not
provide any command to create database.
use myNewDB
db.myNewCollection1.insert( { x: 1 } )
check the database
check the database Name
>db
check the database list
>show dbs
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(JavaScript Object Notation) objects.
Sources: https://www.mongodb.com/compare/mongodb-mysql
Databases and Collections
MongoDB stores in collections; the collections in databases. Collections are analogous to tables in
relational databases.
Sources: https://www.mongodb.com/compare/mongodb-mysql00
create collection
>db.createCollection("IGU")
check the created collection
>show collections
create collection automatically
>db.IGU2020.insert({"name" : "MSIT"})
>show collections
insert()
db.users.insert({name: "sue", age: 25, status: "A"})
https://docs.mongodb.com/v3.2/crud/
Create an array of documents
var AllcoursesIGU =
[
{ "city" : "AGAWAM", "loc" : [ -72.622739, 42.070206 ], "pop" : 15338, "state" :
"MA", "_id" : "01001" },
{ "city" : "CUSHMAN", "loc" : [ -72.51564999999999, 42.377017 ], "pop" : 36963,
"state" : "MA", "_id" : "01002" },
{ "city" : "BARRE", "loc" : [ -72.10835400000001, 42.409698 ], "pop" : 4546,
"state" : "MA", "_id" : "01005" },
{ "city" : "BELCHERTOWN", "loc" : [ -72.41095300000001, 42.275103 ], "pop" :
Inserts the documents
> db.igu.insert( AllcoursesIGU );
> db.igu.find()
Read Operations: find()
>db.users.find()
Comparison Query Operators
$eq Matches values that are equal to a specified value.
$gt Matches values that are greater than a specified value.
$gte Matches values that are greater than or equal to a specified value.
$lt Matches values that are less than a specified value.
$lte Matches values that are less than or equal to a specified value.
$ne Matches all values that are not equal to a specified value.
Comparison Query Operators
db.igu.find( { state: { $eq: "MA" } } )

MongoDB

  • 1.
  • 2.
    What is MongoDB MongoDBis an open-source document database Purpose to build MongoDB Scalability Performance High Availability History of MongoDB MongoDB began in 2007 Thanks: http://www.javatpoint.com
  • 3.
    Terminology and Concepts MySQLMongoDB 1. MongoDB is an open-source database developed by MongoDB, Inc. 2. MongoDB stores data in JSON-like documents that can vary in structure. 3. MongoDB uses dynamic schemas, meaning that you can create records without first defining the structure, such as the fields or the types of their values. 1. MySQL is a popular open-source relational database management system (RDBMS). 2. MySQL stores data in tables and uses structured query language (SQL) for database access. 3. In MySQL, related information may be stored in separate tables, but associated through the use of joins. Sources: https://www.mongodb.com/compare/mongodb-mysql
  • 4.
    Compare MySQL MongoDB Sources: https://www.mongodb.com/compare/mongodb-mysql TableCollection Row Document Column Field Joins Embedded documents, linking
  • 5.
    Are MongoDB andMySQL used together? Many e-commerce applications use a combination of MongoDB and MySQL. The product catalog, which includes multiple products with different attributes, is a good fit for MongoDB’s flexible data model. On the other hand, the checkout system, which requires complex transactions, would likely be built on MySQL or another relational technology.
  • 6.
    How to installMongoDB on Windows
  • 7.
  • 8.
  • 9.
    Create a Database Thereis no create database command in MongoDB. Actually, MongoDB do not provide any command to create database. use myNewDB db.myNewCollection1.insert( { x: 1 } )
  • 10.
    check the database checkthe database Name >db check the database list >show dbs
  • 11.
    Document Database A recordin MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB documents are similar to JSON(JavaScript Object Notation) objects. Sources: https://www.mongodb.com/compare/mongodb-mysql
  • 12.
    Databases and Collections MongoDBstores in collections; the collections in databases. Collections are analogous to tables in relational databases. Sources: https://www.mongodb.com/compare/mongodb-mysql00
  • 13.
    create collection >db.createCollection("IGU") check thecreated collection >show collections
  • 14.
  • 15.
    insert() db.users.insert({name: "sue", age:25, status: "A"}) https://docs.mongodb.com/v3.2/crud/
  • 16.
    Create an arrayof documents var AllcoursesIGU = [ { "city" : "AGAWAM", "loc" : [ -72.622739, 42.070206 ], "pop" : 15338, "state" : "MA", "_id" : "01001" }, { "city" : "CUSHMAN", "loc" : [ -72.51564999999999, 42.377017 ], "pop" : 36963, "state" : "MA", "_id" : "01002" }, { "city" : "BARRE", "loc" : [ -72.10835400000001, 42.409698 ], "pop" : 4546, "state" : "MA", "_id" : "01005" }, { "city" : "BELCHERTOWN", "loc" : [ -72.41095300000001, 42.275103 ], "pop" :
  • 17.
    Inserts the documents >db.igu.insert( AllcoursesIGU ); > db.igu.find()
  • 18.
  • 19.
    Comparison Query Operators $eqMatches values that are equal to a specified value. $gt Matches values that are greater than a specified value. $gte Matches values that are greater than or equal to a specified value. $lt Matches values that are less than a specified value. $lte Matches values that are less than or equal to a specified value. $ne Matches all values that are not equal to a specified value.
  • 20.
    Comparison Query Operators db.igu.find({ state: { $eq: "MA" } } )

Editor's Notes

  • #2 MongoDB tutorial provides basic and advanced concepts of SQL. Our MongoDB tutorial is designed for beginners and professionals. MongoDB is a No SQL database. It is an open-source, cross-platform, document-oriented database written in C++. Our MongoDB tutorial includes all topics of MongoDB database such as insert documents, update documents, delete documents, query documents, projection, sort() and limit() methods, create collection, drop collection etc. There are also given MongoDB interview questions to help you better understand the MongoDB database.
  • #3  MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling. In simple words you can say that - Mongo DB is a document oriented database. It is an open source product, developed and supported by a company named 10gen. MongoDB is available under General Public license for free and it is also available under Commercial license from the manufacture. The manufacturing company 10 gen has given the definition of Mongo DB: "Mongo DB is scalable, open source, high performance, document oriented database." - 10 gen MongoDB was designed to work with commodity servers. Now it is used by company of all sizes, across all industry. Purpose to build MongoDB This may be a very genuine question that - "what was the need of MongoDB although there were many databases in action?" This is a very simple answer: All the modern applications require big data, fast features development, flexible deployment and the older database systems not enough competent, so the MongoDB was obviously needed. Main purpose to build MongoDB: Scalability Performance High Availability Scaling from single server deployments to large, complex multi-site architectures. Key points of MongoDB Develop Faster Deploy Easier Scale Bigger