πŸŽ“ Computer Science & Engineering Portal

Master Engineering Disciplines with Structured Notes

Comprehensive academic lecture notes, exam-oriented unit summaries, laboratory manuals, and previous year question papers designed strictly for university students.

πŸ“‘

University Syllabi

AKTU & AICTE aligned semester guidelines.

πŸ“

Exam Question Papers

Previous 5 years solved university papers.

πŸ’‘

Lab Manuals & Viva

Practical codes with outputs & interview Qs.

Core Subjects & Units Hub

Click on any specific unit to immediately view its lecture notes below

Viewing All Lectures

MongoDB

MongoDB:

Introduction:

MongoDB is an open-source document database and leading NoSQL database. MongoDB is written in C++. This tutorial will give you a great understanding of MongoDB concepts needed to create and deploy a highly scalable and performance-oriented database.

Data Types:

MongoDB supports many data types. Some of them are βˆ’

  • String βˆ’ This is the most commonly used datatype to store the data. String in MongoDB must be UTF-8 valid.
  • Integer βˆ’ This type is used to store a numerical value. Integer can be 32 bit or 64 bit depending upon your server.
  • Boolean βˆ’ This type is used to store a boolean (true/ false) value.
  • Double βˆ’ This type is used to store floating-point values.
  • Min/ Max keys βˆ’ This type is used to compare a value against the lowest and highest BSON elements.
  • Arrays βˆ’ This type is used to store arrays or lists or multiple values into one key.
  • Timestamp βˆ’ timestamp. This can be handy for recording when a document has been modified or added.
  • Object βˆ’ This data type is used for embedded documents.
  • Null βˆ’ This type is used to store a Null value.
  • Symbol βˆ’ This datatype is used identically to a string; however, it's generally reserved for languages that use a specific symbol type.
  • Date βˆ’ This data type is used to store the current date or time in UNIX time format. You can specify your own date time by creating an object of Date and passing day, month, a year into it.
  • Object ID βˆ’ This data type is used to store the document’s ID.
  • Binary data βˆ’ This data type is used to store binary data.
  • Code βˆ’ This data type is used to store JavaScript code into the document.
  • Regular expression βˆ’ This data type is used to store regular expression.

Creating Document:

Insert a Single Document

db.collection.insertOne() inserts a single document into a collection.

Insert Multiple Document

db.collection.insertMany() can insert multiple documents into a collection. Pass an array of documents to the method.

 

Updating Document

db.collection.updateOne(<filter>, <update>, <options>)

Updates at most a single document that matches a specified filter even though multiple documents may match the specified filter.

db.collection.updateMany(<filter>, <update>, <options>)

Update all documents that match a specified filter.

db.collection.replaceOne(<filter>, <update>, <options>)

Replaces at most a single document that matches a specified filter even though multiple documents may match the specified filter.

db.collection.update()

Either updates or replaces a single document that matches a specified filter or updates all documents that match a specified filter.

By default, the db.collection.update() method updates a single document. To update multiple documents, use the multi option.

Deleting Documents

db.collection.deleteMany()

Delete all documents that match a specified filter.

db.collection.deleteOne()

Delete at most a single document that matches a specified filter even though multiple documents may match the specified filter.

db.collection.remove()

Delete a single document or all documents that match a specified filter.

db.collection.findOneAndDelete()
findOneAndDelete() provides a sort option. The option allows for the deletion of the first document sorted by the specified order.

db.collection.findAndModify()
db.collection.findAndModify() provides a sort option. The option allows for the deletion of the first document sorted by the specified order.

db.collection.bulkWrite()

Labels: ,

Discussion & Queries (<$I18NNumComments$>):

<$CommentPager$>
<$I18NAtCommentTimeWithPermalink$>, <$I18NCommentAuthorSaid$>

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>