Big Data & Tools with NoSQL
  • Big Data & Tools
  • ReadMe
  • Big Data Overview
    • Overview
    • Job Opportunities
    • What is Data?
    • How does it help?
    • Types of Data
    • The Big 4 V's
      • Variety
      • Volume
      • Velocity
      • Veracity
      • Other V's
    • Trending Technologies
    • Big Data Concerns
    • Big Data Challenges
    • Data Integration
    • Scaling
      • CAP Theorem
      • Optimistic concurrency
      • Eventual consistency
      • Concurrent vs. Parallel Programming
    • Big Data Tools
    • No SQL Databases
    • What does Big Data learning means?
  • Linux & Tools
    • Overview
    • Linux Commands - 01
    • Linux Commands - 02
    • AWK
    • CSVKIT
    • CSVSQL
    • CSVGREP
  • Data Format
    • Storage Formats
    • CSV/TSV/Parquet
    • Parquet Example
    • JSON
    • HTTP & REST API
      • Terms to Know
        • Statefulness
        • Statelessness
        • Monolithic Architecture
        • Microservices
        • Idempotency
    • REST API
    • Python
      • Setup
      • Decorator
      • Unit Testing
      • Flask Demo
      • Flask Demo - 01
      • Flask Demo - 02
      • Flask Demo - 03
      • Flask Demo - 04
      • Flask Demo - 06
    • API Testing
    • Flask Demo Testing
    • API Performance
    • API in Big Data World
  • NoSQL
    • Types of NoSQL Databases
    • Redis
      • Overview
      • Terms to know
      • Redis - (RDBMS) MySql
      • Redis Cache Demo
      • Use Cases
      • Data Structures
        • Strings
        • List
        • Set
        • Hash
        • Geospatial Index
        • Pub/Sub
        • Redis - Python
      • Redis JSON
      • Redis Search
      • Persistence
      • Databases
      • Timeseries
    • Neo4J
      • Introduction
      • Neo4J Terms
      • Software
      • Neo4J Components
      • Hello World
      • Examples
        • MySQL: Neo4J
        • Sample Transactions
        • Sample
        • Create Nodes
        • Update Nodes
        • Relation
        • Putting it all together
        • Commonly used Functions
        • Data Profiling
        • Queries
        • Python Scripts
      • More reading
    • MongoDB
      • Sample JSON
      • Introduction
      • Software
      • MongoDB Best Practices
      • MongoDB Commands
      • Insert Document
      • Querying MongoDB
      • Update & Remove
      • Import
      • Logical Operators
      • Data Types
      • Operators
      • Aggregation Pipeline
      • Further Reading
      • Fun Task
        • Sample
    • InfluxDB
      • Data Format
      • Scripts
  • Python
    • Python Classes
    • Serialization-Deserialization
  • Tools
    • JQ
    • DUCK DB
    • CICD Intro
    • CICD Tools
      • CI YAML
      • CD Yaml
    • Containers
      • VMs or Containers
      • What container does
      • Podman
      • Podman Examples
  • Cloud Everywhere
    • Overview
    • Types of Cloud Services
    • Challenges of Cloud Computing
    • High Availability
    • Azure Cloud
      • Services
      • Storages
      • Demo
    • Terraform
  • Data Engineering
    • Batch vs Streaming
    • Kafka
      • Introduction
      • Kafka Use Cases
      • Kafka Software
      • Python Scripts
      • Different types of Streaming
    • Quality & Governance
    • Medallion Architecture
    • Data Engineering Model
    • Data Mesh
  • Industry Trends
    • Roadmap - Data Engineer
    • Good Reads
      • IP & SUBNET
Powered by GitBook
On this page
  1. NoSQL
  2. MongoDB

Update & Remove

Update Statement

// Update Statement

db.friendsCollection.update({"firstname":"Ross"}, {$set: {age: 33}})

// Verify the update

db.friendsCollection.find({"firstname":{'$regex' : '^r', '$options' : 'i'}})

Remove Statement

// Remove the attribute / element
db.friendsCollection.update({"firstname": "Phoebe"}, {$unset: {age:""}});

// Remove entire document
db.friendsCollection.remove({firstname: "Ross"}, true);

db.friendsCollection.find();

// Remove all documents from friendsCollection
db.friendsCollection.remove({});

Drop Statement()

db.collection.drop() 

Bulk Insert

Unordered Insert - Asynchronous

var bulk = db.students1.initializeUnorderedBulkOp();
bulk.insert( { firstname: "Sheldon", last_name: "Cooper" } );
bulk.insert( { firstname: "Jerry", last_name: "Seinfeld" } );
bulk.insert( { firstname: "Ray", last_name: "Ramona" } );
bulk.insert( { firstname: "Penny" } );
bulk.insert( { firstname: "Cosmo", last_name: "Kramer" } );
bulk.find({firstname:"Penny"}).update({$set:{lastname:"noName",gender:"F"}})
bulk.execute();
  • Asynchronous Execution: The operations can be executed in parallel or in any order, not necessarily the order in which they were added to the bulk operation. This can lead to performance benefits because MongoDB doesn't need to wait for one operation to complete before starting the next one.

  • Error Handling: If an error occurs, MongoDB will attempt to execute the rest of the operations in the bulk. It does not stop at the first error (unless the error is on the server side, like losing connection).

  • Use Case: Useful when the order of the operations does not affect the outcome and when performance is a priority over execution order.

Ordered Insert - Does in sequence

var bulk = db.students2.initializeOrderedBulkOp();
bulk.insert( { firstname: "Sheldon", last_name: "Cooper" } );
bulk.insert( { firstname: "Jerry", last_name: "Seinfeld" } );
bulk.insert( { firstname: "Ray", last_name: "Ramona" } );
bulk.insert( { firstname: "Penny" } );
bulk.insert( { firstname: "Cosmo", last_name: "Kramer" } );
bulk.find({firstname:"Penny"}).update({$set:{lastname:"noName",gender:"F"}})
bulk.execute();
  • Sequential Execution: The operations are executed in the exact order they were added to the bulk operation. If an operation fails, MongoDB stops processing any remaining operations in the bulk.

  • Error Handling: Stops at the first error encountered. This allows you to know exactly at which point the bulk operation failed, making debugging easier.

  • Use Case: Important when the order of operations affects the final state of the database. For example, if one operation depends on the result of a previous operation, ordered bulk operations ensure that these dependencies are respected.

PreviousQuerying MongoDBNextImport

Last updated 1 year ago