BIG DATA ANALYTICS
BIG DATA ANALYTICS
UNIT – 4 : MONGODB
Introduction to MongoDB : Definition of MongoDB - Need of MongoDB - Terms used in
RDBMS and MongoDB - Data Types in MongoDB - MongoDB Query Language.
1 Introduction to MongoDB
1.1 Definition of MongoDB
MongoDB is
1. Cross-platform.
2. Open source.
3. Non-relational.
4. Distributed.
5. NoSQL.
6. Document-oriented data store.
• The use myDB command ensures that we are working inside the myDB database.
• Only the active database can be dropped.
Step 2: Try to Update with upsert: false (Document Does Not Exist Yet)
Since Hersch Gibbs does not exist yet, this will not insert a new document.
Command:
> db.Students.update(
{_id: 4, StudName: "Hersch Gibbs", Grade: "VII"},
{$set: {Hobbies: "Graffiti"}},
{upsert: false}
)
Output:
WriteResult({ "nMatched" : 0, "nModified" : 0, "nUpserted" : 0 })
• Since upsert: false, no new document is inserted.
• "nMatched" : 0 → No matching document was found.
• "nUpserted" : 0 → No document was inserted.
Check the Collection Again:
> db.Students.find().pretty()
Output (No change in the collection):
{ "_id" : 1, "StudName" : "Michelle Jacintha", "Grade" : "VII", "Hobbies" : "Internet
Surfing" }
{ "_id" : 2, "StudName" : "Mabel Mathews", "Grade" : "VII", "Hobbies" : "Baseball"
}
{ "_id" : 3, "StudName" : "Aryan David", "Grade" : "VII", "Hobbies" : "Chess" }
{ "_id" : ObjectId("5f4c8e3c2a3aeb5f6b89e4a3"), "StudName" : "Vamsi Bapat",
"Grade" : "VI" }
• No new document for Hersch Gibbs is inserted.