{"id":32094,"date":"2026-09-01T13:13:37","date_gmt":"2026-09-01T07:43:37","guid":{"rendered":"https:\/\/opstree.com\/blog\/?p=32094"},"modified":"2026-09-01T13:13:37","modified_gmt":"2026-09-01T07:43:37","slug":"mongodb-crud-operations-part-2","status":"publish","type":"post","link":"https:\/\/opstree.com\/blog\/mongodb-crud-operations-part-2\/","title":{"rendered":"MongoDB Zero to Hero: CRUD Operations in MongoDB (Part 2)"},"content":{"rendered":"<p><span data-contrast=\"auto\">In <a href=\"https:\/\/opstree.com\/blog\/mongodb-basics-concepts-architecture-part-1\/\" target=\"_blank\" rel=\"noopener\">MongoDB Zero to Hero: Understanding MongoDB from Scratch (Part 1)<\/a><\/span><span data-contrast=\"auto\">, we explored the fundamentals of MongoDB, including the document model, JSON vs BSON, the _id field, MongoDB architecture,\u00a0it\u2019s\u00a0key\u00a0componets, etc.\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Now that we understand how MongoDB works,\u00a0it&#8217;s\u00a0time to get our hands dirty.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">In this part,\u00a0we&#8217;ll\u00a0learn how to\u00a0<\/span><b><span data-contrast=\"auto\">create, read, update and delete documents<\/span><\/b><span data-contrast=\"auto\"> in MongoDB, the four basic operations commonly known as\u00a0<\/span><b><span data-contrast=\"auto\">CRUD<\/span><\/b><span data-contrast=\"auto\">.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">By the end of this article,\u00a0you&#8217;ll\u00a0know how to:<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<ul>\n<li><span data-contrast=\"auto\">Create databases and collections\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">Insert documents\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">Retrieve documents using queries\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">Filter data using query operators\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">Update existing documents\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">Delete documents\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">Work with arrays and nested documents\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-contrast=\"auto\">We&#8217;ll\u00a0use a simple\u00a0<\/span><b><span data-contrast=\"auto\">e-commerce application<\/span><\/b><span data-contrast=\"auto\">\u00a0throughout this article so that each operation is easy to understand.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<h2><span class=\"TextRun SCXW254067738 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW254067738 BCX0\" data-ccp-parastyle=\"heading 2\">What is CRUD?<\/span><\/span><\/h2>\n<p><b><span data-contrast=\"auto\">CRUD<\/span><\/b><span data-contrast=\"auto\">\u00a0stands for:<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">C \u2192 Create<\/span><br \/>\n<span data-contrast=\"auto\">R \u2192 Read<\/span><br \/>\n<span data-contrast=\"auto\">U \u2192 Update<\/span><br \/>\n<span data-contrast=\"auto\">D \u2192 Delete<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/p>\n<p><span class=\"TextRun SCXW36122893 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW36122893 BCX0\">These are the four basic operations we perform on data.<\/span><\/span><span class=\"EOP Selected SCXW36122893 BCX0\" data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-32100\" src=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2026\/09\/page_2_image_1-1024x590.jpeg\" alt=\"\" width=\"1024\" height=\"590\" srcset=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2026\/09\/page_2_image_1-1024x590.jpeg 1024w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2026\/09\/page_2_image_1-300x173.jpeg 300w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2026\/09\/page_2_image_1-768x443.jpeg 768w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2026\/09\/page_2_image_1.jpeg 1299w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<h3><span data-contrast=\"none\">1. Create Operations:<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;335559738&quot;:160,&quot;335559739&quot;:80}\">\u00a0<\/span><\/h3>\n<ul>\n<li><span data-contrast=\"auto\">Create\u00a0operations\u00a0<\/span><b><span data-contrast=\"auto\">add\u00a0new documents<\/span><\/b><span data-contrast=\"auto\">\u00a0to a collection. If the collection does not exist yet, MongoDB will automatically create it.<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">We use\u00a0<\/span><span data-contrast=\"auto\">insertOne() and\u00a0insertMany() to\u00a0insert\u00a0documents\u00a0in collections.<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true}\">\u00a0<\/span><\/li>\n<li><b><span data-contrast=\"auto\">insertOne()<\/span><\/b><span data-contrast=\"auto\">\u00a0\u2192 inserts\u00a0<\/span><b><span data-contrast=\"auto\">one document<\/span><\/b><span data-contrast=\"auto\">\u00a0into a collection.\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<li><b><span data-contrast=\"auto\">insertMany()<\/span><\/b><span data-contrast=\"auto\">\u00a0\u2192\u00a0inserts\u00a0<\/span><b><span data-contrast=\"auto\">multiple documents<\/span><\/b><span data-contrast=\"auto\">\u00a0into a collection.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span class=\"TextRun SCXW230346257 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW230346257 BCX0\">Using\u00a0<\/span><\/span><strong><span class=\"TextRun SCXW230346257 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SpellingErrorV2Themed SCXW230346257 BCX0\">insertOne<\/span><span class=\"NormalTextRun SCXW230346257 BCX0\">()<\/span><\/span><span class=\"EOP Selected SCXW230346257 BCX0\" data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/strong><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.insertOne({\r\n  productName: \"Laptop\",\r\n  price: 64999\r\n})<\/code><\/pre>\n<\/div>\n<p><span class=\"TextRun SCXW185217754 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW185217754 BCX0\">Using\u00a0<\/span><strong><span class=\"NormalTextRun SpellingErrorV2Themed SCXW185217754 BCX0\">i<\/span><\/strong><\/span><strong><span class=\"TextRun SCXW185217754 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SpellingErrorV2Themed SCXW185217754 BCX0\">nsertMany<\/span><span class=\"NormalTextRun SCXW185217754 BCX0\">()<\/span><\/span><\/strong><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.insertMany([\r\n  {\r\n    productName: \"Laptop\",\r\n    price: 64999\r\n  },\r\n  {\r\n    productName: \"Mouse\",\r\n    price: 799\r\n  }\r\n])<\/code><\/pre>\n<\/div>\n<p><span class=\"TextRun SCXW195824747 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun ContextualSpellingAndGrammarErrorV2Themed SCXW195824747 BCX0\">Here products<\/span><span class=\"NormalTextRun SCXW195824747 BCX0\">\u00a0<\/span><span class=\"NormalTextRun SCXW195824747 BCX0\">is<\/span><span class=\"NormalTextRun SCXW195824747 BCX0\">\u00a0the collection name.<\/span><\/span><span class=\"EOP Selected SCXW195824747 BCX0\" data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/p>\n<h3><span class=\"TextRun SCXW111835503 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW111835503 BCX0\" data-ccp-parastyle=\"heading 2\">2. Read Operations<\/span><\/span><span class=\"EOP Selected SCXW111835503 BCX0\" data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;335559738&quot;:160,&quot;335559739&quot;:80}\">\u00a0<\/span><\/h3>\n<ul>\n<li><span data-contrast=\"auto\">Read operations are used to retrieve or query documents from a <a href=\"https:\/\/opstree.com\/blog\/mongodb-setup-on-kubernetes-using-mongodb-operator\/\" target=\"_blank\" rel=\"noopener\">MongoDB<\/a> collection.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">MongoDB provides the\u00a0find() and\u00a0findOne() methods for reading documents from a collection<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">findOne(): Returns the first document that matches the query filter<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">find(): Returns a cursor pointing to all matching documents<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><strong><span class=\"TextRun SCXW17208879 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun ContextualSpellingAndGrammarErrorV2Themed SCXW17208879 BCX0\">find(<\/span><span class=\"NormalTextRun SCXW17208879 BCX0\">):<\/span><\/span><\/strong><\/p>\n<p><span class=\"EOP Selected SCXW17208879 BCX0\" data-ccp-props=\"{}\"><span class=\"TextRun SCXW202116633 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW202116633 BCX0\">Return all documents from the products collection.<\/span><\/span><span class=\"EOP Selected SCXW202116633 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span><\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.find()<\/code><\/pre>\n<\/div>\n<p><span class=\"TextRun SCXW134266334 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW134266334 BCX0\">Returns all products where the brand is\u00a0<\/span><\/span><span class=\"TextRun SCXW134266334 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW134266334 BCX0\">Dell<\/span><\/span><span class=\"TextRun SCXW134266334 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW134266334 BCX0\">.<\/span><\/span><span class=\"EOP Selected SCXW134266334 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.find({\r\n  \"brand\": \"Dell\"\r\n})<\/code><\/pre>\n<\/div>\n<p><strong><span class=\"TextRun SCXW122647692 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SpellingErrorV2Themed SCXW122647692 BCX0\">findOne<\/span><span class=\"NormalTextRun SCXW122647692 BCX0\">():<\/span><\/span><span class=\"EOP Selected SCXW122647692 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span><\/strong><\/p>\n<p><span class=\"TextRun SCXW120635382 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW120635382 BCX0\">Search the products collection and returns the first matching document<\/span><\/span><span class=\"EOP Selected SCXW120635382 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.findOne({\r\n  \"productName\": \"Laptop\"\r\n})<\/code><\/pre>\n<\/div>\n<p><span class=\"TextRun SCXW212195374 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW212195374 BCX0\">Suppose our collection\u00a0<\/span><span class=\"NormalTextRun SCXW212195374 BCX0\">c<\/span><span class=\"NormalTextRun SCXW212195374 BCX0\">ontains<\/span><span class=\"NormalTextRun SCXW212195374 BCX0\">:<\/span><\/span><span class=\"EOP Selected SCXW212195374 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">[\r\n  {\r\n    \"productName\": \"Laptop\",\r\n    \"brand\": \"Dell\",\r\n    \"price\": 64999\r\n  },\r\n  {\r\n    \"productName\": \"Monitor\",\r\n    \"brand\": \"Dell\",\r\n    \"price\": 15999\r\n  },\r\n  {\r\n    \"productName\": \"Phone\",\r\n    \"brand\": \"Samsung\",\r\n    \"price\": 32999\r\n  }\r\n]<\/code><\/pre>\n<\/div>\n<p><span class=\"TextRun SCXW107324749 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW107324749 BCX0\">If we want to get only Laptop and Monitor documents. Then run below query using\u00a0<\/span><span class=\"NormalTextRun ContextualSpellingAndGrammarErrorV2Themed SCXW107324749 BCX0\">find(<\/span><span class=\"NormalTextRun SCXW107324749 BCX0\">)<\/span><\/span><span class=\"EOP Selected SCXW107324749 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.find({\r\n  \"brand\": \"Dell\"\r\n})<\/code><\/pre>\n<\/div>\n<p><span class=\"TextRun SCXW50118325 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW50118325 BCX0\">If you want only one\u00a0<\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW50118325 BCX0\">maching<\/span><span class=\"NormalTextRun SCXW50118325 BCX0\">\u00a0<\/span><span class=\"NormalTextRun ContextualSpellingAndGrammarErrorV2Themed SCXW50118325 BCX0\">document<\/span><span class=\"NormalTextRun SCXW50118325 BCX0\">\u00a0then run below query using\u00a0<\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW50118325 BCX0\">findOne<\/span><span class=\"NormalTextRun SCXW50118325 BCX0\">()<\/span><\/span><span class=\"EOP Selected SCXW50118325 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.findOne({\r\n  \"brand\": \"Dell\"\r\n})<\/code><\/pre>\n<\/div>\n<h3 aria-level=\"2\"><span data-contrast=\"none\">3. Update Operations:<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;335559685&quot;:0,&quot;335559738&quot;:160,&quot;335559739&quot;:80}\">\u00a0<\/span><\/h3>\n<ul>\n<li><span data-contrast=\"auto\">Update operations are used to change existing documents in a MongoDB collection.\u00a0You can update one or multiple documents by specifying a condition that\u00a0identifies\u00a0which documents should be changed.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">MongoDB provides methods such as:<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">updateOne() \u2013 updates one matching document.\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">updateMany() \u2013 updates multiple matching documents.\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">replaceOne() \u2013 replaces an entire document.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><strong><span class=\"TextRun SCXW120662295 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SpellingErrorV2Themed SCXW120662295 BCX0\">updateOne<\/span><span class=\"NormalTextRun SCXW120662295 BCX0\">():<\/span><\/span><\/strong><\/p>\n<p><span class=\"EOP Selected SCXW120662295 BCX0\" data-ccp-props=\"{}\"><span class=\"TextRun SCXW255072107 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW255072107 BCX0\">Suppose we have a products collection:<\/span><\/span><span class=\"EOP Selected SCXW255072107 BCX0\" data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">{\r\n  \"productName\": \"Laptop\",\r\n  \"brand\": \"Dell\",\r\n  \"price\": 64999\r\n}<\/code><\/pre>\n<\/div>\n<p><span data-contrast=\"auto\">Now, suppose the laptop price changes from\u00a0<\/span><b><span data-contrast=\"auto\">\u20b964,999 to \u20b969,999<\/span><\/b><span data-contrast=\"auto\">.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">We can update the document using\u00a0updateOne():<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.updateOne(\r\n  { \"productName\": \"Laptop\" },\r\n  { \"$set\": { \"price\": 69999 } }\r\n)<\/code><\/pre>\n<\/div>\n<p><span data-contrast=\"auto\">Here:<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<ul>\n<li><span data-contrast=\"auto\">{ &#8220;productName&#8221;: &#8220;Laptop&#8221; }\u00a0-&gt;\u00a0finds the document we want to update.\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">$set\u00a0&#8211;&gt;\u00a0specifies the field we want to change.\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">&#8220;price&#8221;: 69999\u00a0&#8211;&gt;\u00a0changes the price to \u20b969,999.\u00a0<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><b><span data-contrast=\"auto\">updateMany():<\/span><\/b><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">If we want to update\u00a0<\/span><b><span data-contrast=\"auto\">multiple documents<\/span><\/b><span data-contrast=\"auto\">, we can use\u00a0updateMany().<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">For example, increase the price of all Dell products:<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.updateMany(\r\n  { \"brand\": \"Dell\" },\r\n  { \"$set\": { \"price\": 70000 } }\r\n)<\/code><\/pre>\n<\/div>\n<p><span data-contrast=\"auto\">Here, $set\u00a0will update\u00a0the price of every matching product\u00a0to 70,000<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">In simple terms:<\/span><\/b><span data-contrast=\"auto\">\u00a0updateOne() changes one matching document, while\u00a0updateMany() changes all documents that match the given condition.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">When using\u00a0updateOne() or\u00a0updateMany(), you must use update operators to dictate how the document changes:<\/span><\/b><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<ul>\n<li><span data-contrast=\"auto\">$set: Overwrites the value of an existing field or creates the field if it does not exist.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">$unset: Removes a specified field from a document.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">$inc: Increments or decrements a numeric field value by a specified amount.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">$push: Appends a specified value into an array field.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">$pull: Removes all array elements that match a specified value or condition<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/li>\n<\/ul>\n<h3><span class=\"TextRun SCXW145325099 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW145325099 BCX0\" data-ccp-parastyle=\"heading 2\">4.\u00a0<\/span><span class=\"NormalTextRun SCXW145325099 BCX0\" data-ccp-parastyle=\"heading 2\">Delete<\/span><span class=\"NormalTextRun SCXW145325099 BCX0\" data-ccp-parastyle=\"heading 2\">\u00a0Operations<\/span><\/span><span class=\"EOP Selected SCXW145325099 BCX0\" data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;335559738&quot;:160,&quot;335559739&quot;:80}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">Delete operations are used to remove existing documents from a MongoDB collection. You can\u00a0delete\u00a0a single document or multiple documents by specifying a condition. If required, you can also remove all documents from a collection.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">MongoDB provides two commonly used methods:<\/span><\/p>\n<ul>\n<li><span data-contrast=\"auto\">deleteOne() \u2013 removes the first document that matches the condition. <\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"auto\">deleteMany() \u2013 removes all documents that match the condition<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><strong><span class=\"TextRun SCXW184538282 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SpellingErrorV2Themed SCXW184538282 BCX0\">deleteOne<\/span><span class=\"NormalTextRun SCXW184538282 BCX0\">():<\/span><\/span><span class=\"EOP Selected SCXW184538282 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span><\/strong><\/p>\n<p><span class=\"TextRun SCXW51482226 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW51482226 BCX0\">This will remove\u00a0<\/span><\/span><span class=\"TextRun SCXW51482226 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW51482226 BCX0\">one matching document<\/span><\/span><span class=\"TextRun SCXW51482226 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW51482226 BCX0\">\u00a0from the collection.<\/span><\/span><span class=\"EOP Selected SCXW51482226 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.deleteOne({\r\n  \"productName\": \"Laptop\"\r\n})<\/code><\/pre>\n<\/div>\n<p><strong><span class=\"TextRun SCXW175242425 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SpellingErrorV2Themed SCXW175242425 BCX0\">deleteMany<\/span><span class=\"NormalTextRun SCXW175242425 BCX0\">():<\/span><\/span><span class=\"EOP Selected SCXW175242425 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span>\u00a0<\/strong><\/p>\n<p><span class=\"TextRun SCXW67706288 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW67706288 BCX0\">This will\u00a0<\/span><span class=\"NormalTextRun ContextualSpellingAndGrammarErrorV2Themed SCXW67706288 BCX0\">removes<\/span><span class=\"NormalTextRun SCXW67706288 BCX0\">\u00a0all documents where brand is &#8220;Dell&#8221;<\/span><\/span><span class=\"EOP Selected SCXW67706288 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.deleteMany({\r\n  \"brand\": \"Dell\"\r\n})<\/code><\/pre>\n<\/div>\n<p><strong><span class=\"TextRun SCXW242580037 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW242580037 BCX0\">To remove\u00a0<\/span><span class=\"NormalTextRun SCXW242580037 BCX0\">all documents<\/span><span class=\"NormalTextRun SCXW242580037 BCX0\">\u00a0from a collection:<\/span><\/span><span class=\"EOP Selected SCXW242580037 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span>\u00a0<\/strong><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.deleteMany({})<\/code><\/pre>\n<\/div>\n<blockquote>\n<h3 aria-level=\"2\"><span data-contrast=\"none\">Important: Be Careful with Update and Delete Operations<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;335559738&quot;:160,&quot;335559739&quot;:80}\">\u00a0<\/span><\/h3>\n<p><b><span data-contrast=\"auto\">Before running an update or\u00a0delete\u00a0operation, always verify your filter condition carefully. A small mistake in the query can\u00a0modify\u00a0or delete more documents than intended. It is a good practice to first run the same condition with\u00a0find() to check which documents will be affected. For important or production data, take a backup before performing update or\u00a0delete\u00a0operations so that the data can be restored if something goes wrong.<\/span><\/b><span data-ccp-props=\"{}\">\u00a0<\/span><\/p><\/blockquote>\n<h3><span class=\"TextRun SCXW252070493 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW252070493 BCX0\" data-ccp-parastyle=\"heading 2\">Working with Arrays and Nested Documents<\/span><\/span><\/h3>\n<p><span class=\"EOP Selected SCXW252070493 BCX0\" data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;335559738&quot;:160,&quot;335559739&quot;:80}\"><span class=\"TextRun SCXW173779063 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW173779063 BCX0\">MongoDB documents can\u00a0<\/span><span class=\"NormalTextRun SCXW173779063 BCX0\">contain<\/span><span class=\"NormalTextRun SCXW173779063 BCX0\">\u00a0arrays and nested documents, allowing us to store related information together in a single document.<\/span><\/span><span class=\"EOP Selected SCXW173779063 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span>\u00a0<\/span><\/p>\n<h4><strong><span class=\"TextRun SCXW114728564 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW114728564 BCX0\">Working with Arrays:<\/span><\/span><span class=\"EOP Selected SCXW114728564 BCX0\" data-ccp-props=\"{}\">\u00a0<\/span><\/strong><\/h4>\n<p><span data-contrast=\"auto\">An array allows you to store multiple values in a single field.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">For example:<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">{\r\n  \"productName\": \"Laptop\",\r\n  \"brand\": \"Dell\",\r\n  \"colors\": [\"Black\", \"Silver\", \"Blue\"]\r\n}<\/code><\/pre>\n<\/div>\n<p><span data-contrast=\"auto\">Here,\u00a0colors\u00a0is an array\u00a0containing\u00a0multiple values.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">You can search for products that have a specific color:<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.find({\r\n  \"colors\": \"Black\"\r\n})<\/code><\/pre>\n<\/div>\n<p><span data-contrast=\"auto\">MongoDB will return documents where the\u00a0colors\u00a0array\u00a0contains\u00a0&#8220;Black&#8221;.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">You can also store an array of objects:<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">{\r\n  \"productName\": \"Laptop\",\r\n  \"reviews\": [\r\n    {\r\n      \"user\": \"John\",\r\n      \"rating\": 5\r\n    },\r\n    {\r\n      \"user\": \"David\",\r\n      \"rating\": 4\r\n    }\r\n  ]\r\n}<\/code><\/pre>\n<\/div>\n<p><span class=\"TextRun SCXW38839948 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW38839948 BCX0\">This is useful when a document\u00a0<\/span><span class=\"NormalTextRun SCXW38839948 BCX0\">contains<\/span><span class=\"NormalTextRun SCXW38839948 BCX0\">\u00a0a list of related items, such as reviews, order items, tags, or product specifications.<\/span><\/span><span class=\"EOP Selected SCXW38839948 BCX0\" data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<h3><span class=\"TextRun SCXW216185982 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW216185982 BCX0\">Working with Nested Documents<\/span><span class=\"NormalTextRun SCXW216185982 BCX0\">:<\/span><\/span><\/h3>\n<p><span data-contrast=\"auto\">A\u00a0<\/span><b><span data-contrast=\"auto\">nested document<\/span><\/b><span data-contrast=\"auto\">\u00a0is a document stored inside another document.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">For example:<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">{\r\n  \"productName\": \"Laptop\",\r\n  \"brand\": \"Dell\",\r\n  \"price\": 70000,\r\n  \"specifications\": {\r\n    \"ram\": \"16GB\",\r\n    \"storage\": \"512GB SSD\",\r\n    \"processor\": \"Intel i7\"\r\n  }\r\n}<\/code><\/pre>\n<\/div>\n<p><span data-contrast=\"auto\">Here, specifications\u00a0is\u00a0a nested document\u00a0containing\u00a0its own fields.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">You can query a field inside the nested document using\u00a0<\/span><b><span data-contrast=\"auto\">dot notation<\/span><\/b><span data-contrast=\"auto\">:<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<div style=\"margin: 20px 0;\">\n<pre style=\"background: #1e1e1e !important; color: #d4d4d4 !important; padding: 18px; border-radius: 8px; overflow-x: auto; font-family: Consolas,'Courier New',monospace; font-size: 14px; line-height: 1.6;\"><code style=\"background: transparent !important; color: inherit !important; padding: 0 !important; margin: 0 !important; border: none !important; box-shadow: none !important;\">db.products.find({\r\n  \"specifications.ram\": \"16GB\"\r\n})<\/code><\/pre>\n<\/div>\n<p><span class=\"TextRun SCXW126013726 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW126013726 BCX0\">This finds products where the RAM is 16GB.<\/span><\/span><span class=\"EOP Selected SCXW126013726 BCX0\" data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<h2><span class=\"TextRun SCXW236394169 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW236394169 BCX0\">Conclusion<\/span><\/span><\/h2>\n<p><span data-contrast=\"auto\">We learned how to insert documents using\u00a0insertOne() and\u00a0insertMany(), retrieve data using\u00a0find() and\u00a0findOne(),\u00a0modify\u00a0documents using\u00a0updateOne() and\u00a0updateMany(), and remove documents using\u00a0deleteOne() and\u00a0deleteMany(). We also explored\u00a0arrays,\u00a0nested documents.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">One important lesson is to always verify your query before\u00a0running update\u00a0or\u00a0delete\u00a0operations, especially when working with multiple documents. For important data, taking a backup before making changes is also a good practice.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<h3><span data-ccp-props=\"{}\">Related Searches<\/span><\/h3>\n<ul>\n<li class=\"ekit-heading--title elementskit-section-title \"><a href=\"https:\/\/opstree.com\/case-study\/a-leading-logistics-platform-achieved-30-faster-incident-resolution-with-ai-driven-observability\/\" target=\"_blank\" rel=\"noopener\">A Leading Logistics Platform Achieved 30% Faster Incident Resolution with AI-Driven Observability<\/a><\/li>\n<li class=\"ekit-heading--title elementskit-section-title \"><a href=\"https:\/\/opstree.com\/case-study\/driving-40-faster-resolution-with-ai-across-one-of-asias-largest-digital-businesses\/\" target=\"_blank\" rel=\"noopener\">Driving 40% Faster Resolution with AI Across One of Asia\u2019s Largest Digital Businesses<\/a><\/li>\n<li><a href=\"https:\/\/buildpiper.io\/blogs\/ci-cd-pipeline-native-clone-multiple-repos\/\" target=\"_blank\" rel=\"noopener\">Stop Building Script Bridges: Why Your CI\/CD Pipeline Should Native-Clone Multiple Repos<\/a><\/li>\n<\/ul>\n<h2>Related Solutions<\/h2>\n<ul>\n<li><a href=\"https:\/\/opstree.com\/services\/database-and-data-engineering\/\" target=\"_blank\" rel=\"noopener\">Automate ETL Pipelines Enterprise<\/a><\/li>\n<li><a href=\"https:\/\/opstree.com\/services\/observability-sre-production-engineering\/\" target=\"_blank\" rel=\"noopener\">SRE consulting services<\/a><\/li>\n<li><a href=\"https:\/\/opstree.com\/aws-partner\/\" target=\"_blank\" rel=\"noopener\">AWS Consulting Partner<\/a><\/li>\n<li><a href=\"https:\/\/opstree.com\/services\/cloud-migration-and-modernization-services\/\" target=\"_blank\" rel=\"noopener\">Cloud Modernization Services<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In MongoDB Zero to Hero: Understanding MongoDB from Scratch (Part 1), we explored the fundamentals of MongoDB, including the document model, JSON vs BSON, the _id field, MongoDB architecture,\u00a0it\u2019s\u00a0key\u00a0componets, etc.\u00a0\u00a0 Now that we understand how MongoDB works,\u00a0it&#8217;s\u00a0time to get our hands dirty.\u00a0 In this part,\u00a0we&#8217;ll\u00a0learn how to\u00a0create, read, update and delete documents in MongoDB, the [&hellip;]<\/p>\n","protected":false},"author":244582729,"featured_media":32103,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[768739361],"tags":[768739707,768739621,475,21954763],"class_list":["post-32094","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-engineering","tag-crud","tag-data-engineering-services","tag-database","tag-mongodb"],"blocksy_meta":[],"jetpack_publicize_connections":[],"acf":[],"jetpack_featured_media_url":"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2026\/09\/CRUD-Operations-in-MongoDB.png","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfDBOm-8lE","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/32094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/users\/244582729"}],"replies":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/comments?post=32094"}],"version-history":[{"count":7,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/32094\/revisions"}],"predecessor-version":[{"id":32106,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/32094\/revisions\/32106"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media\/32103"}],"wp:attachment":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media?parent=32094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/categories?post=32094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/tags?post=32094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}