{"id":2837,"date":"2024-06-30T17:06:27","date_gmt":"2024-06-30T11:36:27","guid":{"rendered":"https:\/\/moodle.sit.ac.in\/blog\/?p=2837"},"modified":"2024-06-30T22:26:25","modified_gmt":"2024-06-30T16:56:25","slug":"mongodb-lab-manual-bds456b-2","status":"publish","type":"post","link":"https:\/\/moodle.sit.ac.in\/blog\/mongodb-lab-manual-bds456b-2\/","title":{"rendered":"MongoDB Lab Manual &#8211; BDS456B"},"content":{"rendered":"\n<p><strong><strong>MongoDB Laboratory (BDS456B)<\/strong><\/strong><\/p>\n\n\n\n<p>In this blog post, you will find solutions for the <strong>MongoDB Laboratory (BDS456B)<\/strong> course work for the IV semester of <strong>VTU<\/strong> university. To follow along, you will need to have up a machine running any flavour of <strong>GNULinux<\/strong> OS. This blog provides instructions to get MongoDB installed on your system. The solutions have been tested on <strong>Ubuntu 22.04 <\/strong>OS. You can find the lab syllabus on the university&#8217;s website or here below.<\/p>\n\n\n\n<div data-wp-interactive=\"core\/file\" class=\"wp-block-file\"><object data-wp-bind--hidden=\"!state.hasPdfPreview\" hidden class=\"wp-block-file__embed\" data=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/BDS456B_MongoDB.pdf\" type=\"application\/pdf\" style=\"width:100%;height:600px\" aria-label=\"Embed of BDS456B_MongoDB.\"><\/object><a id=\"wp-block-file--media-5b479234-611f-4b21-b413-2b915f1cd84e\" href=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/BDS456B_MongoDB.pdf\">BDS456B_MongoDB<\/a><a href=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/BDS456B_MongoDB.pdf\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-5b479234-611f-4b21-b413-2b915f1cd84e\">Download<\/a><\/div>\n\n\n\n<p>All these solutions have been maintained at the following git repository shown below. If you want to contribute send me a PR.<\/p>\n\n\n\n<p><a href=\"https:\/\/gitlab.com\/lab_manuals\/current\/iv-semester\/bds456b_mongodb\">https:\/\/gitlab.com\/lab_manuals\/current\/iv-semester\/bds456b_mongodb<\/a><\/p>\n\n\n\n<p>The following blog shows how to install and configure&nbsp;<strong>MongoDB<\/strong>&nbsp;on&nbsp;<strong>Ubuntu<\/strong>&nbsp;step-by-step to power your application\u2019s database. This comprehensive guide covers everything from installation and service setup to basic configuration and optional security measures. By following these instructions, you\u2019ll have&nbsp;<strong>MongoDB<\/strong>&nbsp;up and running smoothly on your Ubuntu machine, ready to support your applications data needs efficiently and securely.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-myblogosphere wp-block-embed-myblogosphere\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"AVMWPO6G7t\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/setting-up-mongodb-on-ubuntu\/\">Setting Up MongoDB on Ubuntu<\/a><\/blockquote><iframe class=\"wp-embedded-content lazyload\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Setting Up MongoDB on Ubuntu&#8221; &#8212; MyBlogosphere\" data-src=\"https:\/\/moodle.sit.ac.in\/blog\/setting-up-mongodb-on-ubuntu\/embed\/#?secret=IkAl9zciqc#?secret=AVMWPO6G7t\" data-secret=\"AVMWPO6G7t\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>After getting the necessary development environment setup, Now lets focus on the solutions. For all programs the MongoDB server should be up and running which can be done as follows.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Start MongoDB.<\/h3>\n\n\n\n<p>Open a terminal and type  the following.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"sudo systemctl start mongod\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">sudo<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">systemctl<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">start<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">mongod<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">2. Begin using MongoDB.<\/h3>\n\n\n\n<p>To begin using MongoDB start the MongoDB Shell.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"mongosh\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">mongosh<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Now you will see a MongoDB shell, where you can issue the queries.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-align-center\"><strong>Solutions to lab exercises<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"color: #ff0000;\"><a href=\"#P01\" title=\"Question 1\">Question 1<\/a><\/span>\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"#P01a\" title=\" Illustration of Where Clause, AND,OR operations in MongoDB.\"> Illustration of Where Clause, AND,OR operations in MongoDB.<\/a><\/strong><\/li>\n\n\n\n<li><strong><a href=\"#P01b\" title=\"MongoDB : Insert, Query, Update, Delete and Projection.\">MongoDB : Insert, Query, Update, Delete and Projection.<\/a><\/strong><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\"><a href=\"#P02\" title=\"Question 2\">Question 2<\/a><\/span>\n<ul class=\"wp-block-list\">\n<li><a href=\"#P02a\" title=\"MongoDB query to select and ignore certain fields\">MongoDB query to select and ignore certain fields<\/a><\/li>\n\n\n\n<li><a href=\"#P02b\" title=\"Use of limit and find in MongoDB query\">Use of limit and find in MongoDB query<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\"><a href=\"#P03\" title=\"Question 2\">Question 3<\/a><\/span>\n<ul class=\"wp-block-list\">\n<li><a href=\"#P03a\" title=\"Execute query selectors (comparison selectors, logical selectors )\">Execute query selectors (comparison selectors, logical selectors )<\/a><\/li>\n\n\n\n<li><a href=\"#P03b\" title=\"Execute query selectors (Geospatial selectors, Bitwise selectors )\">Execute query selectors (Geospatial selectors, Bitwise selectors )<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\"><a href=\"#P04\" title=\"Question 4\">Question 4<\/a><\/span>\n<ul class=\"wp-block-list\">\n<li><a href=\"#P04a\" title=\"Projection operators\">Projection operators<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\"><a href=\"#P05\" title=\"Question 5\">Question 5<\/a><\/span>\n<ul class=\"wp-block-list\">\n<li><a href=\"#P05a\" title=\"Aggregation operations\">Aggregation operations<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\"><a href=\"#P06\" title=\"Question 6\">Question 6<\/a><\/span>\n<ul class=\"wp-block-list\">\n<li><a href=\"#P06a\" title=\"Aggregation Pipeline and its operations\">Aggregation Pipeline and its operations<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\"><a href=\"#P07\" title=\"Question 7\">Question 7<\/a><\/span>\n<ul class=\"wp-block-list\">\n<li><a href=\"#P07a\" title=\"Find all listings\">Find all listings<\/a><\/li>\n\n\n\n<li><a href=\"#P07b\" title=\"E-commerce collection reviews summary \">E-commerce collection reviews summary <\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\"><a href=\"#P08\" title=\"Question 8\">Question 8<\/a><\/span>\n<ul class=\"wp-block-list\">\n<li><a href=\"#P08a\" title=\"Demonstrate different types of indexes\">Demonstrate different types of indexes<\/a><\/li>\n\n\n\n<li><a href=\"#P08b\" title=\"Demonstrate optimization of queries using indexes.\">Demonstrate optimization of queries using indexes.<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\"><a href=\"#P09\" title=\"Question 9\">Question 9<\/a><\/span>\n<ul class=\"wp-block-list\">\n<li><a href=\"#P09a\" title=\"Demonstrate Text search using catalog data collection for a given word\">Demonstrate Text search using catalog data collection for a given word<\/a><\/li>\n\n\n\n<li><a href=\"#P09b\" title=\"Excluding documents with certain words and phrases\">Excluding documents with certain words and phrases<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><span style=\"color: #ff0000;\"><a href=\"#P10\" title=\"Question 10\">Question 10<\/a><\/span>\n<ul class=\"wp-block-list\">\n<li><a href=\"#P10a\" title=\"Aggregation pipeline to illustrate Text search on Catalog data collection.\">Aggregation pipeline to illustrate Text search on Catalog data collection.<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" data-src=\"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/10\/CodingAd.png?ssl=1\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center\"><strong>PART A<\/strong><\/h2>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P01\">Question 1 <\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">MongoDB Operations<\/h2>\n\n\n\n<p id=\"P01b\"><strong>b. Execute the Commands of MongoDB and operations in MongoDB : Insert, Query, Update, Delete and Projection. (Note: use any collection)<\/strong><\/p>\n\n\n\n<p><strong>(part a is answered after part b)<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Switch to a Database (Optional):<\/strong><\/h3>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-19647ee7f36c787199c27f0c277b71b7\">If you want to use a specific database, switch to that database using the&nbsp;<code>use<\/code>&nbsp;command. If the database doesn\u2019t exist, MongoDB will create it implicitly when you insert data into it:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"test&gt; use ProgBooksDB\nswitched to db ProgBooksDB\nProgBooksDB&gt;\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">test<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">use<\/span><span style=\"color: #E1E4E8\"> ProgBooksDB<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">switched <\/span><span style=\"color: #F97583\">to<\/span><span style=\"color: #E1E4E8\"> db ProgBooksDB<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">&nbsp;<strong>Create the&nbsp;<code>ProgrammingBooks<\/code>&nbsp;Collection:<\/strong><\/h3>\n\n\n\n<p>To create the&nbsp;<code>ProgrammingBooks<\/code>&nbsp;collection, use the&nbsp;<code>createCollection()<\/code>&nbsp;method. This step is optional because MongoDB will automatically create the collection when you insert data into it, but you can explicitly create it if needed:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt; db.createCollection(&quot;ProgrammingBooks&quot;)\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">db<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">createCollection<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;ProgrammingBooks&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Insert operations<\/h3>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Insert a Single Document into&nbsp;<code>ProgrammingBooks<\/code>:<\/strong><\/h5>\n\n\n\n<p>Use the&nbsp;<code>insertOne()<\/code>&nbsp;method to insert a new document into the&nbsp;<code>ProgrammingBooks<\/code>&nbsp;collection:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt;  db.ProgrammingBooks.insertOne({\n  title: &quot;The Pragmatic Programmer: Your Journey to Mastery&quot;,\n  author: &quot;David Thomas, Andrew Hunt&quot;,\n  category: &quot;Software Development&quot;,\n  year: 1999\n})\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #79B8FF\">db<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">ProgrammingBooks<\/span><span style=\"color: #E1E4E8\">.insertOne({<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  title: <\/span><span style=\"color: #9ECBFF\">&quot;The Pragmatic Programmer: Your Journey to Mastery&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  author: <\/span><span style=\"color: #9ECBFF\">&quot;David Thomas, Andrew Hunt&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  category: <\/span><span style=\"color: #9ECBFF\">&quot;Software Development&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1999<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">})<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Insert multiple Documents into the&nbsp;<code>ProgrammingBooks<\/code>&nbsp;Collection :<\/strong><\/h5>\n\n\n\n<p>Now, insert 5 documents representing programming books into the&nbsp;<code>ProgrammingBooks<\/code>&nbsp;collection using the&nbsp;<code>insertMany()<\/code>&nbsp;method:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt; db.ProgrammingBooks.insertMany([\n  {\n    title: &quot;Clean Code: A Handbook of Agile Software Craftsmanship&quot;,\n    author: &quot;Robert C. Martin&quot;,\n    category: &quot;Software Development&quot;,\n    year: 2008\n  },\n  {\n    title: &quot;JavaScript: The Good Parts&quot;,\n    author: &quot;Douglas Crockford&quot;,\n    category: &quot;JavaScript&quot;,\n    year: 2008\n  },\n  {\n    title: &quot;Design Patterns: Elements of Reusable Object-Oriented Software&quot;,\n    author: &quot;Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides&quot;,\n    category: &quot;Software Design&quot;,\n    year: 1994\n  },\n  {\n    title: &quot;Introduction to Algorithms&quot;,\n    author: &quot;Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein&quot;,\n    category: &quot;Algorithms&quot;,\n    year: 1990\n  },\n  {\n    title: &quot;Python Crash Course: A Hands-On, Project-Based Introduction to Programming&quot;,\n    author: &quot;Eric Matthes&quot;,\n    category: &quot;Python&quot;,\n    year: 2015\n  }\n])\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dracula\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F8F8F2\">ProgBooksDB<\/span><span style=\"color: #FF79C6\">&gt;<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #BD93F9\">db<\/span><span style=\"color: #F8F8F2\">.<\/span><span style=\"color: #BD93F9\">ProgrammingBooks<\/span><span style=\"color: #F8F8F2\">.insertMany([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    title: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Clean Code: A Handbook of Agile Software Craftsmanship<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    author: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Robert C. Martin<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    category: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Software Development<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    title: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">JavaScript: The Good Parts<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    author: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Douglas Crockford<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    category: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">JavaScript<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    title: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Design Patterns: Elements of Reusable Object-Oriented Software<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    author: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    category: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Software Design<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">1994<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    title: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Introduction to Algorithms<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    author: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    category: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Algorithms<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">1990<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    title: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Python Crash Course: A Hands-On, Project-Based Introduction to Programming<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    author: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Eric Matthes<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    category: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Python<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">2015<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">])<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Query operations<\/h3>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Find All Documents<\/strong><\/h5>\n\n\n\n<p>To retrieve all documents from the&nbsp;<code>ProgrammingBooks<\/code>&nbsp;collection:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(253, 253, 237, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt; db.ProgrammingBooks.find().pretty()\n[\n  {\n    _id: ObjectId('664ee3b1924a8039f62202d8'),\n    title: 'The Pragmatic Programmer: Your Journey to Mastery',\n    author: 'David Thomas, Andrew Hunt',\n    category: 'Software Development',\n    year: 1999\n  },\n  {\n    _id: ObjectId('664ee452924a8039f62202d9'),\n    title: 'Clean Code: A Handbook of Agile Software Craftsmanship',\n    author: 'Robert C. Martin',\n    category: 'Software Development',\n    year: 2008\n  },\n  {\n    _id: ObjectId('664ee452924a8039f62202da'),\n    title: 'JavaScript: The Good Parts',\n    author: 'Douglas Crockford',\n    category: 'JavaScript',\n    year: 2008\n  },\n  {\n    _id: ObjectId('664ee452924a8039f62202db'),\n    title: 'Design Patterns: Elements of Reusable Object-Oriented Software',\n    author: 'Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides',\n    category: 'Software Design',\n    year: 1994\n  },\n  {\n    _id: ObjectId('664ee452924a8039f62202dc'),\n    title: 'Introduction to Algorithms',\n    author: 'Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein',\n    category: 'Algorithms',\n    year: 1990\n  },\n  {\n    _id: ObjectId('664ee452924a8039f62202dd'),\n    title: 'Python Crash Course: A Hands-On, Project-Based Introduction to Programming',\n    author: 'Eric Matthes',\n    category: 'Python',\n    year: 2015\n  }\n]\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dracula\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #F8F8F2\">ProgBooksDB<\/span><span style=\"color: #FF79C6\">&gt;<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #BD93F9\">db<\/span><span style=\"color: #F8F8F2\">.<\/span><span style=\"color: #BD93F9\">ProgrammingBooks<\/span><span style=\"color: #F8F8F2\">.find().pretty()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    _id: ObjectId(<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">664ee3b1924a8039f62202d8<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    title: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">The Pragmatic Programmer: Your Journey to Mastery<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    author: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">David Thomas, Andrew Hunt<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    category: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Software Development<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">1999<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    _id: ObjectId(<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">664ee452924a8039f62202d9<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    title: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Clean Code: A Handbook of Agile Software Craftsmanship<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    author: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Robert C. Martin<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    category: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Software Development<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    _id: ObjectId(<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">664ee452924a8039f62202da<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    title: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">JavaScript: The Good Parts<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    author: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Douglas Crockford<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    category: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">JavaScript<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    _id: ObjectId(<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">664ee452924a8039f62202db<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    title: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Design Patterns: Elements of Reusable Object-Oriented Software<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    author: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    category: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Software Design<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">1994<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    _id: ObjectId(<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">664ee452924a8039f62202dc<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    title: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Introduction to Algorithms<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    author: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    category: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Algorithms<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">1990<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    _id: ObjectId(<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">664ee452924a8039f62202dd<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    title: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Python Crash Course: A Hands-On, Project-Based Introduction to Programming<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    author: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Eric Matthes<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    category: <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">Python<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">2015<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Find Documents Matching a Condition<\/strong><\/h5>\n\n\n\n<p>To find books published after the year 2000:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt; db.ProgrammingBooks.find({ year: { $gt: 2000 } }).pretty()\n[\n  {\n    _id: ObjectId('664ee452924a8039f62202d9'),\n    title: 'Clean Code: A Handbook of Agile Software Craftsmanship',\n    author: 'Robert C. Martin',\n    category: 'Software Development',\n    year: 2008\n  },\n  {\n    _id: ObjectId('664ee452924a8039f62202da'),\n    title: 'JavaScript: The Good Parts',\n    author: 'Douglas Crockford',\n    category: 'JavaScript',\n    year: 2008\n  },\n  {\n    _id: ObjectId('664ee452924a8039f62202dd'),\n    title: 'Python Crash Course: A Hands-On, Project-Based Introduction to Programming',\n    author: 'Eric Matthes',\n    category: 'Python',\n    year: 2015\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">db<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">ProgrammingBooks<\/span><span style=\"color: #E1E4E8\">.find({ <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: { $gt: <\/span><span style=\"color: #79B8FF\">2000<\/span><span style=\"color: #E1E4E8\"> } }).pretty()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;664ee452924a8039f62202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Clean Code: A Handbook of Agile Software Craftsmanship&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Robert C. Martin&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Software Development&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;664ee452924a8039f62202da&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;JavaScript: The Good Parts&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Douglas Crockford&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;JavaScript&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;664ee452924a8039f62202dd&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Python Crash Course: A Hands-On, Project-Based Introduction to Programming&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Eric Matthes&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Python&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2015<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Update Operations<\/h3>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>a. Update a Single Document<\/strong><\/h5>\n\n\n\n<p>To update a specific book (e.g., change the author of a book):<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt;db.ProgrammingBooks.updateOne(\n  { title: &quot;Clean Code: A Handbook of Agile Software Craftsmanship&quot; },\n  { $set: { author: &quot;Robert C. Martin (Uncle Bob)&quot; } }\n)\n\/\/verify by displaying books published in year 2008\nProgBooksDB&gt; db.ProgrammingBooks.find({ year: { $eq: 2008 } }).pretty()\n[\n  {\n    _id: ObjectId('663eaaebae582498972202df'),\n    title: 'Clean Code: A Handbook of Agile Software Craftsmanship',\n    author: 'Robert C. Martin (Uncle Bob)',\n    category: 'Software Development',\n    year: 2008\n  },\n  {\n    _id: ObjectId('663eaaebae582498972202e0'),\n    title: 'JavaScript: The Good Parts',\n    author: 'Douglas Crockford',\n    category: 'JavaScript',\n    year: 2008\n  }\n]\n\/\/another way to verify\nProgBooksDB&gt; db.ProgrammingBooks.find({ author: { $regex: &quot;Robert*&quot; } }).pretty()\n[\n  {\n    _id: ObjectId('664ee452924a8039f62202d9'),\n    title: 'Clean Code: A Handbook of Agile Software Craftsmanship',\n    author: 'Robert C. Martin (Uncle Bob)',\n    category: 'Software Development',\n    year: 2008\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #79B8FF\">db<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">ProgrammingBooks<\/span><span style=\"color: #E1E4E8\">.updateOne(<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;Clean Code: A Handbook of Agile Software Craftsmanship&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { $<\/span><span style=\"color: #F97583\">set<\/span><span style=\"color: #E1E4E8\">: { author: <\/span><span style=\"color: #9ECBFF\">&quot;Robert C. Martin (Uncle Bob)&quot;<\/span><span style=\"color: #E1E4E8\"> } }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">\/\/<\/span><span style=\"color: #E1E4E8\">verify <\/span><span style=\"color: #F97583\">by<\/span><span style=\"color: #E1E4E8\"> displaying books published <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">db<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">ProgrammingBooks<\/span><span style=\"color: #E1E4E8\">.find({ <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: { $eq: <\/span><span style=\"color: #79B8FF\">2008<\/span><span style=\"color: #E1E4E8\"> } }).pretty()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;663eaaebae582498972202df&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Clean Code: A Handbook of Agile Software Craftsmanship&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Robert C. Martin (Uncle Bob)&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Software Development&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;663eaaebae582498972202e0&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;JavaScript: The Good Parts&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Douglas Crockford&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;JavaScript&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">\/\/<\/span><span style=\"color: #E1E4E8\">another way <\/span><span style=\"color: #F97583\">to<\/span><span style=\"color: #E1E4E8\"> verify<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">db<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">ProgrammingBooks<\/span><span style=\"color: #E1E4E8\">.find({ author: { $regex: <\/span><span style=\"color: #9ECBFF\">&quot;Robert*&quot;<\/span><span style=\"color: #E1E4E8\"> } }).pretty()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;664ee452924a8039f62202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Clean Code: A Handbook of Agile Software Craftsmanship&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Robert C. Martin (Uncle Bob)&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Software Development&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>b. Update Multiple Documents<\/strong><\/h5>\n\n\n\n<p>To update multiple books (e.g., update the category of books published before 2010):<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt; db.ProgrammingBooks.updateMany(\n  { year: { $lt: 2010 } },\n  { $set: { category: &quot;Classic Programming Books&quot; } }\n)\n\/\/verify the update operation by displaying books published before year 2010\nProgBooksDB&gt; db.ProgrammingBooks.find({ year: { $lt: 2010 } }).pretty()\n[\n  {\n    _id: ObjectId('663eaaebae582498972202df'),\n    title: 'Clean Code: A Handbook of Agile Software Craftsmanship',\n    author: 'Robert C. Martin (Uncle Bob)',\n    category: 'Classic Programming Books',\n    year: 2008\n  },\n  {\n    _id: ObjectId('663eaaebae582498972202e0'),\n    title: 'JavaScript: The Good Parts',\n    author: 'Douglas Crockford',\n    category: 'Classic Programming Books',\n    year: 2008\n  },\n  {\n    _id: ObjectId('663eaaebae582498972202e1'),\n    title: 'Design Patterns: Elements of Reusable Object-Oriented Software',\n    author: 'Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides',\n    category: 'Classic Programming Books',\n    year: 1994\n  },\n  {\n    _id: ObjectId('663eaaebae582498972202e2'),\n    title: 'Introduction to Algorithms',\n    author: 'Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein',\n    category: 'Classic Programming Books',\n    year: 1990\n  },\n  {\n    _id: ObjectId('663eab05ae582498972202e4'),\n    title: 'The Pragmatic Programmer: Your Journey to Mastery',\n    author: 'David Thomas, Andrew Hunt',\n    category: 'Classic Programming Books',\n    year: 1999\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">db<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">ProgrammingBooks<\/span><span style=\"color: #E1E4E8\">.updateMany(<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: { $lt: <\/span><span style=\"color: #79B8FF\">2010<\/span><span style=\"color: #E1E4E8\"> } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { $<\/span><span style=\"color: #F97583\">set<\/span><span style=\"color: #E1E4E8\">: { category: <\/span><span style=\"color: #9ECBFF\">&quot;Classic Programming Books&quot;<\/span><span style=\"color: #E1E4E8\"> } }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #F97583\">\/\/<\/span><span style=\"color: #E1E4E8\">verify the <\/span><span style=\"color: #F97583\">update<\/span><span style=\"color: #E1E4E8\"> operation <\/span><span style=\"color: #F97583\">by<\/span><span style=\"color: #E1E4E8\"> displaying books published <\/span><span style=\"color: #F97583\">before<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">2010<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">db<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">ProgrammingBooks<\/span><span style=\"color: #E1E4E8\">.find({ <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: { $lt: <\/span><span style=\"color: #79B8FF\">2010<\/span><span style=\"color: #E1E4E8\"> } }).pretty()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;663eaaebae582498972202df&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Clean Code: A Handbook of Agile Software Craftsmanship&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Robert C. Martin (Uncle Bob)&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Classic Programming Books&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;663eaaebae582498972202e0&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;JavaScript: The Good Parts&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Douglas Crockford&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Classic Programming Books&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;663eaaebae582498972202e1&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Design Patterns: Elements of Reusable Object-Oriented Software&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Classic Programming Books&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1994<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;663eaaebae582498972202e2&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Introduction to Algorithms&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Classic Programming Books&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1990<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;663eab05ae582498972202e4&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;The Pragmatic Programmer: Your Journey to Mastery&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;David Thomas, Andrew Hunt&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Classic Programming Books&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">year<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1999<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Delete Operations<\/h3>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Delete a Single Document<\/strong><\/h5>\n\n\n\n<p>To delete a specific book from the collection (e.g., delete a book by title):<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt; db.ProgrammingBooks.deleteOne({ title: &quot;JavaScript: The Good Parts&quot; })\n{ acknowledged: true, deletedCount: 1 }\n\/\/Verify to see document is deleted\nProgBooksDB&gt; db.ProgrammingBooks.find({ title: &quot;JavaScript: The Good Parts&quot; }).pretty()\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">deleteOne<\/span><span style=\"color: #E1E4E8\">({ title: <\/span><span style=\"color: #9ECBFF\">&quot;JavaScript: The Good Parts&quot;<\/span><span style=\"color: #E1E4E8\"> })<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{ <\/span><span style=\"color: #B392F0\">acknowledged<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #B392F0\">deletedCount<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/Verify to see document is deleted<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({ title: <\/span><span style=\"color: #9ECBFF\">&quot;JavaScript: The Good Parts&quot;<\/span><span style=\"color: #E1E4E8\"> }).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Delete Multiple Documents<\/strong><\/h5>\n\n\n\n<p>To delete multiple books based on a condition (e.g., delete all books published before 1995):<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt; db.ProgrammingBooks.deleteMany({ year: { $lt: 1995 } })\n{ acknowledged: true, deletedCount: 2 }\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">deleteMany<\/span><span style=\"color: #E1E4E8\">({ year: { $lt: <\/span><span style=\"color: #79B8FF\">1995<\/span><span style=\"color: #E1E4E8\"> } })<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{ <\/span><span style=\"color: #B392F0\">acknowledged<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #B392F0\">deletedCount<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>You can check whether the specified documents were deleted by displaying the contents of the collection.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Delete All Documents in the Collection:<\/strong><\/h5>\n\n\n\n<p>To delete all documents in a collection (e.g.,&nbsp;<code>ProgrammingBooks<\/code>), use the&nbsp;<code>deleteMany()<\/code>&nbsp;method with an empty filter&nbsp;<code>{}<\/code>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/delete all documents in a collection\nProgBooksDB&gt; db.ProgrammingBooks.deleteMany({})\n{ acknowledged: true, deletedCount: 3 }\n\/\/verify by displaying the collection\nProgBooksDB&gt; db.ProgrammingBooks.find().pretty()\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #6A737D\">\/\/delete all documents in a collection<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">deleteMany<\/span><span style=\"color: #E1E4E8\">({})<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{ <\/span><span style=\"color: #B392F0\">acknowledged<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #B392F0\">deletedCount<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/verify by displaying the collection<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">().<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Projection Operations<\/h3>\n\n\n\n<p>In MongoDB, a projection refers to the mechanism of specifying which fields (or columns) should be returned from a query result. When querying a collection, you can use projection to control the shape of the returned documents by specifying which fields to include or exclude.<\/p>\n\n\n\n<p>In MongoDB, projection is typically specified as the second parameter to the <code>find()<\/code> method. The projection parameter takes an object where keys represent the fields to include or exclude, with values of <code>1<\/code> (include) or <code>0<\/code> (exclude).<\/p>\n\n\n\n<p><strong>Include Specific Fields:<\/strong> <\/p>\n\n\n\n<p>Use <code>1<\/code> to include a field in the result:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt; db.ProgrammingBooks.find({}, { title: 1, author: 1 } )\n[\n  {\n    _id: ObjectId('665163289edbdf91e12202dd'),\n    title: 'Clean Code: A Handbook of Agile Software Craftsmanship',\n    author: 'Robert C. Martin'\n  },\n  {\n    _id: ObjectId('665163289edbdf91e12202e1'),\n    title: 'Python Crash Course: A Hands-On, Project-Based Introduction to Programming',\n    author: 'Eric Matthes'\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({}, { title: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, author: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> } )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665163289edbdf91e12202dd&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Clean Code: A Handbook of Agile Software Craftsmanship&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Robert C. Martin&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665163289edbdf91e12202e1&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Python Crash Course: A Hands-On, Project-Based Introduction to Programming&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Eric Matthes&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Exclude Specific Fields:<\/strong> <\/p>\n\n\n\n<p>Use <code>0<\/code> to exclude a field from the result:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt; db.ProgrammingBooks.find({}, {year: 0})\n[\n  {\n    _id: ObjectId('665163289edbdf91e12202dd'),\n    title: 'Clean Code: A Handbook of Agile Software Craftsmanship',\n    author: 'Robert C. Martin',\n    category: 'Software Development'\n  },\n  {\n    _id: ObjectId('665163289edbdf91e12202e1'),\n    title: 'Python Crash Course: A Hands-On, Project-Based Introduction to Programming',\n    author: 'Eric Matthes',\n    category: 'Python'\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({}, {year: <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\">})<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665163289edbdf91e12202dd&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Clean Code: A Handbook of Agile Software Craftsmanship&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Robert C. Martin&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Software Development&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665163289edbdf91e12202e1&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Python Crash Course: A Hands-On, Project-Based Introduction to Programming&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Eric Matthes&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Python&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Where Clause, AND,OR operations in MongoDB.<\/h2>\n\n\n\n<p id=\"P01a\"><strong>a. Illustration of Where Clause, AND,OR operations in MongoDB.<\/strong><\/p>\n\n\n\n<p>In MongoDB, the equivalent of SQL&#8217;s <code>WHERE<\/code> clause is achieved using query filters within the <code>find()<\/code> method. You can also combine multiple conditions using logical operators like <code>$and<\/code> and <code>$or<\/code>. Here\u2019s how you can illustrate the usage of these features:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Setting Up Example Data<\/h3>\n\n\n\n<p>First, let&#8217;s assume we have a collection named <code>ProgrammingBooks<\/code> with the following documents:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"ProgBooksDB&gt; use newDB\nswitched to db newDB\nnewDB&gt; db.createCollection(&quot;ProgrammingBooks&quot;)\n{ ok: 1 }\nnewDB&gt; db.ProgrammingBooks.insertMany([\n  { title: &quot;Clean Code&quot;, author: &quot;Robert C. Martin&quot;, category: &quot;Software Development&quot;, year: 2008 },\n  { title: &quot;JavaScript: The Good Parts&quot;, author: &quot;Douglas Crockford&quot;, category: &quot;JavaScript&quot;, year: 2008 },\n  { title: &quot;Design Patterns&quot;, author: &quot;Erich Gamma&quot;, category: &quot;Software Design&quot;, year: 1994 },\n  { title: &quot;Introduction to Algorithms&quot;, author: &quot;Thomas H. Cormen&quot;, category: &quot;Algorithms&quot;, year: 2009 },\n  { title: &quot;Python Crash Course&quot;, author: &quot;Eric Matthes&quot;, category: &quot;Python&quot;, year: 2015 }\n]);\n{\n  acknowledged: true,\n  insertedIds: {\n    '0': ObjectId('6651daad9edbdf91e12202e2'),\n    '1': ObjectId('6651daad9edbdf91e12202e3'),\n    '2': ObjectId('6651daad9edbdf91e12202e4'),\n    '3': ObjectId('6651daad9edbdf91e12202e5'),\n    '4': ObjectId('6651daad9edbdf91e12202e6')\n  }\n}\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">ProgBooksDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> use newDB<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">switched to db newDB<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">newDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.<\/span><span style=\"color: #B392F0\">createCollection<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;ProgrammingBooks&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{ <\/span><span style=\"color: #B392F0\">ok<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">newDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">insertMany<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;Clean Code&quot;<\/span><span style=\"color: #E1E4E8\">, author: <\/span><span style=\"color: #9ECBFF\">&quot;Robert C. Martin&quot;<\/span><span style=\"color: #E1E4E8\">, category: <\/span><span style=\"color: #9ECBFF\">&quot;Software Development&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">2008<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;JavaScript: The Good Parts&quot;<\/span><span style=\"color: #E1E4E8\">, author: <\/span><span style=\"color: #9ECBFF\">&quot;Douglas Crockford&quot;<\/span><span style=\"color: #E1E4E8\">, category: <\/span><span style=\"color: #9ECBFF\">&quot;JavaScript&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">2008<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;Design Patterns&quot;<\/span><span style=\"color: #E1E4E8\">, author: <\/span><span style=\"color: #9ECBFF\">&quot;Erich Gamma&quot;<\/span><span style=\"color: #E1E4E8\">, category: <\/span><span style=\"color: #9ECBFF\">&quot;Software Design&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">1994<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;Introduction to Algorithms&quot;<\/span><span style=\"color: #E1E4E8\">, author: <\/span><span style=\"color: #9ECBFF\">&quot;Thomas H. Cormen&quot;<\/span><span style=\"color: #E1E4E8\">, category: <\/span><span style=\"color: #9ECBFF\">&quot;Algorithms&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">2009<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;Python Crash Course&quot;<\/span><span style=\"color: #E1E4E8\">, author: <\/span><span style=\"color: #9ECBFF\">&quot;Eric Matthes&quot;<\/span><span style=\"color: #E1E4E8\">, category: <\/span><span style=\"color: #9ECBFF\">&quot;Python&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">2015<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">]);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">acknowledged<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">insertedIds<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;0&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e2&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;1&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e3&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;2&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e4&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;3&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e5&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;4&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e6&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Using the <code>WHERE<\/code> Clause Equivalent<\/h3>\n\n\n\n<p>To query documents with specific conditions, you can use the <code>find()<\/code> method with a filter object. For example, to find books published in the year 2008:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"newDB&gt; db.ProgrammingBooks.find({ year: 2008 }).pretty()\n[\n  {\n    _id: ObjectId('6651daad9edbdf91e12202e2'),\n    title: 'Clean Code',\n    author: 'Robert C. Martin',\n    category: 'Software Development',\n    year: 2008\n  },\n  {\n    _id: ObjectId('6651daad9edbdf91e12202e3'),\n    title: 'JavaScript: The Good Parts',\n    author: 'Douglas Crockford',\n    category: 'JavaScript',\n    year: 2008\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">newDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({ year: <\/span><span style=\"color: #79B8FF\">2008<\/span><span style=\"color: #E1E4E8\"> }).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e2&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Clean Code&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Robert C. Martin&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Software Development&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e3&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;JavaScript: The Good Parts&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Douglas Crockford&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;JavaScript&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Using the <code>$and<\/code> Operator<\/h3>\n\n\n\n<p>The <code>$and<\/code> operator is used to combine multiple conditions that must all be true. Here\u2019s how to find books that are in the &#8220;Software Development&#8221; category and published in the year 2008:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"newDB&gt;db.ProgrammingBooks.find({\n  $and: [\n    { category: &quot;Software Development&quot; },\n    { year: 2008 }\n  ]\n}).pretty()\n[\n  {\n    _id: ObjectId('6651daad9edbdf91e12202e2'),\n    title: 'Clean Code',\n    author: 'Robert C. Martin',\n    category: 'Software Development',\n    year: 2008\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">newDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\">db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  $and: [<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    { category: <\/span><span style=\"color: #9ECBFF\">&quot;Software Development&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    { year: <\/span><span style=\"color: #79B8FF\">2008<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  ]<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e2&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Clean Code&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Robert C. Martin&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Software Development&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this query:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Both conditions must be met for a document to be included in the result.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Using the <code>$or<\/code> Operator<\/h3>\n\n\n\n<p>The <code>$or<\/code> operator is used to combine multiple conditions where at least one must be true. Here\u2019s how to find books that are either in the &#8220;JavaScript&#8221; category or published in the year 2015:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"newDB&gt; db.ProgrammingBooks.find({\n  $or: [\n    { category: &quot;JavaScript&quot; },\n    { year: 2015 }\n  ]\n}).pretty()\n[\n  {\n    _id: ObjectId('6651daad9edbdf91e12202e3'),\n    title: 'JavaScript: The Good Parts',\n    author: 'Douglas Crockford',\n    category: 'JavaScript',\n    year: 2008\n  },\n  {\n    _id: ObjectId('6651daad9edbdf91e12202e6'),\n    title: 'Python Crash Course',\n    author: 'Eric Matthes',\n    category: 'Python',\n    year: 2015\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">newDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  $or: [<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    { category: <\/span><span style=\"color: #9ECBFF\">&quot;JavaScript&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    { year: <\/span><span style=\"color: #79B8FF\">2015<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  ]<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e3&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;JavaScript: The Good Parts&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Douglas Crockford&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;JavaScript&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e6&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Python Crash Course&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Eric Matthes&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Python&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2015<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this query:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A document will be included in the result if it meets either condition.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Combining <code>$and<\/code> and <code>$or<\/code> Operators<\/h3>\n\n\n\n<p>You can combine <code>$and<\/code> and <code>$or<\/code> operators for more complex queries. For example, to find books that are either in the &#8220;Software Development&#8221; category and published after 2007, or in the &#8220;Python&#8221; category:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"newDB&gt; db.ProgrammingBooks.find({\n  $or: [\n    {\n      $and: [\n        { category: &quot;Software Development&quot; },\n        { year: { $gt: 2007 } }\n      ]\n    },\n    { category: &quot;Python&quot; }\n  ]\n}).pretty()\n[\n  {\n    _id: ObjectId('6651daad9edbdf91e12202e2'),\n    title: 'Clean Code',\n    author: 'Robert C. Martin',\n    category: 'Software Development',\n    year: 2008\n  },\n  {\n    _id: ObjectId('6651daad9edbdf91e12202e6'),\n    title: 'Python Crash Course',\n    author: 'Eric Matthes',\n    category: 'Python',\n    year: 2015\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">newDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.ProgrammingBooks.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  $or: [<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    {<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">      $and: [<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">        { category: <\/span><span style=\"color: #9ECBFF\">&quot;Software Development&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">        { year: { $gt: <\/span><span style=\"color: #79B8FF\">2007<\/span><span style=\"color: #E1E4E8\"> } }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">      ]<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    { category: <\/span><span style=\"color: #9ECBFF\">&quot;Python&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  ]<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e2&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Clean Code&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Robert C. Martin&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Software Development&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2008<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;6651daad9edbdf91e12202e6&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Python Crash Course&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    author: <\/span><span style=\"color: #9ECBFF\">&#39;Eric Matthes&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&#39;Python&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2015<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this query:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The document will be included if it meets the combined <code>$and<\/code> conditions of being in the &#8220;Software Development&#8221; category and published after 2007, or if it is in the &#8220;Python&#8221; category.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading has-e-1-e-4-e-8-color has-text-color\" id=\"P02\">Question 2 <\/h2>\n\n\n\n<h2 class=\"wp-block-heading has-e-1-e-4-e-8-color has-text-color\" id=\"P02a\">a. Select and ignore fields<\/h2>\n\n\n\n<p><strong>Develop a MongoDB query to select certain fields and ignore some fields of the documents from any collection.<\/strong><\/p>\n\n\n\n<p>To select certain fields and ignore others in MongoDB, you use projections in your queries. Projections allow you to specify which fields to include or exclude in the returned documents.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-e-1-e-4-e-8-color has-text-color\">Create database and create the Collection:<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(253, 253, 237, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"test&gt; use MoviesDB\nswitched to db MoviesDB\nMoviesDB&gt; db.createCollection(&quot;Movies&quot;)\n{ ok: 1 }\nMoviesDB&gt; db.Movies.insertMany([\n  { title: &quot;Inception&quot;, director: &quot;Christopher Nolan&quot;, genre: &quot;Science Fiction&quot;, year: 2010, ratings: { imdb: 8.8, rottenTomatoes: 87 } },\n  { title: &quot;The Matrix&quot;, director: &quot;Wachowskis&quot;, genre: &quot;Science Fiction&quot;, year: 1999, ratings: { imdb: 8.7, rottenTomatoes: 87 } },\n  { title: &quot;The Godfather&quot;, director: &quot;Francis Ford Coppola&quot;, genre: &quot;Crime&quot;, year: 1972, ratings: { imdb: 9.2, rottenTomatoes: 97 } }\n]);\n{\n  acknowledged: true,\n  insertedIds: {\n    '0': ObjectId('66523751d5449c3abf2202d8'),\n    '1': ObjectId('66523751d5449c3abf2202d9'),\n    '2': ObjectId('66523751d5449c3abf2202da')\n  }\n}\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dracula\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #F8F8F2\">test<\/span><span style=\"color: #FF79C6\">&gt;<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #FF79C6\">use<\/span><span style=\"color: #F8F8F2\"> MoviesDB<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">switched <\/span><span style=\"color: #FF79C6\">to<\/span><span style=\"color: #F8F8F2\"> db MoviesDB<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #F8F8F2\">MoviesDB<\/span><span style=\"color: #FF79C6\">&gt;<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #BD93F9\">db<\/span><span style=\"color: #F8F8F2\">.<\/span><span style=\"color: #BD93F9\">createCollection<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Movies<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">{ ok: <\/span><span style=\"color: #BD93F9\">1<\/span><span style=\"color: #F8F8F2\"> }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #F8F8F2\">MoviesDB<\/span><span style=\"color: #FF79C6\">&gt;<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #BD93F9\">db<\/span><span style=\"color: #F8F8F2\">.<\/span><span style=\"color: #BD93F9\">Movies<\/span><span style=\"color: #F8F8F2\">.insertMany([<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #F8F8F2\">  { title: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Inception<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">, director: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Christopher Nolan<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">, genre: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Science Fiction<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">2010<\/span><span style=\"color: #F8F8F2\">, ratings: { imdb: <\/span><span style=\"color: #BD93F9\">8<\/span><span style=\"color: #F8F8F2\">.<\/span><span style=\"color: #BD93F9\">8<\/span><span style=\"color: #F8F8F2\">, rottenTomatoes: <\/span><span style=\"color: #BD93F9\">87<\/span><span style=\"color: #F8F8F2\"> } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #F8F8F2\">  { title: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">The Matrix<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">, director: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Wachowskis<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">, genre: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Science Fiction<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">1999<\/span><span style=\"color: #F8F8F2\">, ratings: { imdb: <\/span><span style=\"color: #BD93F9\">8<\/span><span style=\"color: #F8F8F2\">.<\/span><span style=\"color: #BD93F9\">7<\/span><span style=\"color: #F8F8F2\">, rottenTomatoes: <\/span><span style=\"color: #BD93F9\">87<\/span><span style=\"color: #F8F8F2\"> } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #F8F8F2\">  { title: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">The Godfather<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">, director: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Francis Ford Coppola<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">, genre: <\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F1FA8C\">Crime<\/span><span style=\"color: #E9F284\">&quot;<\/span><span style=\"color: #F8F8F2\">, <\/span><span style=\"color: #FF79C6\">year<\/span><span style=\"color: #F8F8F2\">: <\/span><span style=\"color: #BD93F9\">1972<\/span><span style=\"color: #F8F8F2\">, ratings: { imdb: <\/span><span style=\"color: #BD93F9\">9<\/span><span style=\"color: #F8F8F2\">.<\/span><span style=\"color: #BD93F9\">2<\/span><span style=\"color: #F8F8F2\">, rottenTomatoes: <\/span><span style=\"color: #BD93F9\">97<\/span><span style=\"color: #F8F8F2\"> } }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #F8F8F2\">]);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  acknowledged: true,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  insertedIds: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">0<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">: ObjectId(<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">66523751d5449c3abf2202d8<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">1<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">: ObjectId(<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">66523751d5449c3abf2202d9<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">2<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">: ObjectId(<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F1FA8C\">66523751d5449c3abf2202da<\/span><span style=\"color: #E9F284\">&#39;<\/span><span style=\"color: #F8F8F2\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Syntax for Projection<\/h3>\n\n\n\n<p>When using the <code>find()<\/code> method, the first parameter is the query filter, and the second parameter is the projection object. The projection object specifies the fields to include (using <code>1<\/code>) or exclude (using <code>0<\/code>).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Including Specific Fields<\/h3>\n\n\n\n<p>To include specific fields, set the fields you want to include to <code>1<\/code>:<\/p>\n\n\n\n<p>To select only the <code>title<\/code> and <code>director<\/code> fields from the <code>Movies<\/code> collection:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"MoviesDB&gt; db.Movies.find({}, { title: 1, director: 1 })\n[\n  {\n    _id: ObjectId('66523751d5449c3abf2202d8'),\n    title: 'Inception',\n    director: 'Christopher Nolan'\n  },\n  {\n    _id: ObjectId('66523751d5449c3abf2202d9'),\n    title: 'The Matrix',\n    director: 'Wachowskis'\n  },\n  {\n    _id: ObjectId('66523751d5449c3abf2202da'),\n    title: 'The Godfather',\n    director: 'Francis Ford Coppola'\n  }\n]\nMoviesDB&gt; db.Movies.find({}, { title: 1, director: 1, _id: 0 })\n[\n  { title: 'Inception', director: 'Christopher Nolan' },\n  { title: 'The Matrix', director: 'Wachowskis' },\n  { title: 'The Godfather', director: 'Francis Ford Coppola' }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">MoviesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">db<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">Movies<\/span><span style=\"color: #E1E4E8\">.find({}, { title: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> })<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;66523751d5449c3abf2202d8&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Inception&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    director: <\/span><span style=\"color: #9ECBFF\">&#39;Christopher Nolan&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;66523751d5449c3abf2202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;The Matrix&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    director: <\/span><span style=\"color: #9ECBFF\">&#39;Wachowskis&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;66523751d5449c3abf2202da&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;The Godfather&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    director: <\/span><span style=\"color: #9ECBFF\">&#39;Francis Ford Coppola&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">MoviesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">db<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">Movies<\/span><span style=\"color: #E1E4E8\">.find({}, { title: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, _id: <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\"> })<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&#39;Inception&#39;<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #9ECBFF\">&#39;Christopher Nolan&#39;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&#39;The Matrix&#39;<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #9ECBFF\">&#39;Wachowskis&#39;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&#39;The Godfather&#39;<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #9ECBFF\">&#39;Francis Ford Coppola&#39;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this query:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The filter <code>{}<\/code> means we want to select all documents.<\/li>\n\n\n\n<li>The projection <code>{ title: 1, director: 1, _id: 0 }<\/code> means we include the <code>title<\/code> and <code>director<\/code> fields, and exclude the <code>_id<\/code> field (which is included by default unless explicitly excluded).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Excluding Specific Fields<\/h3>\n\n\n\n<p>To exclude specific fields, set the fields you want to exclude to <code>0<\/code>:<\/p>\n\n\n\n<p>To exclude the <code>ratings<\/code> field from the results:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"MoviesDB&gt; db.Movies.find({}, { ratings: 0 })\n[\n  {\n    _id: ObjectId('66523751d5449c3abf2202d8'),\n    title: 'Inception',\n    director: 'Christopher Nolan',\n    genre: 'Science Fiction',\n    year: 2010\n  },\n  {\n    _id: ObjectId('66523751d5449c3abf2202d9'),\n    title: 'The Matrix',\n    director: 'Wachowskis',\n    genre: 'Science Fiction',\n    year: 1999\n  },\n  {\n    _id: ObjectId('66523751d5449c3abf2202da'),\n    title: 'The Godfather',\n    director: 'Francis Ford Coppola',\n    genre: 'Crime',\n    year: 1972\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">MoviesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Movies.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({}, { ratings: <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\"> })<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;66523751d5449c3abf2202d8&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;Inception&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    director: <\/span><span style=\"color: #9ECBFF\">&#39;Christopher Nolan&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Science Fiction&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2010<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;66523751d5449c3abf2202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;The Matrix&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    director: <\/span><span style=\"color: #9ECBFF\">&#39;Wachowskis&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Science Fiction&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">1999<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;66523751d5449c3abf2202da&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    title: <\/span><span style=\"color: #9ECBFF\">&#39;The Godfather&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    director: <\/span><span style=\"color: #9ECBFF\">&#39;Francis Ford Coppola&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Crime&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">1972<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this query:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The filter <code>{}<\/code> means we want to select all documents.<\/li>\n\n\n\n<li>The projection <code>{ ratings: 0 }<\/code> means we exclude the <code>ratings<\/code> field.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Combining Filter and Projection<\/h3>\n\n\n\n<p>You can also combine a query filter with a projection. For example, to find movies directed by &#8220;Christopher Nolan&#8221; and include only the <code>title<\/code> and <code>year<\/code> fields:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"MoviesDB&gt; db.Movies.find({ director: &quot;Christopher Nolan&quot; }, { title: 1, year: 1, _id: 0 })\n[ { title: 'Inception', year: 2010 } ]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">MoviesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Movies.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({ director: <\/span><span style=\"color: #9ECBFF\">&quot;Christopher Nolan&quot;<\/span><span style=\"color: #E1E4E8\"> }, { title: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, _id: <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\"> })<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[ { title: <\/span><span style=\"color: #9ECBFF\">&#39;Inception&#39;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">2010<\/span><span style=\"color: #E1E4E8\"> } ]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this query:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The filter <code>{ director: \"Christopher Nolan\" }<\/code> selects documents where the <code>director<\/code> is &#8220;Christopher Nolan&#8221;.<\/li>\n\n\n\n<li>The projection <code>{ title: 1, year: 1, _id: 0 }<\/code> includes only the <code>title<\/code> and <code>year<\/code> fields and excludes the <code>_id<\/code> field.<\/li>\n<\/ul>\n\n\n\n<p>In MongoDB, projections are used to control which fields are included or excluded in the returned documents. This is useful for optimizing queries and reducing the amount of data transferred over the network. You specify projections as the second parameter in the <code>find()<\/code> method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"P02b\">b. Use of limit and find in MongoDB query<\/h2>\n\n\n\n<p><strong>Develop a MongoDB query to display the first 5 documents from the results obtained in a. (illustrate use of limit and find)<\/strong><\/p>\n\n\n\n<p>To display the first 5 documents from a query result in MongoDB, you can use the <code>limit()<\/code> method in conjunction with the <code>find()<\/code> method. The <code>limit()<\/code> method restricts the number of documents returned by the query to the specified number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example Scenario<\/h3>\n\n\n\n<p>Assume we have the <code>Movies<\/code> collection as described previously:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"test&gt; use MoviesDB\nswitched to db MoviesDB\nMoviesDB&gt; db.createCollection(&quot;Movies&quot;)\n{ ok: 1 }\nMoviesDB&gt;db.Movies.insertMany([\n  { title: &quot;Inception&quot;, director: &quot;Christopher Nolan&quot;, genre: &quot;Science Fiction&quot;, year: 2010, ratings: { imdb: 8.8, rottenTomatoes: 87 } },\n  { title: &quot;The Matrix&quot;, director: &quot;Wachowskis&quot;, genre: &quot;Science Fiction&quot;, year: 1999, ratings: { imdb: 8.7, rottenTomatoes: 87 } },\n  { title: &quot;The Godfather&quot;, director: &quot;Francis Ford Coppola&quot;, genre: &quot;Crime&quot;, year: 1972, ratings: { imdb: 9.2, rottenTomatoes: 97 } },\n  { title: &quot;Pulp Fiction&quot;, director: &quot;Quentin Tarantino&quot;, genre: &quot;Crime&quot;, year: 1994, ratings: { imdb: 8.9, rottenTomatoes: 92 } },\n  { title: &quot;The Shawshank Redemption&quot;, director: &quot;Frank Darabont&quot;, genre: &quot;Drama&quot;, year: 1994, ratings: { imdb: 9.3, rottenTomatoes: 91 } },\n  { title: &quot;The Dark Knight&quot;, director: &quot;Christopher Nolan&quot;, genre: &quot;Action&quot;, year: 2008, ratings: { imdb: 9.0, rottenTomatoes: 94 } },\n  { title: &quot;Fight Club&quot;, director: &quot;David Fincher&quot;, genre: &quot;Drama&quot;, year: 1999, ratings: { imdb: 8.8, rottenTomatoes: 79 } }\n]);\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">test<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> use MoviesDB<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">switched to db MoviesDB<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">MoviesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.<\/span><span style=\"color: #B392F0\">createCollection<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Movies&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{ <\/span><span style=\"color: #B392F0\">ok<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">MoviesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\">db.Movies.<\/span><span style=\"color: #B392F0\">insertMany<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;Inception&quot;<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #9ECBFF\">&quot;Christopher Nolan&quot;<\/span><span style=\"color: #E1E4E8\">, genre: <\/span><span style=\"color: #9ECBFF\">&quot;Science Fiction&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">2010<\/span><span style=\"color: #E1E4E8\">, ratings: { imdb: <\/span><span style=\"color: #79B8FF\">8.8<\/span><span style=\"color: #E1E4E8\">, rottenTomatoes: <\/span><span style=\"color: #79B8FF\">87<\/span><span style=\"color: #E1E4E8\"> } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;The Matrix&quot;<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #9ECBFF\">&quot;Wachowskis&quot;<\/span><span style=\"color: #E1E4E8\">, genre: <\/span><span style=\"color: #9ECBFF\">&quot;Science Fiction&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">1999<\/span><span style=\"color: #E1E4E8\">, ratings: { imdb: <\/span><span style=\"color: #79B8FF\">8.7<\/span><span style=\"color: #E1E4E8\">, rottenTomatoes: <\/span><span style=\"color: #79B8FF\">87<\/span><span style=\"color: #E1E4E8\"> } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;The Godfather&quot;<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #9ECBFF\">&quot;Francis Ford Coppola&quot;<\/span><span style=\"color: #E1E4E8\">, genre: <\/span><span style=\"color: #9ECBFF\">&quot;Crime&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">1972<\/span><span style=\"color: #E1E4E8\">, ratings: { imdb: <\/span><span style=\"color: #79B8FF\">9.2<\/span><span style=\"color: #E1E4E8\">, rottenTomatoes: <\/span><span style=\"color: #79B8FF\">97<\/span><span style=\"color: #E1E4E8\"> } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;Pulp Fiction&quot;<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #9ECBFF\">&quot;Quentin Tarantino&quot;<\/span><span style=\"color: #E1E4E8\">, genre: <\/span><span style=\"color: #9ECBFF\">&quot;Crime&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">1994<\/span><span style=\"color: #E1E4E8\">, ratings: { imdb: <\/span><span style=\"color: #79B8FF\">8.9<\/span><span style=\"color: #E1E4E8\">, rottenTomatoes: <\/span><span style=\"color: #79B8FF\">92<\/span><span style=\"color: #E1E4E8\"> } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;The Shawshank Redemption&quot;<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #9ECBFF\">&quot;Frank Darabont&quot;<\/span><span style=\"color: #E1E4E8\">, genre: <\/span><span style=\"color: #9ECBFF\">&quot;Drama&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">1994<\/span><span style=\"color: #E1E4E8\">, ratings: { imdb: <\/span><span style=\"color: #79B8FF\">9.3<\/span><span style=\"color: #E1E4E8\">, rottenTomatoes: <\/span><span style=\"color: #79B8FF\">91<\/span><span style=\"color: #E1E4E8\"> } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;The Dark Knight&quot;<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #9ECBFF\">&quot;Christopher Nolan&quot;<\/span><span style=\"color: #E1E4E8\">, genre: <\/span><span style=\"color: #9ECBFF\">&quot;Action&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">2008<\/span><span style=\"color: #E1E4E8\">, ratings: { imdb: <\/span><span style=\"color: #79B8FF\">9.0<\/span><span style=\"color: #E1E4E8\">, rottenTomatoes: <\/span><span style=\"color: #79B8FF\">94<\/span><span style=\"color: #E1E4E8\"> } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { title: <\/span><span style=\"color: #9ECBFF\">&quot;Fight Club&quot;<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #9ECBFF\">&quot;David Fincher&quot;<\/span><span style=\"color: #E1E4E8\">, genre: <\/span><span style=\"color: #9ECBFF\">&quot;Drama&quot;<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">1999<\/span><span style=\"color: #E1E4E8\">, ratings: { imdb: <\/span><span style=\"color: #79B8FF\">8.8<\/span><span style=\"color: #E1E4E8\">, rottenTomatoes: <\/span><span style=\"color: #79B8FF\">79<\/span><span style=\"color: #E1E4E8\"> } }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">]);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Query with Projection and Limit<\/h3>\n\n\n\n<p>Suppose you want to display the first 5 documents from the <code>Movies<\/code> collection, including only the <code>title<\/code>, <code>director<\/code>, and <code>year<\/code> fields. Here\u2019s how you can do it:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"MoviesDB&gt; db.Movies.find({}, { title: 1, director: 1, year: 1, _id: 0 }).limit(5)\n[\n  { &quot;title&quot;: &quot;Inception&quot;, &quot;director&quot;: &quot;Christopher Nolan&quot;, &quot;year&quot;: 2010 },\n  { &quot;title&quot;: &quot;The Matrix&quot;, &quot;director&quot;: &quot;Wachowskis&quot;, &quot;year&quot;: 1999 },\n  { &quot;title&quot;: &quot;The Godfather&quot;, &quot;director&quot;: &quot;Francis Ford Coppola&quot;, &quot;year&quot;: 1972 },\n  { &quot;title&quot;: &quot;Pulp Fiction&quot;, &quot;director&quot;: &quot;Quentin Tarantino&quot;, &quot;year&quot;: 1994 },\n  { &quot;title&quot;: &quot;The Shawshank Redemption&quot;, &quot;director&quot;: &quot;Frank Darabont&quot;, &quot;year&quot;: 1994 }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">MoviesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Movies.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({}, { title: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, director: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, year: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, _id: <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\"> }).<\/span><span style=\"color: #B392F0\">limit<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;title&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Inception&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;director&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Christopher Nolan&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;year&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2010<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;title&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;The Matrix&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;director&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Wachowskis&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;year&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1999<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;title&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;The Godfather&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;director&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Francis Ford Coppola&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;year&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1972<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;title&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Pulp Fiction&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;director&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Quentin Tarantino&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;year&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1994<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;title&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;The Shawshank Redemption&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;director&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Frank Darabont&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;year&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1994<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>find({})<\/code><\/strong>: This filter <code>{}<\/code> selects all documents in the collection.<\/li>\n\n\n\n<li><strong><code>{ title: 1, director: 1, year: 1, _id: 0 }<\/code><\/strong>: This projection includes the <code>title<\/code>, <code>director<\/code>, and <code>year<\/code> fields, and excludes the <code>_id<\/code> field.<\/li>\n\n\n\n<li><strong><code>.limit(5)<\/code><\/strong>: This method limits the query result to the first 5 documents.<\/li>\n<\/ul>\n\n\n\n<p>By using the <code>find()<\/code> method with a projection and the <code>limit()<\/code> method, you can efficiently query and display a subset of documents from a MongoDB collection. This approach helps manage large datasets by retrieving only a specific number of documents, which is particularly useful for paginating results in applications.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P03\">Question 3<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"P03a\">a. Query selectors (comparison selectors, logical selectors )<\/h2>\n\n\n\n<p><strong>Execute query selectors (comparison selectors, logical selectors ) and list out the results on any collection<\/strong><\/p>\n\n\n\n<p>Let&#8217;s create a new collection called <code>Employees<\/code> and insert some documents into it. Then, we&#8217;ll demonstrate the use of comparison selectors and logical selectors to query this collection.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create the <code>Employees<\/code> Collection and Insert Documents<\/h3>\n\n\n\n<p>First, we need to create the <code>Employees<\/code> collection and insert some sample documents.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"test&gt; use companyDB\ncompanyDB&gt; db.Employees.insertMany([\n  { name: &quot;Alice&quot;, age: 30, department: &quot;HR&quot;, salary: 50000, joinDate: new Date(&quot;2015-01-15&quot;) },\n  { name: &quot;Bob&quot;, age: 24, department: &quot;Engineering&quot;, salary: 70000, joinDate: new Date(&quot;2019-03-10&quot;) },\n  { name: &quot;Charlie&quot;, age: 29, department: &quot;Engineering&quot;, salary: 75000, joinDate: new Date(&quot;2017-06-23&quot;) },\n  { name: &quot;David&quot;, age: 35, department: &quot;Marketing&quot;, salary: 60000, joinDate: new Date(&quot;2014-11-01&quot;) },\n  { name: &quot;Eve&quot;, age: 28, department: &quot;Finance&quot;, salary: 80000, joinDate: new Date(&quot;2018-08-19&quot;) }\n])\n{\n  acknowledged: true,\n  insertedIds: {\n    '0': ObjectId('665356cff5b334bcf92202d8'),\n    '1': ObjectId('665356cff5b334bcf92202d9'),\n    '2': ObjectId('665356cff5b334bcf92202da'),\n    '3': ObjectId('665356cff5b334bcf92202db'),\n    '4': ObjectId('665356cff5b334bcf92202dc')\n  }\n}\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">test<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> use companyDB<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">companyDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Employees.<\/span><span style=\"color: #B392F0\">insertMany<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Alice&quot;<\/span><span style=\"color: #E1E4E8\">, age: <\/span><span style=\"color: #79B8FF\">30<\/span><span style=\"color: #E1E4E8\">, department: <\/span><span style=\"color: #9ECBFF\">&quot;HR&quot;<\/span><span style=\"color: #E1E4E8\">, salary: <\/span><span style=\"color: #79B8FF\">50000<\/span><span style=\"color: #E1E4E8\">, joinDate: <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Date<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;2015-01-15&quot;<\/span><span style=\"color: #E1E4E8\">) },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Bob&quot;<\/span><span style=\"color: #E1E4E8\">, age: <\/span><span style=\"color: #79B8FF\">24<\/span><span style=\"color: #E1E4E8\">, department: <\/span><span style=\"color: #9ECBFF\">&quot;Engineering&quot;<\/span><span style=\"color: #E1E4E8\">, salary: <\/span><span style=\"color: #79B8FF\">70000<\/span><span style=\"color: #E1E4E8\">, joinDate: <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Date<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;2019-03-10&quot;<\/span><span style=\"color: #E1E4E8\">) },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Charlie&quot;<\/span><span style=\"color: #E1E4E8\">, age: <\/span><span style=\"color: #79B8FF\">29<\/span><span style=\"color: #E1E4E8\">, department: <\/span><span style=\"color: #9ECBFF\">&quot;Engineering&quot;<\/span><span style=\"color: #E1E4E8\">, salary: <\/span><span style=\"color: #79B8FF\">75000<\/span><span style=\"color: #E1E4E8\">, joinDate: <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Date<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;2017-06-23&quot;<\/span><span style=\"color: #E1E4E8\">) },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;David&quot;<\/span><span style=\"color: #E1E4E8\">, age: <\/span><span style=\"color: #79B8FF\">35<\/span><span style=\"color: #E1E4E8\">, department: <\/span><span style=\"color: #9ECBFF\">&quot;Marketing&quot;<\/span><span style=\"color: #E1E4E8\">, salary: <\/span><span style=\"color: #79B8FF\">60000<\/span><span style=\"color: #E1E4E8\">, joinDate: <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Date<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;2014-11-01&quot;<\/span><span style=\"color: #E1E4E8\">) },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Eve&quot;<\/span><span style=\"color: #E1E4E8\">, age: <\/span><span style=\"color: #79B8FF\">28<\/span><span style=\"color: #E1E4E8\">, department: <\/span><span style=\"color: #9ECBFF\">&quot;Finance&quot;<\/span><span style=\"color: #E1E4E8\">, salary: <\/span><span style=\"color: #79B8FF\">80000<\/span><span style=\"color: #E1E4E8\">, joinDate: <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Date<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;2018-08-19&quot;<\/span><span style=\"color: #E1E4E8\">) }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">])<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">acknowledged<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">insertedIds<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;0&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202d8&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;1&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;2&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202da&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;3&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202db&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;4&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202dc&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Queries Using Comparison Selectors<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. <code>$eq<\/code> (Equal)<\/h4>\n\n\n\n<p>Find employees in the &#8220;Engineering&#8221; department.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"companyDB&gt; db.Employees.find({ department: { $eq: &quot;Engineering&quot; } }).pretty()\n[\n  {\n    _id: ObjectId('665356cff5b334bcf92202d9'),\n    name: 'Bob',\n    age: 24,\n    department: 'Engineering',\n    salary: 70000,\n    joinDate: ISODate('2019-03-10T00:00:00.000Z')\n  },\n  {\n    _id: ObjectId('665356cff5b334bcf92202da'),\n    name: 'Charlie',\n    age: 29,\n    department: 'Engineering',\n    salary: 75000,\n    joinDate: ISODate('2017-06-23T00:00:00.000Z')\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">companyDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Employees.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({ department: { $eq: <\/span><span style=\"color: #9ECBFF\">&quot;Engineering&quot;<\/span><span style=\"color: #E1E4E8\"> } }).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Bob&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">24<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Engineering&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">70000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: <\/span><span style=\"color: #B392F0\">ISODate<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;2019-03-10T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202da&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Charlie&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">29<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Engineering&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">75000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: <\/span><span style=\"color: #B392F0\">ISODate<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;2017-06-23T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2. <code>$ne<\/code> (Not Equal)<\/h4>\n\n\n\n<p>Find employees who are not in the &#8220;HR&#8221; department.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"companyDB&gt; db.Employees.find({ department: { $ne: &quot;HR&quot; } }).pretty()\n[\n  {\n    _id: ObjectId('665356cff5b334bcf92202d9'),\n    name: 'Bob',\n    age: 24,\n    department: 'Engineering',\n    salary: 70000,\n    joinDate: ISODate('2019-03-10T00:00:00.000Z')\n  },\n  {\n    _id: ObjectId('665356cff5b334bcf92202da'),\n    name: 'Charlie',\n    age: 29,\n    department: 'Engineering',\n    salary: 75000,\n    joinDate: ISODate('2017-06-23T00:00:00.000Z')\n  },\n  {\n    _id: ObjectId('665356cff5b334bcf92202db'),\n    name: 'David',\n    age: 35,\n    department: 'Marketing',\n    salary: 60000,\n    joinDate: ISODate('2014-11-01T00:00:00.000Z')\n  },\n  {\n    _id: ObjectId('665356cff5b334bcf92202dc'),\n    name: 'Eve',\n    age: 28,\n    department: 'Finance',\n    salary: 80000,\n    joinDate: ISODate('2018-08-19T00:00:00.000Z')\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">companyDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Employees.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({ department: { $ne: <\/span><span style=\"color: #9ECBFF\">&quot;HR&quot;<\/span><span style=\"color: #E1E4E8\"> } }).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Bob&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">24<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Engineering&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">70000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: <\/span><span style=\"color: #B392F0\">ISODate<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;2019-03-10T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202da&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Charlie&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">29<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Engineering&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">75000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: <\/span><span style=\"color: #B392F0\">ISODate<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;2017-06-23T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202db&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;David&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">35<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Marketing&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">60000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: <\/span><span style=\"color: #B392F0\">ISODate<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;2014-11-01T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202dc&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Eve&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">28<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Finance&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">80000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: <\/span><span style=\"color: #B392F0\">ISODate<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;2018-08-19T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">3. <code>$gt<\/code> (Greater Than)<\/h4>\n\n\n\n<p>Find employees who are older than 30.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(1 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"companyDB&gt; db.Employees.find({ age: { $gt: 30 } }).pretty()\n[\n  {\n    _id: ObjectId('665356cff5b334bcf92202db'),\n    name: 'David',\n    age: 35,\n    department: 'Marketing',\n    salary: 60000,\n    joinDate: ISODate('2014-11-01T00:00:00.000Z')\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">companyDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Employees.find<\/span><span style=\"color: #E1E4E8\">({ age: { $gt: 30 } }).pretty()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202db&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;David&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">35<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Marketing&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">60000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: ISODate(<\/span><span style=\"color: #9ECBFF\">&#39;2014-11-01T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">4. <code>$lt<\/code> (Less Than)<\/h4>\n\n\n\n<p>Find employees with a salary less than 70000.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(1 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"companyDB&gt; db.Employees.find({ salary: { $lt: 70000 } }).pretty()\n[\n  {\n    _id: ObjectId('665356cff5b334bcf92202d8'),\n    name: 'Alice',\n    age: 30,\n    department: 'HR',\n    salary: 50000,\n    joinDate: ISODate('2015-01-15T00:00:00.000Z')\n  },\n  {\n    _id: ObjectId('665356cff5b334bcf92202db'),\n    name: 'David',\n    age: 35,\n    department: 'Marketing',\n    salary: 60000,\n    joinDate: ISODate('2014-11-01T00:00:00.000Z')\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">companyDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Employees.find<\/span><span style=\"color: #E1E4E8\">({ salary: { $lt: 70000 } }).pretty()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202d8&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Alice&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">30<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;HR&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">50000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: ISODate(<\/span><span style=\"color: #9ECBFF\">&#39;2015-01-15T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202db&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;David&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">35<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Marketing&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">60000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: ISODate(<\/span><span style=\"color: #9ECBFF\">&#39;2014-11-01T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">5. <code>$gte<\/code> (Greater Than or Equal)<\/h4>\n\n\n\n<p>Find employees who joined on or after January 1, 2018.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(1 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"companyDB&gt; db.Employees.find({ joinDate: { $gte: new Date(&quot;2018-01-01&quot;) } }).pretty()\n[\n  {\n    _id: ObjectId('665356cff5b334bcf92202d9'),\n    name: 'Bob',\n    age: 24,\n    department: 'Engineering',\n    salary: 70000,\n    joinDate: ISODate('2019-03-10T00:00:00.000Z')\n  },\n  {\n    _id: ObjectId('665356cff5b334bcf92202dc'),\n    name: 'Eve',\n    age: 28,\n    department: 'Finance',\n    salary: 80000,\n    joinDate: ISODate('2018-08-19T00:00:00.000Z')\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">companyDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Employees.find<\/span><span style=\"color: #E1E4E8\">({ joinDate: { $gte: new Date(&quot;2018-01-01&quot;) } }).pretty()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Bob&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">24<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Engineering&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">70000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: ISODate(<\/span><span style=\"color: #9ECBFF\">&#39;2019-03-10T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202dc&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Eve&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">28<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Finance&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">80000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: ISODate(<\/span><span style=\"color: #9ECBFF\">&#39;2018-08-19T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">6. <code>$lte<\/code> (Less Than or Equal)<\/h4>\n\n\n\n<p>Find employees who are 28 years old or younger.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"companyDB&gt; db.Employees.find({ age: { $lte: 28 } }).pretty()\n[\n  {\n    _id: ObjectId('665356cff5b334bcf92202d9'),\n    name: 'Bob',\n    age: 24,\n    department: 'Engineering',\n    salary: 70000,\n    joinDate: ISODate('2019-03-10T00:00:00.000Z')\n  },\n  {\n    _id: ObjectId('665356cff5b334bcf92202dc'),\n    name: 'Eve',\n    age: 28,\n    department: 'Finance',\n    salary: 80000,\n    joinDate: ISODate('2018-08-19T00:00:00.000Z')\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">companyDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Employees.find<\/span><span style=\"color: #E1E4E8\">({ age: { $lte: 28 } }).pretty()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Bob&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">24<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Engineering&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">70000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: ISODate(<\/span><span style=\"color: #9ECBFF\">&#39;2019-03-10T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202dc&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Eve&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">28<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Finance&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">80000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: ISODate(<\/span><span style=\"color: #9ECBFF\">&#39;2018-08-19T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Queries Using Logical Selectors<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. <code>$and<\/code> (Logical AND)<\/h4>\n\n\n\n<p>Find employees who are in the &#8220;Engineering&#8221; department and have a salary greater than 70000.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"companyDB&gt; db.Employees.find({ \n  $and: [\n    { department: &quot;Engineering&quot; },\n    { salary: { $gt: 70000 } }\n  ] \n}).pretty()\n[\n  {\n    _id: ObjectId('665356cff5b334bcf92202da'),\n    name: 'Charlie',\n    age: 29,\n    department: 'Engineering',\n    salary: 75000,\n    joinDate: ISODate('2017-06-23T00:00:00.000Z')\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">companyDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Employees.find<\/span><span style=\"color: #E1E4E8\">({ <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  $and: [<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #B392F0\">department:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&quot;Engineering&quot;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">},<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #B392F0\">salary:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">{<\/span><span style=\"color: #E1E4E8\"> $gt<\/span><span style=\"color: #9ECBFF\">:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">70000<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">}<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">}<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  ] <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">})<\/span><span style=\"color: #B392F0\">.pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">_id:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">&#39;665356cff5b334bcf92202da&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">name:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;Charlie&#39;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">age:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">29<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">department:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;Engineering&#39;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">salary:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">75000<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">joinDate:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">ISODate<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">&#39;2017-06-23T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2. <code>$or<\/code> (Logical OR)<\/h4>\n\n\n\n<p>Find employees who are either in the &#8220;HR&#8221; department or have a salary less than 60000.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"companyDB&gt; db.Employees.find({ \n  $or: [\n    { department: &quot;HR&quot; },\n    { salary: { $lt: 60000 } }\n  ] \n}).pretty()\n[\n  {\n    _id: ObjectId('665356cff5b334bcf92202d8'),\n    name: 'Alice',\n    age: 30,\n    department: 'HR',\n    salary: 50000,\n    joinDate: ISODate('2015-01-15T00:00:00.000Z')\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">companyDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Employees.find<\/span><span style=\"color: #E1E4E8\">({ <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  $or: [<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #B392F0\">department:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&quot;HR&quot;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">},<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #B392F0\">salary:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">{<\/span><span style=\"color: #E1E4E8\"> $lt<\/span><span style=\"color: #9ECBFF\">:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">60000<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">}<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">}<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  ] <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">})<\/span><span style=\"color: #B392F0\">.pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">_id:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">&#39;665356cff5b334bcf92202d8&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">name:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;Alice&#39;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">age:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">30<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">department:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;HR&#39;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">salary:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">50000<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">joinDate:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">ISODate<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">&#39;2015-01-15T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">3. <code>$not<\/code> (Logical NOT)<\/h4>\n\n\n\n<p>Find employees who are not in the &#8220;Engineering&#8221; department.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"companyDB&gt; db.Employees.find({ \n  department: { \n    $not: { $eq: &quot;Engineering&quot; } \n  } \n}).pretty()\n[\n  {\n    _id: ObjectId('665356cff5b334bcf92202d8'),\n    name: 'Alice',\n    age: 30,\n    department: 'HR',\n    salary: 50000,\n    joinDate: ISODate('2015-01-15T00:00:00.000Z')\n  },\n  {\n    _id: ObjectId('665356cff5b334bcf92202db'),\n    name: 'David',\n    age: 35,\n    department: 'Marketing',\n    salary: 60000,\n    joinDate: ISODate('2014-11-01T00:00:00.000Z')\n  },\n  {\n    _id: ObjectId('665356cff5b334bcf92202dc'),\n    name: 'Eve',\n    age: 28,\n    department: 'Finance',\n    salary: 80000,\n    joinDate: ISODate('2018-08-19T00:00:00.000Z')\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">companyDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Employees.find<\/span><span style=\"color: #E1E4E8\">({ <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">department:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">{<\/span><span style=\"color: #E1E4E8\"> <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    $not: <\/span><span style=\"color: #9ECBFF\">{<\/span><span style=\"color: #E1E4E8\"> $eq<\/span><span style=\"color: #9ECBFF\">:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&quot;Engineering&quot;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">}<\/span><span style=\"color: #E1E4E8\"> <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  } <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">}).pretty()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202d8&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Alice&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">30<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;HR&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">50000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: ISODate(<\/span><span style=\"color: #9ECBFF\">&#39;2015-01-15T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202db&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;David&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">35<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Marketing&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">60000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: ISODate(<\/span><span style=\"color: #9ECBFF\">&#39;2014-11-01T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;665356cff5b334bcf92202dc&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Eve&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    age: <\/span><span style=\"color: #79B8FF\">28<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    department: <\/span><span style=\"color: #9ECBFF\">&#39;Finance&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    salary: <\/span><span style=\"color: #79B8FF\">80000<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    joinDate: ISODate(<\/span><span style=\"color: #9ECBFF\">&#39;2018-08-19T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">4. <code>$nor<\/code> (Logical NOR)<\/h4>\n\n\n\n<p>Find employees who are neither in the &#8220;HR&#8221; department nor have a salary greater than 75000.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"companyDB&gt; db.Employees.find({ \n  $nor: [\n    { department: &quot;HR&quot; },\n    { salary: { $gt: 75000 } }\n  ] \n}).pretty()\n[\n  {\n    _id: ObjectId('665356cff5b334bcf92202d9'),\n    name: 'Bob',\n    age: 24,\n    department: 'Engineering',\n    salary: 70000,\n    joinDate: ISODate('2019-03-10T00:00:00.000Z')\n  },\n  {\n    _id: ObjectId('665356cff5b334bcf92202da'),\n    name: 'Charlie',\n    age: 29,\n    department: 'Engineering',\n    salary: 75000,\n    joinDate: ISODate('2017-06-23T00:00:00.000Z')\n  },\n  {\n    _id: ObjectId('665356cff5b334bcf92202db'),\n    name: 'David',\n    age: 35,\n    department: 'Marketing',\n    salary: 60000,\n    joinDate: ISODate('2014-11-01T00:00:00.000Z')\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">companyDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Employees.find<\/span><span style=\"color: #E1E4E8\">({ <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  $nor: [<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #B392F0\">department:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&quot;HR&quot;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">},<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #B392F0\">salary:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">{<\/span><span style=\"color: #E1E4E8\"> $gt<\/span><span style=\"color: #9ECBFF\">:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">75000<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">}<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">}<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  ] <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">})<\/span><span style=\"color: #B392F0\">.pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">_id:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">&#39;665356cff5b334bcf92202d9&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">name:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;Bob&#39;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">age:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">24<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">department:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;Engineering&#39;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">salary:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">70000<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">joinDate:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">ISODate<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">&#39;2019-03-10T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">_id:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">&#39;665356cff5b334bcf92202da&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">name:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;Charlie&#39;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">age:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">29<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">department:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;Engineering&#39;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">salary:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">75000<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">joinDate:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">ISODate<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">&#39;2017-06-23T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">_id:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">&#39;665356cff5b334bcf92202db&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">name:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;David&#39;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">age:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">35<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">department:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">&#39;Marketing&#39;,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">salary:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">60000<\/span><span style=\"color: #9ECBFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #B392F0\">joinDate:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">ISODate<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #B392F0\">&#39;2014-11-01T00:00:00.000Z&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"P03b\">b. Query selectors (Geospatial selectors, Bitwise selectors )<\/h2>\n\n\n\n<p><strong>Execute query selectors (Geospatial selectors, Bitwise selectors ) and list out the results on any collection<\/strong><\/p>\n\n\n\n<p>Let&#8217;s extend our MongoDB examples to include queries using geospatial selectors and bitwise selectors. We will create a new collection called <code>Places<\/code> for geospatial queries and a collection called <code>Devices<\/code> for bitwise queries.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Geospatial Selectors<\/h3>\n\n\n\n<p>First, let&#8217;s create a <code>Places<\/code> collection with geospatial data.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Create the <code>Places<\/code> Collection and Insert Documents<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"test&gt; use geoDatabase\nswitched to db geoDatabase\ngeoDatabase&gt; db.Places.insertMany([\n  { name: &quot;Central Park&quot;, location: { type: &quot;Point&quot;, coordinates: [-73.9654, 40.7829] } },\n  { name: &quot;Times Square&quot;, location: { type: &quot;Point&quot;, coordinates: [-73.9851, 40.7580] } },\n  { name: &quot;Brooklyn Bridge&quot;, location: { type: &quot;Point&quot;, coordinates: [-73.9969, 40.7061] } },\n  { name: &quot;Empire State Building&quot;, location: { type: &quot;Point&quot;, coordinates: [-73.9857, 40.7488] } },\n  { name: &quot;Statue of Liberty&quot;, location: { type: &quot;Point&quot;, coordinates: [-74.0445, 40.6892] } }\n])\n{\n  acknowledged: true,\n  insertedIds: {\n    '0': ObjectId('66536a9799cad9cd2b2202d8'),\n    '1': ObjectId('66536a9799cad9cd2b2202d9'),\n    '2': ObjectId('66536a9799cad9cd2b2202da'),\n    '3': ObjectId('66536a9799cad9cd2b2202db'),\n    '4': ObjectId('66536a9799cad9cd2b2202dc')\n  }\n}\n\/\/ Create a geospatial index\ngeoDatabase&gt; db.Places.createIndex({ location: &quot;2dsphere&quot; })\nlocation_2dsphere\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">test<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> use geoDatabase<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">switched to db geoDatabase<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">geoDatabase<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Places.<\/span><span style=\"color: #B392F0\">insertMany<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Central Park&quot;<\/span><span style=\"color: #E1E4E8\">, location: { type: <\/span><span style=\"color: #9ECBFF\">&quot;Point&quot;<\/span><span style=\"color: #E1E4E8\">, coordinates: [<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">73.9654<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.7829<\/span><span style=\"color: #E1E4E8\">] } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Times Square&quot;<\/span><span style=\"color: #E1E4E8\">, location: { type: <\/span><span style=\"color: #9ECBFF\">&quot;Point&quot;<\/span><span style=\"color: #E1E4E8\">, coordinates: [<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">73.9851<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.7580<\/span><span style=\"color: #E1E4E8\">] } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Brooklyn Bridge&quot;<\/span><span style=\"color: #E1E4E8\">, location: { type: <\/span><span style=\"color: #9ECBFF\">&quot;Point&quot;<\/span><span style=\"color: #E1E4E8\">, coordinates: [<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">73.9969<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.7061<\/span><span style=\"color: #E1E4E8\">] } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Empire State Building&quot;<\/span><span style=\"color: #E1E4E8\">, location: { type: <\/span><span style=\"color: #9ECBFF\">&quot;Point&quot;<\/span><span style=\"color: #E1E4E8\">, coordinates: [<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">73.9857<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.7488<\/span><span style=\"color: #E1E4E8\">] } },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Statue of Liberty&quot;<\/span><span style=\"color: #E1E4E8\">, location: { type: <\/span><span style=\"color: #9ECBFF\">&quot;Point&quot;<\/span><span style=\"color: #E1E4E8\">, coordinates: [<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">74.0445<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.6892<\/span><span style=\"color: #E1E4E8\">] } }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">acknowledged<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">insertedIds<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;0&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;66536a9799cad9cd2b2202d8&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;1&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;66536a9799cad9cd2b2202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;2&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;66536a9799cad9cd2b2202da&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;3&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;66536a9799cad9cd2b2202db&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;4&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;66536a9799cad9cd2b2202dc&#39;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/ Create a geospatial index<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">geoDatabase<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Places.<\/span><span style=\"color: #B392F0\">createIndex<\/span><span style=\"color: #E1E4E8\">({ location: <\/span><span style=\"color: #9ECBFF\">&quot;2dsphere&quot;<\/span><span style=\"color: #E1E4E8\"> })<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">location_2dsphere<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Geospatial Queries<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">1. <code>$near<\/code> (Find places near a certain point)<\/h5>\n\n\n\n<p>Find places near a specific coordinate, for example, near Times Square.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"geoDatabase&gt; db.Places.find({\n  location: {\n    $near: {\n      $geometry: {\n        type: &quot;Point&quot;,\n        coordinates: [-73.9851, 40.7580]\n      },\n      $maxDistance: 5000 \/\/ distance in meters\n    }\n  }\n}).pretty()\n[\n  {\n    _id: ObjectId('66536a9799cad9cd2b2202d9'),\n    name: 'Times Square',\n    location: { type: 'Point', coordinates: [ -73.9851, 40.758 ] }\n  },\n  {\n    _id: ObjectId('66536a9799cad9cd2b2202db'),\n    name: 'Empire State Building',\n    location: { type: 'Point', coordinates: [ -73.9857, 40.7488 ] }\n  },\n  {\n    _id: ObjectId('66536a9799cad9cd2b2202d8'),\n    name: 'Central Park',\n    location: { type: 'Point', coordinates: [ -73.9654, 40.7829 ] }\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">geoDatabase&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Places.find<\/span><span style=\"color: #E1E4E8\">({<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">location:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    $near: <\/span><span style=\"color: #9ECBFF\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">      $geometry: <\/span><span style=\"color: #9ECBFF\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #79B8FF\">type<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Point&quot;,<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">coordinates:<\/span><span style=\"color: #E1E4E8\"> [-73.9851, <\/span><span style=\"color: #79B8FF\">40.7580<\/span><span style=\"color: #9ECBFF\">]<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">      },<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">      $maxDistance: <\/span><span style=\"color: #79B8FF\">5000<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">\/\/<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">distance<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">in<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">meters<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">}).pretty()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;66536a9799cad9cd2b2202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Times Square&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    location: { type: <\/span><span style=\"color: #9ECBFF\">&#39;Point&#39;<\/span><span style=\"color: #E1E4E8\">, coordinates: [ <\/span><span style=\"color: #79B8FF\">-73.9851<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.758<\/span><span style=\"color: #E1E4E8\"> ] }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;66536a9799cad9cd2b2202db&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Empire State Building&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    location: { type: <\/span><span style=\"color: #9ECBFF\">&#39;Point&#39;<\/span><span style=\"color: #E1E4E8\">, coordinates: [ <\/span><span style=\"color: #79B8FF\">-73.9857<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.7488<\/span><span style=\"color: #E1E4E8\"> ] }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;66536a9799cad9cd2b2202d8&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Central Park&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    location: { type: <\/span><span style=\"color: #9ECBFF\">&#39;Point&#39;<\/span><span style=\"color: #E1E4E8\">, coordinates: [ <\/span><span style=\"color: #79B8FF\">-73.9654<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.7829<\/span><span style=\"color: #E1E4E8\"> ] }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h5 class=\"wp-block-heading\">2. <code>$geoWithin<\/code> (Find places within a specific area)<\/h5>\n\n\n\n<p>Find places within a specific polygon, for example, an area covering part of Manhattan.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"geoDatabase&gt; db.Places.find({\n  location: {\n    $geoWithin: {\n      $geometry: {\n        type: &quot;Polygon&quot;,\n        coordinates: [\n          [\n            [-70.016, 35.715],\n            [-74.014, 40.717],\n            [-73.990, 40.730],\n            [-73.990, 40.715],\n            [-70.016, 35.715]\n          ]\n        ]\n      }\n    }\n  }\n}).pretty()\n[\n  {\n    _id: ObjectId('66536a9799cad9cd2b2202da'),\n    name: 'Brooklyn Bridge',\n    location: { type: 'Point', coordinates: [ -73.9969, 40.7061 ] }\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">geoDatabase&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Places.find<\/span><span style=\"color: #E1E4E8\">({<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">location:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    $geoWithin: <\/span><span style=\"color: #9ECBFF\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">      $geometry: <\/span><span style=\"color: #9ECBFF\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #79B8FF\">type<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Polygon&quot;,<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #B392F0\">coordinates:<\/span><span style=\"color: #E1E4E8\"> [<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">          [<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">            [<\/span><span style=\"color: #79B8FF\">-70.016<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">35.715<\/span><span style=\"color: #E1E4E8\">],<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">            [<\/span><span style=\"color: #79B8FF\">-74.014<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.717<\/span><span style=\"color: #E1E4E8\">],<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">            [<\/span><span style=\"color: #79B8FF\">-73.990<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.730<\/span><span style=\"color: #E1E4E8\">],<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">            [<\/span><span style=\"color: #79B8FF\">-73.990<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.715<\/span><span style=\"color: #E1E4E8\">],<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">            [<\/span><span style=\"color: #79B8FF\">-70.016<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">35.715<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">          ]<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">        ]<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">      }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">}).pretty()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;66536a9799cad9cd2b2202da&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Brooklyn Bridge&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    location: { type: <\/span><span style=\"color: #9ECBFF\">&#39;Point&#39;<\/span><span style=\"color: #E1E4E8\">, coordinates: [ <\/span><span style=\"color: #79B8FF\">-73.9969<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">40.7061<\/span><span style=\"color: #E1E4E8\"> ] }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Bitwise Selectors<\/h3>\n\n\n\n<p>Next, let&#8217;s create a <code>Devices<\/code> collection for bitwise operations.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Create the <code>Devices<\/code> Collection and Insert Documents<\/h4>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"test&gt; use techDB\ntechDB&gt; db.Devices.insertMany([\n  { name: &quot;Device A&quot;, status: 5 }, \/\/ Binary: 0101\n  { name: &quot;Device B&quot;, status: 3 }, \/\/ Binary: 0011\n  { name: &quot;Device C&quot;, status: 12 }, \/\/ Binary: 1100\n  { name: &quot;Device D&quot;, status: 10 }, \/\/ Binary: 1010\n  { name: &quot;Device E&quot;, status: 7 }  \/\/ Binary: 0111\n])\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #79B8FF\">test<\/span><span style=\"color: #E1E4E8\">&gt; <\/span><span style=\"color: #9ECBFF\">use<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">techDB<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">techDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Devices.insertMany<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Device A&quot;<\/span><span style=\"color: #E1E4E8\">, status: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\"> }, \/\/ Binary: <\/span><span style=\"color: #79B8FF\">0101<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Device B&quot;<\/span><span style=\"color: #E1E4E8\">, status: <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\"> }, \/\/ Binary: <\/span><span style=\"color: #79B8FF\">0011<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Device C&quot;<\/span><span style=\"color: #E1E4E8\">, status: <\/span><span style=\"color: #79B8FF\">12<\/span><span style=\"color: #E1E4E8\"> }, \/\/ Binary: <\/span><span style=\"color: #79B8FF\">1100<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Device D&quot;<\/span><span style=\"color: #E1E4E8\">, status: <\/span><span style=\"color: #79B8FF\">10<\/span><span style=\"color: #E1E4E8\"> }, \/\/ Binary: <\/span><span style=\"color: #79B8FF\">1010<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Device E&quot;<\/span><span style=\"color: #E1E4E8\">, status: <\/span><span style=\"color: #79B8FF\">7<\/span><span style=\"color: #E1E4E8\"> }  \/\/ Binary: <\/span><span style=\"color: #79B8FF\">0111<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">])<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Execute Bitwise Queries<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">1. <code>$bitsAllSet<\/code> (Find documents where all bits are set)<\/h5>\n\n\n\n<p>Find devices where the binary status has both the 1st and 3rd bits set (binary mask 0101, or decimal 5).<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"techDB&gt; db.Devices.find({\n  status: { $bitsAllSet: [0, 2] }\n}).pretty()\n[\n  {\n    _id: ObjectId('6653703d4e38f292e52202d8'),\n    name: 'Device A',\n    status: 5\n  },\n  {\n    _id: ObjectId('6653703d4e38f292e52202dc'),\n    name: 'Device E',\n    status: 7\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">techDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Devices.find<\/span><span style=\"color: #E1E4E8\">({<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">status:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">{<\/span><span style=\"color: #E1E4E8\"> $bitsAllSet<\/span><span style=\"color: #9ECBFF\">:<\/span><span style=\"color: #E1E4E8\"> [0, <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #9ECBFF\">]<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">}<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">}).pretty()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;6653703d4e38f292e52202d8&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Device A&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    status: <\/span><span style=\"color: #79B8FF\">5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;6653703d4e38f292e52202dc&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Device E&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    status: <\/span><span style=\"color: #79B8FF\">7<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h5 class=\"wp-block-heading\">2. <code>$bitsAnySet<\/code> (Find documents where any of the bits are set)<\/h5>\n\n\n\n<p>Find devices where the binary status has at least the 2nd bit set (binary mask 0010, or decimal 2).<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"techDB&gt; db.Devices.find({\n  status: { $bitsAnySet: [1] }\n}).pretty()\n[\n  {\n    _id: ObjectId('6653703d4e38f292e52202d9'),\n    name: 'Device B',\n    status: 3\n  },\n  {\n    _id: ObjectId('6653703d4e38f292e52202db'),\n    name: 'Device D',\n    status: 10\n  },\n  {\n    _id: ObjectId('6653703d4e38f292e52202dc'),\n    name: 'Device E',\n    status: 7\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">techDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Devices.find<\/span><span style=\"color: #E1E4E8\">({<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">status:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">{<\/span><span style=\"color: #E1E4E8\"> $bitsAnySet<\/span><span style=\"color: #9ECBFF\">:<\/span><span style=\"color: #E1E4E8\"> [1] }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">}).pretty()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;6653703d4e38f292e52202d9&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Device B&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    status: <\/span><span style=\"color: #79B8FF\">3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;6653703d4e38f292e52202db&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Device D&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    status: <\/span><span style=\"color: #79B8FF\">10<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;6653703d4e38f292e52202dc&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Device E&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    status: <\/span><span style=\"color: #79B8FF\">7<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h5 class=\"wp-block-heading\">3. <code>$bitsAllClear<\/code> (Find documents where all bits are clear)<\/h5>\n\n\n\n<p>Find devices where the binary status has both the 2nd and 4th bits clear (binary mask 1010, or decimal 10).<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"techDB&gt; db.Devices.find({\n  status: { $bitsAllClear: [1, 3] }\n}).pretty()\n[\n  {\n    _id: ObjectId('6653703d4e38f292e52202d8'),\n    name: 'Device A',\n    status: 5\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">techDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Devices.find<\/span><span style=\"color: #E1E4E8\">({<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">status:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">{<\/span><span style=\"color: #E1E4E8\"> $bitsAllClear<\/span><span style=\"color: #9ECBFF\">:<\/span><span style=\"color: #E1E4E8\"> [1, <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #9ECBFF\">]<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">}<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">}).pretty()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;6653703d4e38f292e52202d8&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Device A&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    status: <\/span><span style=\"color: #79B8FF\">5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h5 class=\"wp-block-heading\">4. <code>$bitsAnyClear<\/code> (Find documents where any of the bits are clear)<\/h5>\n\n\n\n<p>Find devices where the binary status has at least the 1st bit clear (binary mask 0001, or decimal 1).<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"techDB&gt; db.Devices.find({\n  status: { $bitsAnyClear: [0] }\n}).pretty()\n[\n  {\n    _id: ObjectId('6653703d4e38f292e52202da'),\n    name: 'Device C',\n    status: 12\n  },\n  {\n    _id: ObjectId('6653703d4e38f292e52202db'),\n    name: 'Device D',\n    status: 10\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #B392F0\">techDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Devices.find<\/span><span style=\"color: #E1E4E8\">({<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #B392F0\">status:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">{<\/span><span style=\"color: #E1E4E8\"> $bitsAnyClear<\/span><span style=\"color: #9ECBFF\">:<\/span><span style=\"color: #E1E4E8\"> [0] }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">}).pretty()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;6653703d4e38f292e52202da&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Device C&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    status: <\/span><span style=\"color: #79B8FF\">12<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: ObjectId(<\/span><span style=\"color: #9ECBFF\">&#39;6653703d4e38f292e52202db&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Device D&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    status: <\/span><span style=\"color: #79B8FF\">10<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P04\">Question 4<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"P04a\">Projection Operators<\/h2>\n\n\n\n<p><strong>Create and demonstrate how projection operators ($, $elematch and $slice) would be used in the MondoDB.<\/strong><\/p>\n\n\n\n<p>To demonstrate the use of projection operators (<code>$<\/code>, <code>$elemMatch<\/code>, and <code>$slice<\/code>) in MongoDB, let&#8217;s create a <code>Products<\/code> collection. We&#8217;ll insert documents that include arrays, which will allow us to showcase these operators effectively.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create the <code>Products<\/code> Collection and Insert Documents<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"test&gt; use retailDB\nswitched to db retailDB\nretailDB&gt; db.Products.insertMany([\n  {\n    name: &quot;Laptop&quot;,\n    brand: &quot;BrandA&quot;,\n    features: [\n      { name: &quot;Processor&quot;, value: &quot;Intel i7&quot; },\n      { name: &quot;RAM&quot;, value: &quot;16GB&quot; },\n      { name: &quot;Storage&quot;, value: &quot;512GB SSD&quot; }\n    ],\n    reviews: [\n      { user: &quot;Alice&quot;, rating: 5, comment: &quot;Excellent!&quot; },\n      { user: &quot;Bob&quot;, rating: 4, comment: &quot;Very good&quot; },\n      { user: &quot;Charlie&quot;, rating: 3, comment: &quot;Average&quot; }\n    ]\n  },\n  {\n    name: &quot;Smartphone&quot;,\n    brand: &quot;BrandB&quot;,\n    features: [\n      { name: &quot;Processor&quot;, value: &quot;Snapdragon 888&quot; },\n      { name: &quot;RAM&quot;, value: &quot;8GB&quot; },\n      { name: &quot;Storage&quot;, value: &quot;256GB&quot; }\n    ],\n    reviews: [\n      { user: &quot;Dave&quot;, rating: 4, comment: &quot;Good phone&quot; },\n      { user: &quot;Eve&quot;, rating: 2, comment: &quot;Not satisfied&quot; }\n    ]\n  }\n])\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #79B8FF\">test<\/span><span style=\"color: #E1E4E8\">&gt; <\/span><span style=\"color: #9ECBFF\">use<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">retailDB<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">switched<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">to<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">retailDB<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">retailDB&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db.Products.insertMany<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    brand: <\/span><span style=\"color: #9ECBFF\">&quot;BrandA&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    features: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { name: <\/span><span style=\"color: #9ECBFF\">&quot;Processor&quot;<\/span><span style=\"color: #E1E4E8\">, value: <\/span><span style=\"color: #9ECBFF\">&quot;Intel i7&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { name: <\/span><span style=\"color: #9ECBFF\">&quot;RAM&quot;<\/span><span style=\"color: #E1E4E8\">, value: <\/span><span style=\"color: #9ECBFF\">&quot;16GB&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { name: <\/span><span style=\"color: #9ECBFF\">&quot;Storage&quot;<\/span><span style=\"color: #E1E4E8\">, value: <\/span><span style=\"color: #9ECBFF\">&quot;512GB SSD&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ],<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    reviews: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Alice&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Excellent!&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Bob&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Very good&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Charlie&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Average&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Smartphone&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    brand: <\/span><span style=\"color: #9ECBFF\">&quot;BrandB&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    features: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { name: <\/span><span style=\"color: #9ECBFF\">&quot;Processor&quot;<\/span><span style=\"color: #E1E4E8\">, value: <\/span><span style=\"color: #9ECBFF\">&quot;Snapdragon 888&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { name: <\/span><span style=\"color: #9ECBFF\">&quot;RAM&quot;<\/span><span style=\"color: #E1E4E8\">, value: <\/span><span style=\"color: #9ECBFF\">&quot;8GB&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { name: <\/span><span style=\"color: #9ECBFF\">&quot;Storage&quot;<\/span><span style=\"color: #E1E4E8\">, value: <\/span><span style=\"color: #9ECBFF\">&quot;256GB&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ],<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    reviews: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Dave&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Good phone&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Eve&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Not satisfied&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">])<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Use Projection Operators<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. The <code>$<\/code> Projection Operator<\/h4>\n\n\n\n<p>The <code>$<\/code> operator is used to project the first matching element from an array of embedded documents.<\/p>\n\n\n\n<p><strong>Example:<\/strong> Find the product named &#8220;Laptop&#8221; and project the review from the user &#8220;Alice&#8221;.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"retailDB&gt; db.Products.find(\n  { name: &quot;Laptop&quot;, &quot;reviews.user&quot;: &quot;Alice&quot; },\n  { &quot;reviews.$&quot;: 1 }\n).pretty()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">retailDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Products.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;reviews.user&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Alice&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;reviews.$&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Result:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;_id&quot;: ObjectId(&quot;...&quot;),\n  &quot;reviews&quot;: [\n    { &quot;user&quot;: &quot;Alice&quot;, &quot;rating&quot;: 5, &quot;comment&quot;: &quot;Excellent!&quot; }\n  ]\n}\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;...&quot;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;reviews&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #9ECBFF\">&quot;user&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Alice&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;rating&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;comment&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Excellent!&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2. The <code>$elemMatch<\/code> Projection Operator<\/h4>\n\n\n\n<p>The <code>$elemMatch<\/code> operator is used to project the first matching element from an array based on specified criteria.<\/p>\n\n\n\n<p><strong>Example:<\/strong> Find the product named &#8220;Laptop&#8221; and project the review where the rating is greater than 4.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"retailDB&gt; db.Products.find(\n  { name: &quot;Laptop&quot; },\n  { reviews: { $elemMatch: { rating: { $gt: 4 } } } }\n).pretty()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">retailDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Products.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { reviews: { $elemMatch: { rating: { $gt: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\"> } } } }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Result:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;_id&quot;: ObjectId(&quot;...&quot;),\n  &quot;reviews&quot;: [\n    { &quot;user&quot;: &quot;Alice&quot;, &quot;rating&quot;: 5, &quot;comment&quot;: &quot;Excellent!&quot; }\n  ]\n}\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;...&quot;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;reviews&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #9ECBFF\">&quot;user&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Alice&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;rating&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;comment&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Excellent!&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">3. The <code>$slice<\/code> Projection Operator<\/h4>\n\n\n\n<p>The <code>$slice<\/code> operator is used to include a subset of the array field.<\/p>\n\n\n\n<p><strong>Example:<\/strong> Find the product named &#8220;Smartphone&#8221; and project the first review.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"retailDB&gt; db.Products.find(\n  { name: &quot;Smartphone&quot; },\n  { reviews: { $slice: 1 } }\n).pretty()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">retailDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Products.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Smartphone&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { reviews: { $slice: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> } }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Result:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;_id&quot;: ObjectId(&quot;...&quot;),\n  &quot;reviews&quot;: [\n    { &quot;user&quot;: &quot;Dave&quot;, &quot;rating&quot;: 4, &quot;comment&quot;: &quot;Good phone&quot; }\n  ]\n}\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;...&quot;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;reviews&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #9ECBFF\">&quot;user&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Dave&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;rating&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;comment&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Good phone&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Additional Example with Multiple Projection Operators<\/h3>\n\n\n\n<p><strong>Example:<\/strong> Find the product named &#8220;Laptop&#8221; and project the <code>name<\/code>, the first two features, and the review with the highest rating.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"retailDB&gt; db.Products.find(\n  { name: &quot;Laptop&quot; },\n  {\n    name: 1,\n    features: { $slice: 2 },\n    reviews: { $elemMatch: { rating: 5 } }\n  }\n).pretty()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">retailDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Products.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { name: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    features: { $slice: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    reviews: { $elemMatch: { rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\"> } }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Result:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;_id&quot;: ObjectId(&quot;...&quot;),\n  &quot;name&quot;: &quot;Laptop&quot;,\n  &quot;features&quot;: [\n    { &quot;name&quot;: &quot;Processor&quot;, &quot;value&quot;: &quot;Intel i7&quot; },\n    { &quot;name&quot;: &quot;RAM&quot;, &quot;value&quot;: &quot;16GB&quot; }\n  ],\n  &quot;reviews&quot;: [\n    { &quot;user&quot;: &quot;Alice&quot;, &quot;rating&quot;: 5, &quot;comment&quot;: &quot;Excellent!&quot; }\n  ]\n}\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;...&quot;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;name&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;features&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #9ECBFF\">&quot;name&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Processor&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;value&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Intel i7&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #9ECBFF\">&quot;name&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;RAM&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;value&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;16GB&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  ],<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;reviews&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    { <\/span><span style=\"color: #9ECBFF\">&quot;user&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Alice&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;rating&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;comment&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Excellent!&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Using projection operators in MongoDB, you can fine-tune the data returned by your queries:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>$<\/code> operator is useful for projecting the first matching element from an array.<\/li>\n\n\n\n<li>The <code>$elemMatch<\/code> operator allows you to project the first array element that matches specified criteria.<\/li>\n\n\n\n<li>The <code>$slice<\/code> operator lets you project a subset of an array, such as the first <code>n<\/code> elements or a specific range.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P05\">Question 5<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"P05a\">Aggregation operations<\/h2>\n\n\n\n<p>Execute Aggregation operations ($avg, $min,$max, $push, $addToSet etc.). students encourage to execute several queries to demonstrate various aggregation operators)<\/p>\n\n\n\n<p>To demonstrate aggregation operations such as <code>$avg<\/code>, <code>$min<\/code>, <code>$max<\/code>, <code>$push<\/code>, and <code>$addToSet<\/code> in MongoDB, we will use a <code>Sales<\/code> collection. This collection will contain documents representing sales transactions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create the <code>Sales<\/code> Collection and Insert Documents<\/h3>\n\n\n\n<p>First, we&#8217;ll create the <code>Sales<\/code> collection and insert sample documents.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"test&gt; use salesDB\nsalesDB&gt; db.Sales.insertMany([\n  { date: new Date(&quot;2024-01-01&quot;), product: &quot;Laptop&quot;, price: 1200, quantity: 1, customer: &quot;Amar&quot; },\n  { date: new Date(&quot;2024-01-02&quot;), product: &quot;Laptop&quot;, price: 1200, quantity: 2, customer: &quot;Babu&quot; },\n  { date: new Date(&quot;2024-01-03&quot;), product: &quot;Mouse&quot;, price: 25, quantity: 5, customer: &quot;Chandra&quot; },\n  { date: new Date(&quot;2024-01-04&quot;), product: &quot;Keyboard&quot;, price: 45, quantity: 3, customer: &quot;Amar&quot; },\n  { date: new Date(&quot;2024-01-05&quot;), product: &quot;Monitor&quot;, price: 300, quantity: 1, customer: &quot;Babu&quot; },\n  { date: new Date(&quot;2024-01-06&quot;), product: &quot;Laptop&quot;, price: 1200, quantity: 1, customer: &quot;Deva&quot; }\n])\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">test<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> use salesDB<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">salesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Sales.<\/span><span style=\"color: #B392F0\">insertMany<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { date: <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Date<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;2024-01-01&quot;<\/span><span style=\"color: #E1E4E8\">), product: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">, price: <\/span><span style=\"color: #79B8FF\">1200<\/span><span style=\"color: #E1E4E8\">, quantity: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, customer: <\/span><span style=\"color: #9ECBFF\">&quot;Amar&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { date: <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Date<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;2024-01-02&quot;<\/span><span style=\"color: #E1E4E8\">), product: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">, price: <\/span><span style=\"color: #79B8FF\">1200<\/span><span style=\"color: #E1E4E8\">, quantity: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">, customer: <\/span><span style=\"color: #9ECBFF\">&quot;Babu&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { date: <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Date<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;2024-01-03&quot;<\/span><span style=\"color: #E1E4E8\">), product: <\/span><span style=\"color: #9ECBFF\">&quot;Mouse&quot;<\/span><span style=\"color: #E1E4E8\">, price: <\/span><span style=\"color: #79B8FF\">25<\/span><span style=\"color: #E1E4E8\">, quantity: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, customer: <\/span><span style=\"color: #9ECBFF\">&quot;Chandra&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { date: <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Date<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;2024-01-04&quot;<\/span><span style=\"color: #E1E4E8\">), product: <\/span><span style=\"color: #9ECBFF\">&quot;Keyboard&quot;<\/span><span style=\"color: #E1E4E8\">, price: <\/span><span style=\"color: #79B8FF\">45<\/span><span style=\"color: #E1E4E8\">, quantity: <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\">, customer: <\/span><span style=\"color: #9ECBFF\">&quot;Amar&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { date: <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Date<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;2024-01-05&quot;<\/span><span style=\"color: #E1E4E8\">), product: <\/span><span style=\"color: #9ECBFF\">&quot;Monitor&quot;<\/span><span style=\"color: #E1E4E8\">, price: <\/span><span style=\"color: #79B8FF\">300<\/span><span style=\"color: #E1E4E8\">, quantity: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, customer: <\/span><span style=\"color: #9ECBFF\">&quot;Babu&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { date: <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Date<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;2024-01-06&quot;<\/span><span style=\"color: #E1E4E8\">), product: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">, price: <\/span><span style=\"color: #79B8FF\">1200<\/span><span style=\"color: #E1E4E8\">, quantity: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, customer: <\/span><span style=\"color: #9ECBFF\">&quot;Deva&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">])<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Execute Aggregation Operations<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. <code>$avg<\/code> (Average)<\/h4>\n\n\n\n<p>Calculate the average price of each product.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"salesDB&gt; db.Sales.aggregate([\n  {\n    $group: {\n      _id: &quot;$product&quot;,\n      averagePrice: { $avg: &quot;$price&quot; }\n    }\n  }\n]).pretty()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">salesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Sales.<\/span><span style=\"color: #B392F0\">aggregate<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $group: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      _id: <\/span><span style=\"color: #9ECBFF\">&quot;$product&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      averagePrice: { $avg: <\/span><span style=\"color: #9ECBFF\">&quot;$price&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Result:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  { &quot;_id&quot;: &quot;Laptop&quot;, &quot;averagePrice&quot;: 1200 },\n  { &quot;_id&quot;: &quot;Mouse&quot;, &quot;averagePrice&quot;: 25 },\n  { &quot;_id&quot;: &quot;Keyboard&quot;, &quot;averagePrice&quot;: 45 },\n  { &quot;_id&quot;: &quot;Monitor&quot;, &quot;averagePrice&quot;: 300 }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;averagePrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1200<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Mouse&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;averagePrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">25<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Keyboard&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;averagePrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">45<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Monitor&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;averagePrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">300<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2. <code>$min<\/code> (Minimum)<\/h4>\n\n\n\n<p>Find the minimum price of each product.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"salesDB&gt; db.Sales.aggregate([\n  {\n    $group: {\n      _id: &quot;$product&quot;,\n      minPrice: { $min: &quot;$price&quot; }\n    }\n  }\n]).pretty()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">salesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Sales.<\/span><span style=\"color: #B392F0\">aggregate<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $group: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      _id: <\/span><span style=\"color: #9ECBFF\">&quot;$product&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      minPrice: { $min: <\/span><span style=\"color: #9ECBFF\">&quot;$price&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Result:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  { &quot;_id&quot;: &quot;Laptop&quot;, &quot;minPrice&quot;: 1200 },\n  { &quot;_id&quot;: &quot;Mouse&quot;, &quot;minPrice&quot;: 25 },\n  { &quot;_id&quot;: &quot;Keyboard&quot;, &quot;minPrice&quot;: 45 },\n  { &quot;_id&quot;: &quot;Monitor&quot;, &quot;minPrice&quot;: 300 }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;minPrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1200<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Mouse&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;minPrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">25<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Keyboard&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;minPrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">45<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Monitor&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;minPrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">300<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">3. <code>$max<\/code> (Maximum)<\/h4>\n\n\n\n<p>Find the maximum price of each product.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"salesDB&gt; db.Sales.aggregate([\n  {\n    $group: {\n      _id: &quot;$product&quot;,\n      maxPrice: { $max: &quot;$price&quot; }\n    }\n  }\n]).pretty()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">salesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Sales.<\/span><span style=\"color: #B392F0\">aggregate<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $group: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      _id: <\/span><span style=\"color: #9ECBFF\">&quot;$product&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      maxPrice: { $max: <\/span><span style=\"color: #9ECBFF\">&quot;$price&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Result:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  { &quot;_id&quot;: &quot;Laptop&quot;, &quot;maxPrice&quot;: 1200 },\n  { &quot;_id&quot;: &quot;Mouse&quot;, &quot;maxPrice&quot;: 25 },\n  { &quot;_id&quot;: &quot;Keyboard&quot;, &quot;maxPrice&quot;: 45 },\n  { &quot;_id&quot;: &quot;Monitor&quot;, &quot;maxPrice&quot;: 300 }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;maxPrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1200<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Mouse&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;maxPrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">25<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Keyboard&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;maxPrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">45<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Monitor&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;maxPrice&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">300<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">4. <code>$push<\/code> (Push Values to an Array)<\/h4>\n\n\n\n<p>Group sales by customer and push each purchased product into an array.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"salesDB&gt; db.Sales.aggregate([\n  {\n    $group: {\n      _id: &quot;$customer&quot;,\n      products: { $push: &quot;$product&quot; }\n    }\n  }\n]).pretty()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">salesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Sales.<\/span><span style=\"color: #B392F0\">aggregate<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $group: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      _id: <\/span><span style=\"color: #9ECBFF\">&quot;$customer&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      products: { $push: <\/span><span style=\"color: #9ECBFF\">&quot;$product&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Result:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  { &quot;_id&quot;: &quot;Amar&quot;, &quot;products&quot;: [&quot;Laptop&quot;, &quot;Keyboard&quot;] },\n  { &quot;_id&quot;: &quot;Babu&quot;, &quot;products&quot;: [&quot;Laptop&quot;, &quot;Monitor&quot;] },\n  { &quot;_id&quot;: &quot;Chandra&quot;, &quot;products&quot;: [&quot;Mouse&quot;] },\n  { &quot;_id&quot;: &quot;Deva&quot;, &quot;products&quot;: [&quot;Laptop&quot;] }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Amar&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;products&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Keyboard&quot;<\/span><span style=\"color: #E1E4E8\">] },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Babu&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;products&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Monitor&quot;<\/span><span style=\"color: #E1E4E8\">] },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Chandra&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;products&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Mouse&quot;<\/span><span style=\"color: #E1E4E8\">] },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Deva&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;products&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">] }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">5. <code>$addToSet<\/code> (Add Unique Values to an Array)<\/h4>\n\n\n\n<p>Group sales by customer and add each unique purchased product to an array.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"salesDB&gt; db.Sales.aggregate([\n  {\n    $group: {\n      _id: &quot;$customer&quot;,\n      uniqueProducts: { $addToSet: &quot;$product&quot; }\n    }\n  }\n]).pretty()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">salesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Sales.<\/span><span style=\"color: #B392F0\">aggregate<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $group: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      _id: <\/span><span style=\"color: #9ECBFF\">&quot;$customer&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      uniqueProducts: { $addToSet: <\/span><span style=\"color: #9ECBFF\">&quot;$product&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Result:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  { &quot;_id&quot;: &quot;Amar&quot;, &quot;uniqueProducts&quot;: [&quot;Laptop&quot;, &quot;Keyboard&quot;] },\n  { &quot;_id&quot;: &quot;Babu&quot;, &quot;uniqueProducts&quot;: [&quot;Laptop&quot;, &quot;Monitor&quot;] },\n  { &quot;_id&quot;: &quot;Chandra&quot;, &quot;uniqueProducts&quot;: [&quot;Mouse&quot;] },\n  { &quot;_id&quot;: &quot;Deva&quot;, &quot;uniqueProducts&quot;: [&quot;Laptop&quot;] }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Amar&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;uniqueProducts&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Keyboard&quot;<\/span><span style=\"color: #E1E4E8\">] },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Babu&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;uniqueProducts&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Monitor&quot;<\/span><span style=\"color: #E1E4E8\">] },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Chandra&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;uniqueProducts&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Mouse&quot;<\/span><span style=\"color: #E1E4E8\">] },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  { <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Deva&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;uniqueProducts&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">] }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Combining Aggregation Operations<\/h3>\n\n\n\n<p>Let&#8217;s combine several aggregation operations to get a comprehensive report.<\/p>\n\n\n\n<p><strong>Example:<\/strong> Calculate the total quantity and total sales amount for each product, and list all customers who purchased each product.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"salesDB&gt; db.Sales.aggregate([\n  {\n    $group: {\n      _id: &quot;$product&quot;,\n      totalQuantity: { $sum: &quot;$quantity&quot; },\n      totalSales: { $sum: { $multiply: [&quot;$price&quot;, &quot;$quantity&quot;] } },\n      customers: { $addToSet: &quot;$customer&quot; }\n    }\n  }\n]).pretty()\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">salesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.Sales.<\/span><span style=\"color: #B392F0\">aggregate<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $group: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      _id: <\/span><span style=\"color: #9ECBFF\">&quot;$product&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      totalQuantity: { $sum: <\/span><span style=\"color: #9ECBFF\">&quot;$quantity&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      totalSales: { $sum: { $multiply: [<\/span><span style=\"color: #9ECBFF\">&quot;$price&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;$quantity&quot;<\/span><span style=\"color: #E1E4E8\">] } },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      customers: { $addToSet: <\/span><span style=\"color: #9ECBFF\">&quot;$customer&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Result:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  {\n    &quot;_id&quot;: &quot;Laptop&quot;,\n    &quot;totalQuantity&quot;: 4,\n    &quot;totalSales&quot;: 4800,\n    &quot;customers&quot;: [&quot;Amar&quot;, &quot;Babu&quot;, &quot;Deva&quot;]\n  },\n  {\n    &quot;_id&quot;: &quot;Mouse&quot;,\n    &quot;totalQuantity&quot;: 5,\n    &quot;totalSales&quot;: 125,\n    &quot;customers&quot;: [&quot;Chandra&quot;]\n  },\n  {\n    &quot;_id&quot;: &quot;Keyboard&quot;,\n    &quot;totalQuantity&quot;: 3,\n    &quot;totalSales&quot;: 135,\n    &quot;customers&quot;: [&quot;Amar&quot;]\n  },\n  {\n    &quot;_id&quot;: &quot;Monitor&quot;,\n    &quot;totalQuantity&quot;: 1,\n    &quot;totalSales&quot;: 300,\n    &quot;customers&quot;: [&quot;Babu&quot;]\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;totalQuantity&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;totalSales&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">4800<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;customers&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Amar&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Babu&quot;<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">&quot;Deva&quot;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Mouse&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;totalQuantity&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;totalSales&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">125<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;customers&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Chandra&quot;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Keyboard&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;totalQuantity&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;totalSales&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">135<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;customers&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Amar&quot;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Monitor&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;totalQuantity&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;totalSales&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">300<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;customers&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><span style=\"color: #9ECBFF\">&quot;Babu&quot;<\/span><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>By using aggregation operations such as <code>$avg<\/code>, <code>$min<\/code>, <code>$max<\/code>, <code>$push<\/code>, and <code>$addToSet<\/code>, you can perform complex data analysis and transformations on MongoDB collections. These operations enable you to calculate averages, find minimum and maximum values, push values into arrays, and create sets of unique values. The examples provided show how to use these operators to analyze a <code>Sales<\/code> collection<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P06\">Question 6<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"P06a\">Aggregation Pipeline and its operations<\/h2>\n\n\n\n<p><strong>Execute Aggregation Pipeline and its operations (pipeline must contain $match, $group, $sort, $project, $skip etc.)<\/strong><\/p>\n\n\n\n<p>Let&#8217;s consider a scenario involving a <code>restaurantDB<\/code> database with a <code>restaurants<\/code> collection. Each document in the <code>restaurants<\/code> collection contains details about a restaurant, including its name, cuisine, location, and an array of reviews. Each review includes a rating and a comment. After creating the <code>restaurantDB<\/code> database and insert sample documents into the <code>restaurants<\/code> collection we will create an aggregation pipeline as shown below.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Switch to the restaurantDB database\nuse restaurantDB\n\/\/ Insert sample documents into the restaurants collection\ndb.restaurants.insertMany([\n  {\n    name: &quot;Biryani House&quot;,\n    cuisine: &quot;Indian&quot;,\n    location: &quot;Jayanagar&quot;,\n    reviews: [\n      { user: &quot;Aarav&quot;, rating: 5, comment: &quot;Amazing biryani!&quot; },\n      { user: &quot;Bhavana&quot;, rating: 4, comment: &quot;Great place!&quot; }\n    ]\n  },\n  {\n    name: &quot;Burger Joint&quot;,\n    cuisine: &quot;American&quot;,\n    location: &quot;Koramangala&quot;,\n    reviews: [\n      { user: &quot;Chirag&quot;, rating: 3, comment: &quot;Average burger&quot; },\n      { user: &quot;Devika&quot;, rating: 4, comment: &quot;Good value&quot; }\n    ]\n  },\n  {\n    name: &quot;Pasta House&quot;,\n    cuisine: &quot;Italian&quot;,\n    location: &quot;Rajajinagar&quot;,\n    reviews: [\n      { user: &quot;Esha&quot;, rating: 5, comment: &quot;Delicious pasta!&quot; },\n      { user: &quot;Farhan&quot;, rating: 4, comment: &quot;Nice ambiance&quot; }\n    ]\n  },\n  {\n    name: &quot;Curry Palace&quot;,\n    cuisine: &quot;Indian&quot;,\n    location: &quot;Jayanagar&quot;,\n    reviews: [\n      { user: &quot;Gaurav&quot;, rating: 4, comment: &quot;Spicy and tasty!&quot; },\n      { user: &quot;Harini&quot;, rating: 5, comment: &quot;Best curry in town!&quot; }\n    ]\n  },\n  {\n    name: &quot;Taco Stand&quot;,\n    cuisine: &quot;Mexican&quot;,\n    location: &quot;Jayanagar&quot;,\n    reviews: [\n      { user: &quot;Ishaan&quot;, rating: 5, comment: &quot;Fantastic tacos!&quot; },\n      { user: &quot;Jaya&quot;, rating: 4, comment: &quot;Very authentic&quot; }\n    ]\n  }\n])\n\/\/ Run the aggregation pipeline query to display reviews summary\ndb.restaurants.aggregate([\n  {\n    $match: {\n      location: &quot;Jayanagar&quot;\n    }\n  },\n  {\n    $unwind: &quot;$reviews&quot;\n  },\n  {\n    $group: {\n      _id: &quot;$name&quot;,\n      averageRating: { $avg: &quot;$reviews.rating&quot; },\n      totalReviews: { $sum: 1 }\n    }\n  },\n  {\n    $sort: {\n      averageRating: -1\n    }\n  },\n  {\n    $project: {\n      _id: 0,\n      restaurant: &quot;$_id&quot;,\n      averageRating: 1,\n      totalReviews: 1\n    }\n  },\n  {\n    $skip: 1\n  }\n]).pretty()\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Switch to the restaurantDB database<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">use restaurantDB<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/ Insert sample documents into the restaurants collection<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">db.restaurants.<\/span><span style=\"color: #B392F0\">insertMany<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Biryani House&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    cuisine: <\/span><span style=\"color: #9ECBFF\">&quot;Indian&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    location: <\/span><span style=\"color: #9ECBFF\">&quot;Jayanagar&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    reviews: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Aarav&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Amazing biryani!&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Bhavana&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Great place!&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Burger Joint&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    cuisine: <\/span><span style=\"color: #9ECBFF\">&quot;American&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    location: <\/span><span style=\"color: #9ECBFF\">&quot;Koramangala&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    reviews: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Chirag&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Average burger&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Devika&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Good value&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Pasta House&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    cuisine: <\/span><span style=\"color: #9ECBFF\">&quot;Italian&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    location: <\/span><span style=\"color: #9ECBFF\">&quot;Rajajinagar&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    reviews: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Esha&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Delicious pasta!&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Farhan&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Nice ambiance&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Curry Palace&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    cuisine: <\/span><span style=\"color: #9ECBFF\">&quot;Indian&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    location: <\/span><span style=\"color: #9ECBFF\">&quot;Jayanagar&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    reviews: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Gaurav&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Spicy and tasty!&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Harini&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Best curry in town!&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Taco Stand&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    cuisine: <\/span><span style=\"color: #9ECBFF\">&quot;Mexican&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    location: <\/span><span style=\"color: #9ECBFF\">&quot;Jayanagar&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    reviews: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Ishaan&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Fantastic tacos!&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Jaya&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Very authentic&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">])<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/ Run the aggregation pipeline query to display reviews summary<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">db.restaurants.<\/span><span style=\"color: #B392F0\">aggregate<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $match: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      location: <\/span><span style=\"color: #9ECBFF\">&quot;Jayanagar&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $unwind: <\/span><span style=\"color: #9ECBFF\">&quot;$reviews&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $group: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      _id: <\/span><span style=\"color: #9ECBFF\">&quot;$name&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      averageRating: { $avg: <\/span><span style=\"color: #9ECBFF\">&quot;$reviews.rating&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      totalReviews: { $sum: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $sort: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      averageRating: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $project: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      _id: <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      restaurant: <\/span><span style=\"color: #9ECBFF\">&quot;$_id&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      averageRating: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      totalReviews: <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $skip: <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Now, let&#8217;s execute an aggregation pipeline that includes the <code>$match<\/code>, <code>$unwind<\/code>, <code>$group<\/code>, <code>$sort<\/code>, <code>$project<\/code>, and <code>$skip<\/code> stages.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Aggregation Pipeline Explanation<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>$match<\/strong>: Filter restaurants by cuisine (<code>\"Jayanagar\"<\/code> location).<\/li>\n\n\n\n<li><strong>$unwind<\/strong>: Deconstruct the <code>reviews<\/code> array from each document to output a document for each review.<\/li>\n\n\n\n<li><strong>$group<\/strong>: Group the documents by restaurant name and calculate the average rating and total number of reviews.<\/li>\n\n\n\n<li><strong>$sort<\/strong>: Sort the results by average rating in descending order.<\/li>\n\n\n\n<li><strong>$project<\/strong>: Restructure the output to include only the restaurant name, average rating, and total reviews.<\/li>\n\n\n\n<li><strong>$skip<\/strong>: Skip the first document.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P07\">Question 7<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"P07a\">a. Find all listings<\/h2>\n\n\n\n<p><strong>Find all listings with listing_url, name, address, host_picture_url in the listings And Reviews collection that have a host with a picture url<\/strong><\/p>\n\n\n\n<p>To find all listings with <code>listing_url<\/code>, <code>name<\/code>, <code>address<\/code>, and <code>host_picture_url<\/code> in the <code>listingsAndReviews<\/code> collection where the host has a picture URL, let is create appropriate databases and queries as follows.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create the Database<\/h3>\n\n\n\n<p>First, switch to or create the database you want to use. For this example, let&#8217;s call the database <code>vacationRentals<\/code>.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"test&gt; use vacationRentals\nswitched to db vacationRentals\nvacationRentals&gt; \" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">test<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> use vacationRentals<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">switched to db vacationRentals<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">vacationRentals<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Create the <code>listingsAndReviews<\/code> Collection and Insert Documents<\/h3>\n\n\n\n<p>Next, create the <code>listingsAndReviews<\/code> collection and insert sample documents. Here are a few example documents to illustrate the structure:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"vacationRentals&gt; db.listingsAndReviews.insertMany([\n  {\n    listing_url: &quot;http:\/\/www.example.com\/listing\/123456&quot;,\n    name: &quot;Beautiful Apartment&quot;,\n    address: {\n      street: &quot;123 Main Street&quot;,\n      suburb: &quot;Central&quot;,\n      city: &quot;Metropolis&quot;,\n      country: &quot;Wonderland&quot;\n    },\n    host: {\n      name: &quot;Alice&quot;,\n      picture_url: &quot;http:\/\/www.example.com\/images\/host\/host123.jpg&quot;\n    }\n  },\n  {\n    listing_url: &quot;http:\/\/www.example.com\/listing\/654321&quot;,\n    name: &quot;Cozy Cottage&quot;,\n    address: {\n      street: &quot;456 Another St&quot;,\n      suburb: &quot;North&quot;,\n      city: &quot;Smallville&quot;,\n      country: &quot;Wonderland&quot;\n    },\n    host: {\n      name: &quot;Bob&quot;,\n      picture_url: &quot;&quot;\n    }\n  },\n  {\n    listing_url: &quot;http:\/\/www.example.com\/listing\/789012&quot;,\n    name: &quot;Modern Condo&quot;,\n    address: {\n      street: &quot;789 Side Road&quot;,\n      suburb: &quot;East&quot;,\n      city: &quot;Gotham&quot;,\n      country: &quot;Wonderland&quot;\n    },\n    host: {\n      name: &quot;Charlie&quot;,\n      picture_url: &quot;http:\/\/www.example.com\/images\/host\/host789.jpg&quot;\n    }\n  }\n])\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">vacationRentals<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.listingsAndReviews.<\/span><span style=\"color: #B392F0\">insertMany<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    listing_url: <\/span><span style=\"color: #9ECBFF\">&quot;http:\/\/www.example.com\/listing\/123456&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Beautiful Apartment&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    address: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      street: <\/span><span style=\"color: #9ECBFF\">&quot;123 Main Street&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      suburb: <\/span><span style=\"color: #9ECBFF\">&quot;Central&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      city: <\/span><span style=\"color: #9ECBFF\">&quot;Metropolis&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      country: <\/span><span style=\"color: #9ECBFF\">&quot;Wonderland&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    host: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      name: <\/span><span style=\"color: #9ECBFF\">&quot;Alice&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      picture_url: <\/span><span style=\"color: #9ECBFF\">&quot;http:\/\/www.example.com\/images\/host\/host123.jpg&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    listing_url: <\/span><span style=\"color: #9ECBFF\">&quot;http:\/\/www.example.com\/listing\/654321&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Cozy Cottage&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    address: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      street: <\/span><span style=\"color: #9ECBFF\">&quot;456 Another St&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      suburb: <\/span><span style=\"color: #9ECBFF\">&quot;North&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      city: <\/span><span style=\"color: #9ECBFF\">&quot;Smallville&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      country: <\/span><span style=\"color: #9ECBFF\">&quot;Wonderland&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    host: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      name: <\/span><span style=\"color: #9ECBFF\">&quot;Bob&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      picture_url: <\/span><span style=\"color: #9ECBFF\">&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    listing_url: <\/span><span style=\"color: #9ECBFF\">&quot;http:\/\/www.example.com\/listing\/789012&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Modern Condo&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    address: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      street: <\/span><span style=\"color: #9ECBFF\">&quot;789 Side Road&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      suburb: <\/span><span style=\"color: #9ECBFF\">&quot;East&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      city: <\/span><span style=\"color: #9ECBFF\">&quot;Gotham&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      country: <\/span><span style=\"color: #9ECBFF\">&quot;Wonderland&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    host: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      name: <\/span><span style=\"color: #9ECBFF\">&quot;Charlie&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      picture_url: <\/span><span style=\"color: #9ECBFF\">&quot;http:\/\/www.example.com\/images\/host\/host789.jpg&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">])<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Query to Find Listings with Host Picture URLs<\/h3>\n\n\n\n<p>Now that the collection is set up, you can run the query to find all listings with <code>listing_url<\/code>, <code>name<\/code>, <code>address<\/code>, and <code>host_picture_url<\/code> where the host has a picture URL.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"db.listingsAndReviews.find(\n  {\n    &quot;host.picture_url&quot;: { $exists: true, $ne: &quot;&quot; }\n  },\n  {\n    listing_url: 1,\n    name: 1,\n    address: 1,\n    &quot;host.picture_url&quot;: 1\n  }\n).pretty()\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">db.listingsAndReviews.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;host.picture_url&quot;<\/span><span style=\"color: #E1E4E8\">: { $exists: <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #E1E4E8\">, $ne: <\/span><span style=\"color: #9ECBFF\">&quot;&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    listing_url: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    address: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;host.picture_url&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Query Filter:<\/strong>\n<ul class=\"wp-block-list\">\n<li><code>\"host.picture_url\": { $exists: true, $ne: \"\" }<\/code>: This part of the query ensures that only documents where the <code>host.picture_url<\/code> field exists and is not an empty string are selected.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Projection:<\/strong>\n<ul class=\"wp-block-list\">\n<li><code>{ listing_url: 1, name: 1, address: 1, \"host.picture_url\": 1 }<\/code>: This part of the query specifies the fields to include in the output. The <code>1<\/code> indicates that these fields should be included.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Expected Result<\/h3>\n\n\n\n<p>The query should return documents where the host has a picture URL. Based on the inserted documents, the result should look something like this:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n  &quot;_id&quot;: ObjectId(&quot;...&quot;),\n  &quot;listing_url&quot;: &quot;http:\/\/www.example.com\/listing\/123456&quot;,\n  &quot;name&quot;: &quot;Beautiful Apartment&quot;,\n  &quot;address&quot;: {\n    &quot;street&quot;: &quot;123 Main Street&quot;,\n    &quot;suburb&quot;: &quot;Central&quot;,\n    &quot;city&quot;: &quot;Metropolis&quot;,\n    &quot;country&quot;: &quot;Wonderland&quot;\n  },\n  &quot;host&quot;: {\n    &quot;picture_url&quot;: &quot;http:\/\/www.example.com\/images\/host\/host123.jpg&quot;\n  }\n}\n{\n  &quot;_id&quot;: ObjectId(&quot;...&quot;),\n  &quot;listing_url&quot;: &quot;http:\/\/www.example.com\/listing\/789012&quot;,\n  &quot;name&quot;: &quot;Modern Condo&quot;,\n  &quot;address&quot;: {\n    &quot;street&quot;: &quot;789 Side Road&quot;,\n    &quot;suburb&quot;: &quot;East&quot;,\n    &quot;city&quot;: &quot;Gotham&quot;,\n    &quot;country&quot;: &quot;Wonderland&quot;\n  },\n  &quot;host&quot;: {\n    &quot;picture_url&quot;: &quot;http:\/\/www.example.com\/images\/host\/host789.jpg&quot;\n  }\n}\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;...&quot;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;listing_url&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;http:\/\/www.example.com\/listing\/123456&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;name&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Beautiful Apartment&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;address&quot;<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;street&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;123 Main Street&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;suburb&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Central&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;city&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Metropolis&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;country&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Wonderland&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;host&quot;<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;picture_url&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;http:\/\/www.example.com\/images\/host\/host123.jpg&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;_id&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;...&quot;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;listing_url&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;http:\/\/www.example.com\/listing\/789012&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;name&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Modern Condo&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;address&quot;<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;street&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;789 Side Road&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;suburb&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;East&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;city&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Gotham&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;country&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Wonderland&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">&quot;host&quot;<\/span><span style=\"color: #E1E4E8\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;picture_url&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;http:\/\/www.example.com\/images\/host\/host789.jpg&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"P07b\">b. E-commerce collection<\/h2>\n\n\n\n<p><strong>Using E-commerce collection write a query to display reviews summary.<\/strong><\/p>\n\n\n\n<p>To display a summary of reviews in an e-commerce collection, we can assume the <code>ecommerce<\/code> database contains a <code>products<\/code> collection with documents structured to include reviews. Each product document could have a <code>reviews<\/code> array with review details such as rating, comment, and user.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Switch to the ecommerce database\nuse ecommerce\n\/\/ Insert sample documents into the products collection\ndb.products.insertMany([\n  {\n    product_id: 1,\n    name: &quot;Laptop&quot;,\n    category: &quot;Electronics&quot;,\n    price: 1200,\n    reviews: [\n      { user: &quot;Alice&quot;, rating: 5, comment: &quot;Excellent!&quot; },\n      { user: &quot;Bob&quot;, rating: 4, comment: &quot;Very good&quot; },\n      { user: &quot;Charlie&quot;, rating: 3, comment: &quot;Average&quot; }\n    ]\n  },\n  {\n    product_id: 2,\n    name: &quot;Smartphone&quot;,\n    category: &quot;Electronics&quot;,\n    price: 800,\n    reviews: [\n      { user: &quot;Dave&quot;, rating: 4, comment: &quot;Good phone&quot; },\n      { user: &quot;Eve&quot;, rating: 2, comment: &quot;Not satisfied&quot; },\n      { user: &quot;Frank&quot;, rating: 5, comment: &quot;Amazing!&quot; }\n    ]\n  },\n  {\n    product_id: 3,\n    name: &quot;Headphones&quot;,\n    category: &quot;Accessories&quot;,\n    price: 150,\n    reviews: [\n      { user: &quot;Grace&quot;, rating: 5, comment: &quot;Great sound&quot; },\n      { user: &quot;Heidi&quot;, rating: 3, comment: &quot;Okay&quot; }\n    ]\n  }\n])\n\/\/ Run the aggregation query to display reviews summary\ndb.products.aggregate([\n  {\n    $unwind: &quot;$reviews&quot;\n  },\n  {\n    $group: {\n      _id: &quot;$name&quot;,\n      totalReviews: { $sum: 1 },\n      averageRating: { $avg: &quot;$reviews.rating&quot; },\n      comments: { $push: &quot;$reviews.comment&quot; }\n    }\n  },\n  {\n    $project: {\n      _id: 0,\n      product: &quot;$_id&quot;,\n      totalReviews: 1,\n      averageRating: 1,\n      comments: 1\n    }\n  }\n]).pretty()\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Switch to the ecommerce database<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">use ecommerce<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/ Insert sample documents into the products collection<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">db.products.<\/span><span style=\"color: #B392F0\">insertMany<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    product_id: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&quot;Electronics&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    price: <\/span><span style=\"color: #79B8FF\">1200<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    reviews: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Alice&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Excellent!&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Bob&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Very good&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Charlie&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Average&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    product_id: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Smartphone&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&quot;Electronics&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    price: <\/span><span style=\"color: #79B8FF\">800<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    reviews: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Dave&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Good phone&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Eve&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Not satisfied&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Frank&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Amazing!&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    product_id: <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&quot;Headphones&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    category: <\/span><span style=\"color: #9ECBFF\">&quot;Accessories&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    price: <\/span><span style=\"color: #79B8FF\">150<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    reviews: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Grace&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Great sound&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      { user: <\/span><span style=\"color: #9ECBFF\">&quot;Heidi&quot;<\/span><span style=\"color: #E1E4E8\">, rating: <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\">, comment: <\/span><span style=\"color: #9ECBFF\">&quot;Okay&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">])<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">\/\/ Run the aggregation query to display reviews summary<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">db.products.<\/span><span style=\"color: #B392F0\">aggregate<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $unwind: <\/span><span style=\"color: #9ECBFF\">&quot;$reviews&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $group: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      _id: <\/span><span style=\"color: #9ECBFF\">&quot;$name&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      totalReviews: { $sum: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      averageRating: { $avg: <\/span><span style=\"color: #9ECBFF\">&quot;$reviews.rating&quot;<\/span><span style=\"color: #E1E4E8\"> },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      comments: { $push: <\/span><span style=\"color: #9ECBFF\">&quot;$reviews.comment&quot;<\/span><span style=\"color: #E1E4E8\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $project: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      _id: <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      product: <\/span><span style=\"color: #9ECBFF\">&quot;$_id&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      totalReviews: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      averageRating: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      comments: <\/span><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]).<\/span><span style=\"color: #B392F0\">pretty<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This script will set up the <code>ecommerce<\/code> database, populate the <code>products<\/code> collection with sample data, and execute an aggregation query to summarize the reviews.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>$unwind:<\/strong> Deconstructs the <code>reviews<\/code> array from each document to output a document for each element.<\/li>\n\n\n\n<li><strong>$group:<\/strong> Groups the documents by product name, and calculates:\n<ul class=\"wp-block-list\">\n<li><code>totalReviews<\/code>: The total number of reviews for each product.<\/li>\n\n\n\n<li><code>averageRating<\/code>: The average rating of the reviews for each product.<\/li>\n\n\n\n<li><code>comments<\/code>: An array of all review comments for each product.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>$project:<\/strong> Restructures the output documents to include the product name, total reviews, average rating, and comments.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Output:<\/h3>\n\n\n\n<p>The query will return a summary for each product in the collection:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  {\n    &quot;product&quot;: &quot;Laptop&quot;,\n    &quot;totalReviews&quot;: 3,\n    &quot;averageRating&quot;: 4,\n    &quot;comments&quot;: [\n      &quot;Excellent!&quot;,\n      &quot;Very good&quot;,\n      &quot;Average&quot;\n    ]\n  },\n  {\n    &quot;product&quot;: &quot;Smartphone&quot;,\n    &quot;totalReviews&quot;: 3,\n    &quot;averageRating&quot;: 3.6666666666666665,\n    &quot;comments&quot;: [\n      &quot;Good phone&quot;,\n      &quot;Not satisfied&quot;,\n      &quot;Amazing!&quot;\n    ]\n  },\n  {\n    &quot;product&quot;: &quot;Headphones&quot;,\n    &quot;totalReviews&quot;: 2,\n    &quot;averageRating&quot;: 4,\n    &quot;comments&quot;: [\n      &quot;Great sound&quot;,\n      &quot;Okay&quot;\n    ]\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;product&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Laptop&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;totalReviews&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;averageRating&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;comments&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;Excellent!&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;Very good&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;Average&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;product&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Smartphone&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;totalReviews&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">3<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;averageRating&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">3.6666666666666665<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;comments&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;Good phone&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;Not satisfied&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;Amazing!&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;product&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;Headphones&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;totalReviews&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;averageRating&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&quot;comments&quot;<\/span><span style=\"color: #E1E4E8\">: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;Great sound&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">      <\/span><span style=\"color: #9ECBFF\">&quot;Okay&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    ]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P08\">Question 8<\/h2>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P08a\">a. Demonstrate different types of indexes<\/h2>\n\n\n\n<p><strong>Demonstrate creation of different types of indexes on collection (unique, sparse, compound and multikey indexes)<\/strong><\/p>\n\n\n\n<p>Let&#8217;s demonstrate the creation of various types of indexes on a <code>restaurants<\/code> collection in the <code>restaurantDB<\/code> database. We&#8217;ll cover unique, sparse, compound, and multikey indexes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create the Database and Collection<\/h3>\n\n\n\n<p>First, let&#8217;s set up the <code>restaurantDB<\/code> database and insert sample documents into the <code>restaurants<\/code> collection.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Switch to the restaurantDB databasenuse restaurantDBnn\/\/ Insert sample documents into the restaurants collectionndb.restaurants.insertMany([n  {n    name: u0022Biryani Houseu0022,n    cuisine: u0022Indianu0022,n    location: u0022Downtownu0022,n    reviews: [n      { user: u0022Aaravu0022, rating: 5, comment: u0022Amazing biryani!u0022 },n      { user: u0022Bhavanau0022, rating: 4, comment: u0022Great place!u0022 }n    ],n    contact: { phone: u00221234567890u0022, email: u0022contact@biryanihouse.comu0022 }n  },n  {n    name: u0022Curry Palaceu0022,n    cuisine: u0022Indianu0022,n    location: u0022Downtownu0022,n    reviews: [n      { user: u0022Gauravu0022, rating: 4, comment: u0022Spicy and tasty!u0022 },n      { user: u0022Hariniu0022, rating: 5, comment: u0022Best curry in town!u0022 }n    ],n    contact: { phone: u00220987654321u0022, email: u0022contact@currypalace.comu0022 }n  },n  {n    name: u0022Taco Standu0022,n    cuisine: u0022Mexicanu0022,n    location: u0022Downtownu0022,n    reviews: [n      { user: u0022Ishaanu0022, rating: 5, comment: u0022Fantastic tacos!u0022 },n      { user: u0022Jayau0022, rating: 4, comment: u0022Very authenticu0022 }n    ],n    contact: { phone: u00221122334455u0022, email: u0022contact@tacostand.comu0022 }n  }n])\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Switch to the restaurantDB databasenuse restaurantDBnn\/\/ Insert sample documents into the restaurants collectionndb.restaurants.insertMany([n  {n    name: u0022Biryani Houseu0022,n    cuisine: u0022Indianu0022,n    location: u0022Downtownu0022,n    reviews: [n      { user: u0022Aaravu0022, rating: 5, comment: u0022Amazing biryani!u0022 },n      { user: u0022Bhavanau0022, rating: 4, comment: u0022Great place!u0022 }n    ],n    contact: { phone: u00221234567890u0022, email: u0022contact@biryanihouse.comu0022 }n  },n  {n    name: u0022Curry Palaceu0022,n    cuisine: u0022Indianu0022,n    location: u0022Downtownu0022,n    reviews: [n      { user: u0022Gauravu0022, rating: 4, comment: u0022Spicy and tasty!u0022 },n      { user: u0022Hariniu0022, rating: 5, comment: u0022Best curry in town!u0022 }n    ],n    contact: { phone: u00220987654321u0022, email: u0022contact@currypalace.comu0022 }n  },n  {n    name: u0022Taco Standu0022,n    cuisine: u0022Mexicanu0022,n    location: u0022Downtownu0022,n    reviews: [n      { user: u0022Ishaanu0022, rating: 5, comment: u0022Fantastic tacos!u0022 },n      { user: u0022Jayau0022, rating: 4, comment: u0022Very authenticu0022 }n    ],n    contact: { phone: u00221122334455u0022, email: u0022contact@tacostand.comu0022 }n  }n])<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create Various Indexes<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. Unique Index<\/h4>\n\n\n\n<p>A unique index ensures that the indexed field does not contain duplicate values.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Create a unique index on the contact.email fieldndb.restaurants.createIndex({ u0022contact.emailu0022: 1 }, { unique: true })\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Create a unique index on the contact.email fieldndb.restaurants.createIndex({ u0022contact.emailu0022: 1 }, { unique: true })<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2. Sparse Index<\/h4>\n\n\n\n<p>A sparse index only includes documents that contain the indexed field, ignoring documents where the field is missing.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Create a sparse index on the location fieldndb.restaurants.createIndex({ location: 1 }, { sparse: true })\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Create a sparse index on the location fieldndb.restaurants.createIndex({ location: 1 }, { sparse: true })<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">3. Compound Index<\/h4>\n\n\n\n<p>A compound index indexes multiple fields within a single index.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Create a compound index on the name and location fieldsndb.restaurants.createIndex({ name: 1, location: 1 })\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Create a compound index on the name and location fieldsndb.restaurants.createIndex({ name: 1, location: 1 })<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">4. Multikey Index<\/h4>\n\n\n\n<p>A multikey index is created on an array field, indexing each element of the array.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Create a multikey index on the reviews fieldndb.restaurants.createIndex({ reviews: 1 })\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Create a multikey index on the reviews fieldndb.restaurants.createIndex({ reviews: 1 })<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Verify Indexes<\/h3>\n\n\n\n<p>To verify the created indexes, you can use the <code>getIndexes<\/code> method.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Verify the created indexesndb.restaurants.getIndexes()\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Verify the created indexesndb.restaurants.getIndexes()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"testu003e use restaurantDBnswitched to db restaurantDBnrestaurantDBu003e db.restaurants.insertMany([n...   {n...     name: u0022Biryani Houseu0022,n...     cuisine: u0022Indianu0022,n...     location: u0022Downtownu0022,n...     reviews: [n...       { user: u0022Aaravu0022, rating: 5, comment: u0022Amazing biryani!u0022 },n...       { user: u0022Bhavanau0022, rating: 4, comment: u0022Great place!u0022 }n...     ],n...     contact: { phone: u00221234567890u0022, email: u0022contact@biryanihouse.comu0022 }n...   },n...   {n...     name: u0022Curry Palaceu0022,n...     cuisine: u0022Indianu0022,n...     location: u0022Downtownu0022,n...     reviews: [n...       { user: u0022Gauravu0022, rating: 4, comment: u0022Spicy and tasty!u0022 },n...       { user: u0022Hariniu0022, rating: 5, comment: u0022Best curry in town!u0022 }n...     ],n...     contact: { phone: u00220987654321u0022, email: u0022contact@currypalace.comu0022 }n...   },n...   {n...     name: u0022Taco Standu0022,n...     cuisine: u0022Mexicanu0022,n...     location: u0022Downtownu0022,n...     reviews: [n...       { user: u0022Ishaanu0022, rating: 5, comment: u0022Fantastic tacos!u0022 },n...       { user: u0022Jayau0022, rating: 4, comment: u0022Very authenticu0022 }n...     ],n...     contact: { phone: u00221122334455u0022, email: u0022contact@tacostand.comu0022 }n...   }n... ])n{n  acknowledged: true,n  insertedIds: {n    '0': ObjectId('667b3c596809bfbfae149f48'),n    '1': ObjectId('667b3c596809bfbfae149f49'),n    '2': ObjectId('667b3c596809bfbfae149f4a')n  }n}nrestaurantDBu003e db.restaurants.createIndex({ u0022contact.emailu0022: 1 }, { unique: true })ncontact.email_1nrestaurantDBu003e db.restaurants.createIndex({ location: 1 }, { sparse: true })nlocation_1nrestaurantDBu003e db.restaurants.createIndex({ name: 1, location: 1 })nname_1_location_1nrestaurantDBu003e db.restaurants.createIndex({ reviews: 1 })nreviews_1nrestaurantDBu003e db.restaurants.getIndexes()n[n  { v: 2, key: { _id: 1 }, name: '_id_' },n  {n    v: 2,n    key: { 'contact.email': 1 },n    name: 'contact.email_1',n    unique: truen  },n  { v: 2, key: { location: 1 }, name: 'location_1', sparse: true },n  { v: 2, key: { name: 1, location: 1 }, name: 'name_1_location_1' },n  { v: 2, key: { reviews: 1 }, name: 'reviews_1' }n]nrestaurantDBu003e n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">testu003e use restaurantDBnswitched to db restaurantDBnrestaurantDBu003e db.restaurants.<\/span><span style=\"color: #B392F0\">insertMany<\/span><span style=\"color: #E1E4E8\">([n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">   {n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     name: u0022Biryani Houseu0022,n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     cuisine: u0022Indianu0022,n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     location: u0022Downtownu0022,n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     reviews: [n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">       { user: u0022Aaravu0022, rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, comment: u0022Amazing biryani<\/span><span style=\"color: #F97583\">!<\/span><span style=\"color: #E1E4E8\">u0022 },n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">       { user: u0022Bhavanau0022, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: u0022Great place<\/span><span style=\"color: #F97583\">!<\/span><span style=\"color: #E1E4E8\">u0022 }n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     ],n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     contact: { phone: u00221234567890u0022, email: u0022contact@biryanihouse.comu0022 }n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">   },n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">   {n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     name: u0022Curry Palaceu0022,n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     cuisine: u0022Indianu0022,n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     location: u0022Downtownu0022,n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     reviews: [n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">       { user: u0022Gauravu0022, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: u0022Spicy and tasty<\/span><span style=\"color: #F97583\">!<\/span><span style=\"color: #E1E4E8\">u0022 },n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">       { user: u0022Hariniu0022, rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, comment: u0022Best curry <\/span><span style=\"color: #F97583\">in<\/span><span style=\"color: #E1E4E8\"> town<\/span><span style=\"color: #F97583\">!<\/span><span style=\"color: #E1E4E8\">u0022 }n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     ],n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     contact: { phone: u00220987654321u0022, email: u0022contact@currypalace.comu0022 }n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">   },n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">   {n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     name: u0022Taco Standu0022,n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     cuisine: u0022Mexicanu0022,n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     location: u0022Downtownu0022,n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     reviews: [n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">       { user: u0022Ishaanu0022, rating: <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">, comment: u0022Fantastic tacos<\/span><span style=\"color: #F97583\">!<\/span><span style=\"color: #E1E4E8\">u0022 },n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">       { user: u0022Jayau0022, rating: <\/span><span style=\"color: #79B8FF\">4<\/span><span style=\"color: #E1E4E8\">, comment: u0022Very authenticu0022 }n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     ],n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">     contact: { phone: u00221122334455u0022, email: u0022contact@tacostand.comu0022 }n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\">   }n<\/span><span style=\"color: #F97583\">...<\/span><span style=\"color: #E1E4E8\"> ])n{n  <\/span><span style=\"color: #B392F0\">acknowledged<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #E1E4E8\">,n  <\/span><span style=\"color: #B392F0\">insertedIds<\/span><span style=\"color: #E1E4E8\">: {n    <\/span><span style=\"color: #9ECBFF\">&#39;0&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667b3c596809bfbfae149f48&#39;<\/span><span style=\"color: #E1E4E8\">),n    <\/span><span style=\"color: #9ECBFF\">&#39;1&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667b3c596809bfbfae149f49&#39;<\/span><span style=\"color: #E1E4E8\">),n    <\/span><span style=\"color: #9ECBFF\">&#39;2&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667b3c596809bfbfae149f4a&#39;<\/span><span style=\"color: #E1E4E8\">)n  }n}nrestaurantDBu003e db.restaurants.<\/span><span style=\"color: #B392F0\">createIndex<\/span><span style=\"color: #E1E4E8\">({ u0022contact.emailu0022: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> }, { unique: <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #E1E4E8\"> })ncontact.email_1nrestaurantDBu003e db.restaurants.<\/span><span style=\"color: #B392F0\">createIndex<\/span><span style=\"color: #E1E4E8\">({ location: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> }, { sparse: <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #E1E4E8\"> })nlocation_1nrestaurantDBu003e db.restaurants.<\/span><span style=\"color: #B392F0\">createIndex<\/span><span style=\"color: #E1E4E8\">({ name: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, location: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> })nname_1_location_1nrestaurantDBu003e db.restaurants.<\/span><span style=\"color: #B392F0\">createIndex<\/span><span style=\"color: #E1E4E8\">({ reviews: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> })nreviews_1nrestaurantDBu003e db.restaurants.<\/span><span style=\"color: #B392F0\">getIndexes<\/span><span style=\"color: #E1E4E8\">()n[n  { v: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">, key: { _id: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> }, name: <\/span><span style=\"color: #9ECBFF\">&#39;_id_&#39;<\/span><span style=\"color: #E1E4E8\"> },n  {n    v: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">,n    key: { <\/span><span style=\"color: #9ECBFF\">&#39;contact.email&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> },n    name: <\/span><span style=\"color: #9ECBFF\">&#39;contact.email_1&#39;<\/span><span style=\"color: #E1E4E8\">,n    unique: truen  },n  { v: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">, key: { location: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> }, name: <\/span><span style=\"color: #9ECBFF\">&#39;location_1&#39;<\/span><span style=\"color: #E1E4E8\">, sparse: <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #E1E4E8\"> },n  { v: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">, key: { name: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, location: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> }, name: <\/span><span style=\"color: #9ECBFF\">&#39;name_1_location_1&#39;<\/span><span style=\"color: #E1E4E8\"> },n  { v: <\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">, key: { reviews: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\"> }, name: <\/span><span style=\"color: #9ECBFF\">&#39;reviews_1&#39;<\/span><span style=\"color: #E1E4E8\"> }n]nrestaurantDBu003e n<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This script sets up the <code>restaurantDB<\/code> database, populates the <code>restaurants<\/code> collection with sample data, and demonstrates the creation of unique, sparse, compound, and multikey indexes. The <code>getIndexes<\/code> method at the end allows you to verify the indexes created on the collection.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P08b\">b. Demonstrate optimization of queries using indexes.<\/h2>\n\n\n\n<p>To demonstrate the optimization of queries using indexes, we have to use a fairly large database where query execution times are longer. For the following examples, we&#8217;ll use a dataset of daily NASDAQ summaries. To follow along, you&#8217;ll need this data locally. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create the Database and Collection<\/h3>\n\n\n\n<p>First, download the archive from <a href=\"http:\/\/mng.bz\/ii49\" title=\"here\">here<\/a> . Then, unzip the file to a temporary folder.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"$ unzip stocks.zip nArchive:  stocks.zipn   creating: dump\/stocks\/n  inflating: dump\/stocks\/system.indexes.bson  n  inflating: dump\/stocks\/values.bson  \" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">$<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">unzip<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">stocks.zip<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">nArchive:<\/span><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">stocks.zipn<\/span><span style=\"color: #E1E4E8\">   <\/span><span style=\"color: #9ECBFF\">creating:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">dump\/stocks\/n<\/span><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">inflating:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">dump\/stocks\/system.indexes.bson<\/span><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">n<\/span><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #9ECBFF\">inflating:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">dump\/stocks\/values.bson<\/span><span style=\"color: #E1E4E8\">  <\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Now its time to import this stocks database into the MongoDB using the <code>mongorestore<\/code> command. After that switch to the <code>stocks<\/code> database. <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"$ mongorestore -d stocks dump\/stocksnn$ mongoshnntestu003e use stocksnswitched to db stocks\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">$<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">mongorestore<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">-d<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">stocks<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">dump\/stocksnn<\/span><span style=\"color: #E1E4E8\">$ <\/span><span style=\"color: #9ECBFF\">mongoshnntestu003e<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">use<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">stocksnswitched<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">to<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">db<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">stocks<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Lets have a look at the structure of this database to find the various fields using the following command. The <code>stocks<\/code> database has a <code>value<\/code> collection that contains, for a certain subset of the NASDAQ stock exchange\u2019s symbols, there\u2019s a document for each day\u2019s high, low, close, and volume for a 25-year period beginning in 1983.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"stocksu003e show collectionsnvaluesnnkeys = db.values.findOne()n{n  _id: ObjectId('4d094f58c96767d7a0099d49'),n  exchange: 'NASDAQ',n  stock_symbol: 'AACC',n  date: '2008-03-07',n  open: 8.4,n  high: 8.75,n  low: 8.08,n  close: 8.55,n  volume: 275800,n  'adj close': 8.55n}nnstocksu003e db.values.countDocuments()n4308303n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">stocksu003e show collectionsnvaluesnnkeys <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> db.values.<\/span><span style=\"color: #B392F0\">findOne<\/span><span style=\"color: #E1E4E8\">()n{n  <\/span><span style=\"color: #B392F0\">_id<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;4d094f58c96767d7a0099d49&#39;<\/span><span style=\"color: #E1E4E8\">),n  <\/span><span style=\"color: #B392F0\">exchange<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&#39;NASDAQ&#39;<\/span><span style=\"color: #E1E4E8\">,n  <\/span><span style=\"color: #B392F0\">stock_symbol<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&#39;AACC&#39;<\/span><span style=\"color: #E1E4E8\">,n  <\/span><span style=\"color: #B392F0\">date<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&#39;2008-03-07&#39;<\/span><span style=\"color: #E1E4E8\">,n  <\/span><span style=\"color: #B392F0\">open<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">8.4<\/span><span style=\"color: #E1E4E8\">,n  <\/span><span style=\"color: #B392F0\">high<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">8.75<\/span><span style=\"color: #E1E4E8\">,n  <\/span><span style=\"color: #B392F0\">low<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">8.08<\/span><span style=\"color: #E1E4E8\">,n  <\/span><span style=\"color: #B392F0\">close<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">8.55<\/span><span style=\"color: #E1E4E8\">,n  <\/span><span style=\"color: #B392F0\">volume<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">275800<\/span><span style=\"color: #E1E4E8\">,n  <\/span><span style=\"color: #9ECBFF\">&#39;adj close&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">8.55<\/span><span style=\"color: #F97583\">n<\/span><span style=\"color: #E1E4E8\">}nnstocksu003e db.values.<\/span><span style=\"color: #B392F0\">countDocuments<\/span><span style=\"color: #E1E4E8\">()n4308303n<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>You can also see that this database has more than four million records\/documents and a huge amount of information in it. Queries run on such databases  usually take more time to execute. For example if we want to find out the first occurrence of Google\u2019s stock price, we issue the following query.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"stocks&gt; db.values.find({&quot;stock_symbol&quot;: &quot;GOOG&quot;}).sort({date: -1}).limit(1)\n[\n  {\n    _id: ObjectId('4d094f7ec96767d7a02a0af6'),\n    exchange: 'NASDAQ',\n    stock_symbol: 'GOOG',\n    date: '2008-03-07',\n    open: 428.88,\n    high: 440,\n    low: 426.24,\n    close: 433.35,\n    volume: 8071800,\n    'adj close': 433.35\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">stocks<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.values.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({<\/span><span style=\"color: #9ECBFF\">&quot;stock_symbol&quot;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #9ECBFF\">&quot;GOOG&quot;<\/span><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">sort<\/span><span style=\"color: #E1E4E8\">({date: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">limit<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;4d094f7ec96767d7a02a0af6&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    exchange: <\/span><span style=\"color: #9ECBFF\">&#39;NASDAQ&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    stock_symbol: <\/span><span style=\"color: #9ECBFF\">&#39;GOOG&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    date: <\/span><span style=\"color: #9ECBFF\">&#39;2008-03-07&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    open: <\/span><span style=\"color: #79B8FF\">428.88<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    high: <\/span><span style=\"color: #79B8FF\">440<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    low: <\/span><span style=\"color: #79B8FF\">426.24<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    close: <\/span><span style=\"color: #79B8FF\">433.35<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    volume: <\/span><span style=\"color: #79B8FF\">8071800<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;adj close&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">433.35<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>We observe that this query takes time to run. Lets see if we can actually measure the time taken. Fortunately we have a explain() method. MongoDB\u2019s explain command provides detailed information about a given query execution details. It provides even more detail with the <code>executionStats<\/code> parameter. Let us see an example<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Issue a slow query<\/h3>\n\n\n\n<p>Let us develop a query to finding the highest closing price in the data set.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"stocks&gt; db.values.find({}).sort({close: -1}).limit(1)\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">stocks<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.values.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({}).<\/span><span style=\"color: #B392F0\">sort<\/span><span style=\"color: #E1E4E8\">({close: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">limit<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>When we execute this query you observe it takes more time to execute and produce the following result.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  {\n    _id: ObjectId('4d094fc2c96767d7a0360a64'),\n    exchange: 'NASDAQ',\n    stock_symbol: 'BORD',\n    date: '2000-09-20',\n    open: 7500,\n    high: 7500,\n    low: 7500,\n    close: 7500,\n    volume: 400,\n    'adj close': 6679.94\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;4d094fc2c96767d7a0360a64&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    exchange: <\/span><span style=\"color: #9ECBFF\">&#39;NASDAQ&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    stock_symbol: <\/span><span style=\"color: #9ECBFF\">&#39;BORD&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    date: <\/span><span style=\"color: #9ECBFF\">&#39;2000-09-20&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    open: <\/span><span style=\"color: #79B8FF\">7500<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    high: <\/span><span style=\"color: #79B8FF\">7500<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    low: <\/span><span style=\"color: #79B8FF\">7500<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    close: <\/span><span style=\"color: #79B8FF\">7500<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    volume: <\/span><span style=\"color: #79B8FF\">400<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #9ECBFF\">&#39;adj close&#39;<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #79B8FF\">6679.94<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Execution statistics<\/h3>\n\n\n\n<p>To obtain execution statistics we need to append the explain method. To get more details pass  <code>executionStats<\/code> to the explain method.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"stocks&gt; db.values.find({}).sort({close: -1}).limit(1).explain()\n\nstocks&gt; db.values.find({}).sort({close: -1}).limit(1).explain(&quot;executionStats&quot;)\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">stocks<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.values.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({}).<\/span><span style=\"color: #B392F0\">sort<\/span><span style=\"color: #E1E4E8\">({close: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">limit<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">explain<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">stocks<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.values.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({}).<\/span><span style=\"color: #B392F0\">sort<\/span><span style=\"color: #E1E4E8\">({close: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">limit<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">explain<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;executionStats&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>You can see from its output that it provides us with a wealth of information regarding the query. But what we are interested is in the execution time and number of documents it has scanned to obtain the result. These information can be obtained as follows.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"stocks&gt; db.values.find({}).sort({close: -1}).limit(1).explain(&quot;executionStats&quot;).executionStats.totalDocsExamined\n4308303\n\nstocks&gt; db.values.find({}).sort({close: -1}).limit(1).explain(&quot;executionStats&quot;).executionStats.executionTimeMillis\n1831\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">stocks<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.values.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({}).<\/span><span style=\"color: #B392F0\">sort<\/span><span style=\"color: #E1E4E8\">({close: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">limit<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">explain<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;executionStats&quot;<\/span><span style=\"color: #E1E4E8\">).executionStats.totalDocsExamined<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">4308303<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">stocks<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.values.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({}).<\/span><span style=\"color: #B392F0\">sort<\/span><span style=\"color: #E1E4E8\">({close: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">limit<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">explain<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;executionStats&quot;<\/span><span style=\"color: #E1E4E8\">).executionStats.executionTimeMillis<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">1831<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>We see that it has scanned all the documents(4308303) to arrive at the result and it has taken 1.8 seconds. The reason for this performance is that the database is not indexed. Let us now index and see the performance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create a Index and optimize query performance<\/h3>\n\n\n\n<p>We will add an index on the <code>close<\/code> field.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"stocks&gt; db.values.createIndex({close: 1})\nclose_1\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">stocks<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.values.<\/span><span style=\"color: #B392F0\">createIndex<\/span><span style=\"color: #E1E4E8\">({close: <\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">})<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">close_1<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>We will rerun the queries now and examine the query performance.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(212, 226, 245, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"stocks&gt; db.values.find({}).sort({close: -1}).limit(1).explain(&quot;executionStats&quot;).executionStats.totalDocsExamined\n1\n\nstocks&gt; db.values.find({}).sort({close: -1}).limit(1).explain(&quot;executionStats&quot;).executionStats.executionTimeMillis\n57\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">stocks<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.values.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({}).<\/span><span style=\"color: #B392F0\">sort<\/span><span style=\"color: #E1E4E8\">({close: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">limit<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">explain<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;executionStats&quot;<\/span><span style=\"color: #E1E4E8\">).executionStats.totalDocsExamined<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">1<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #E1E4E8\">stocks<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.values.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({}).<\/span><span style=\"color: #B392F0\">sort<\/span><span style=\"color: #E1E4E8\">({close: <\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">}).<\/span><span style=\"color: #B392F0\">limit<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">).<\/span><span style=\"color: #B392F0\">explain<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;executionStats&quot;<\/span><span style=\"color: #E1E4E8\">).executionStats.executionTimeMillis<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">57<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Now after the database is indexed we see a huge improvement in performance. The no of records scanned is just 1 and  query took only 57 milliseconds to execute.<\/p>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P09\">Question 9<\/h2>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P09a\">a. Develop a query to demonstrate Text search using catalog data collection for a given word.<\/h2>\n\n\n\n<p>To demonstrate text search in MongoDB using a <code>catalog<\/code> collection, we&#8217;ll follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Create the <code>catalog<\/code> collection and insert sample documents<\/strong>.<\/li>\n\n\n\n<li><strong>Create a text index on the relevant fields<\/strong>.<\/li>\n\n\n\n<li><strong>Perform a text search query to find documents containing a specific word<\/strong>.<\/li>\n<\/ol>\n\n\n\n<p>For this example let us consider a movie database that has been imported from a CSV file. We can import data from the CSV file using the <code>mongoimport<\/code> utility as follows:<\/p>\n\n\n\n<p>The CSV file <code>kan_movies.csv<\/code> is provided below for your reference.<\/p>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-ec2af4d6-d063-4699-8a02-514af0f89904\" href=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/06\/kan_movies.csv\">kan_movies<\/a><a href=\"https:\/\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/06\/kan_movies.csv\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-ec2af4d6-d063-4699-8a02-514af0f89904\">Download<\/a><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Importing from CSV file using mongoimport into the <code>catalog<\/code> Collection <\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"mongoimport --db=kannadaMoviesDB --collection='catalog' --file=kan_movies.csv --type=csv --fields=&quot;name&quot;,&quot;year&quot;,&quot;duration&quot;,&quot;rating&quot;,&quot;genre&quot;,&quot;lang&quot;\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">mongoimport <\/span><span style=\"color: #F97583\">--<\/span><span style=\"color: #E1E4E8\">db<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\">kannadaMoviesDB <\/span><span style=\"color: #F97583\">--<\/span><span style=\"color: #E1E4E8\">collection<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #9ECBFF\">&#39;catalog&#39;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">--<\/span><span style=\"color: #E1E4E8\">file<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\">kan_movies.csv <\/span><span style=\"color: #F97583\">--<\/span><span style=\"color: #E1E4E8\">type<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\">csv <\/span><span style=\"color: #F97583\">--<\/span><span style=\"color: #E1E4E8\">fields<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #9ECBFF\">&quot;name&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><span style=\"color: #9ECBFF\">&quot;year&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><span style=\"color: #9ECBFF\">&quot;duration&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><span style=\"color: #9ECBFF\">&quot;rating&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><span style=\"color: #9ECBFF\">&quot;genre&quot;<\/span><span style=\"color: #E1E4E8\">,<\/span><span style=\"color: #9ECBFF\">&quot;lang&quot;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&#8211;db parameter is used to specify the database into which data is to be imported.<\/li>\n\n\n\n<li>&#8211;file parameter is used to specify the file from which data is to be imported<\/li>\n\n\n\n<li>&#8211;type parameter is used to specify the file type (csv, json,&#8230;..)<\/li>\n\n\n\n<li>&#8211;collection parameter is used to specify the collection into which data is to be imported.<\/li>\n\n\n\n<li>&#8211;fields parameter is used to specify a list of strings that are field names in the collection.<\/li>\n<\/ul>\n\n\n\n<p>On success you should get the following output.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"2024-06-29T02:53:01.473+0530\tconnected to: mongodb:\/\/localhost\/\n2024-06-29T02:53:02.252+0530\t701 document(s) imported successfully. 0 document(s) failed to import.\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #79B8FF\">2024<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">06<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #E1E4E8\">29<\/span><span style=\"color: #B392F0\">T02<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #79B8FF\">53<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #79B8FF\">01<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">473<\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #79B8FF\">0530<\/span><span style=\"color: #E1E4E8\">\tconnected <\/span><span style=\"color: #B392F0\">to<\/span><span style=\"color: #E1E4E8\">: <\/span><span style=\"color: #B392F0\">mongodb<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #6A737D\">\/\/localhost\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">2024<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">06<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #E1E4E8\">29<\/span><span style=\"color: #B392F0\">T02<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #79B8FF\">53<\/span><span style=\"color: #E1E4E8\">:<\/span><span style=\"color: #79B8FF\">02<\/span><span style=\"color: #E1E4E8\">.<\/span><span style=\"color: #79B8FF\">252<\/span><span style=\"color: #F97583\">+<\/span><span style=\"color: #79B8FF\">0530<\/span><span style=\"color: #E1E4E8\">\t<\/span><span style=\"color: #79B8FF\">701<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">document<\/span><span style=\"color: #E1E4E8\">(s) imported successfully. <\/span><span style=\"color: #79B8FF\">0<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">document<\/span><span style=\"color: #E1E4E8\">(s) failed to import.<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Now launch MongoDB and choose the newly created database as follows:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"test&gt; use kannadaMoviesDB\nswitched to db kannadaMoviesDB\nkannadaMoviesDB&gt; show collections\ncatalog\nkannadaMoviesDB&gt; db.catalog.countDocuments()\n701\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">test<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> use kannadaMoviesDB<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">switched to db kannadaMoviesDB<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">kannadaMoviesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> show collections<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">catalog<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">kannadaMoviesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> db.catalog.<\/span><span style=\"color: #B392F0\">countDocuments<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #79B8FF\">701<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Alternatively you can create a <code>catalog<\/code> collection by adding documents using <code>insertMany<\/code> query as done in previous exercises.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create a Text Index<\/h3>\n\n\n\n<p>Next, create a text index on the <code>name<\/code> and <code>genre<\/code> fields to enable text search.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Create a text index on the name and genre fields\ndb.catalog.createIndex({name: &quot;text&quot;, genre: &quot;text&quot;})\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Create a text index on the name and genre fields<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">db.catalog.<\/span><span style=\"color: #B392F0\">createIndex<\/span><span style=\"color: #E1E4E8\">({name: <\/span><span style=\"color: #9ECBFF\">&quot;text&quot;<\/span><span style=\"color: #E1E4E8\">, genre: <\/span><span style=\"color: #9ECBFF\">&quot;text&quot;<\/span><span style=\"color: #E1E4E8\">})<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading has-e-1-e-4-e-8-color has-text-color\">Step 3: Perform a Text Search Query<\/h3>\n\n\n\n<p class=\"has-e-1-e-4-e-8-color has-text-color\">Now, let&#8217;s perform a text search to find documents containing a specific word. For example, let&#8217;s search for the word &#8220;maga&#8221;.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Perform a text search query to find documents containing the word &quot;maga&quot;\ndb.catalog.find({$text: {$search: &quot;maga&quot;}})\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Perform a text search query to find documents containing the word &quot;maga&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">db.catalog.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({$text: {$search: <\/span><span style=\"color: #9ECBFF\">&quot;maga&quot;<\/span><span style=\"color: #E1E4E8\">}})<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading has-e-1-e-4-e-8-color has-text-color\">Output<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  {\n    _id: ObjectId('667f29b50c118ded9b39bd44'),\n    name: 'Jayammana Maga',\n    year: 2013,\n    duration: '139 min',\n    rating: 7.1,\n    genre: 'Drama',\n    lang: 'kannada'\n  },\n  {\n    _id: ObjectId('667f29b50c118ded9b39bc7b'),\n    name: 'Rajannana Maga',\n    year: 2018,\n    duration: '143 min',\n    rating: 7.8,\n    genre: 'Action',\n    lang: 'kannada'\n  },\n  {\n    _id: ObjectId('667f29b50c118ded9b39beea'),\n    name: 'Thayige thakka maga',\n    year: 2018,\n    duration: '147 min',\n    rating: 5.4,\n    genre: 'Drama',\n    lang: 'kannada'\n  },\n  {\n    _id: ObjectId('667f29b50c118ded9b39bd97'),\n    name: 'Bhootayyana Maga Ayyu',\n    year: 1974,\n    duration: '155 min',\n    rating: 8.3,\n    genre: 'Drama',\n    lang: 'kannada'\n  },\n  {\n    _id: ObjectId('667f29b50c118ded9b39bd31'),\n    name: 'Jaga Mechida Maga',\n    year: 1972,\n    duration: '153 min',\n    rating: 8.2,\n    genre: 'Drama',\n    lang: 'kannada'\n  },\n  {\n    _id: ObjectId('667f29b50c118ded9b39bd11'),\n    name: 'Daari Tappida Maga',\n    year: 1975,\n    duration: '138 min',\n    rating: 7.6,\n    genre: 'Crime, Drama            ',\n    lang: 'kannada'\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bd44&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Jayammana Maga&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2013<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;139 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">7.1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Drama&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bc7b&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Rajannana Maga&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2018<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;143 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">7.8<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Action&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39beea&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Thayige thakka maga&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2018<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;147 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">5.4<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Drama&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bd97&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Bhootayyana Maga Ayyu&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">1974<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;155 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">8.3<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Drama&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bd31&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Jaga Mechida Maga&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">1972<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;153 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">8.2<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Drama&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bd11&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Daari Tappida Maga&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">1975<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;138 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">7.6<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Crime, Drama            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Perform a text search query to find documents containing the word &quot;raju&quot;\ndb.catalog.find({$text: {$search: &quot;raju&quot;}})\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Perform a text search query to find documents containing the word &quot;raju&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">db.catalog.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({$text: {$search: <\/span><span style=\"color: #9ECBFF\">&quot;raju&quot;<\/span><span style=\"color: #E1E4E8\">}})<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading has-e-1-e-4-e-8-color has-text-color\">Output<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  {\n    _id: ObjectId('667f29b50c118ded9b39bd33'),\n    name: 'Raju Kannada Medium',\n    year: 2018,\n    duration: '159 min',\n    rating: 7.2,\n    genre: 'Comedy, Drama            ',\n    lang: 'kannada'\n  },\n  {\n    _id: ObjectId('667f29b50c118ded9b39bcd0'),\n    name: 'First Rank Raju',\n    year: 2015,\n    duration: '148 min',\n    rating: 7.8,\n    genre: 'Comedy, Drama            ',\n    lang: 'kannada'\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bd33&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Raju Kannada Medium&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2018<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;159 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">7.2<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Comedy, Drama            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bcd0&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;First Rank Raju&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2015<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;148 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">7.8<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Comedy, Drama            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Perform a Text Search Query for a phrase<\/h3>\n\n\n\n<p>Now, let&#8217;s perform a text search to find documents containing a specific phrase. For example, let&#8217;s search for the phrase &#8220;tappida Maga&#8221;.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Perform a text search query to find documents containing the phrase &quot;maga&quot;\ndb.catalog.find({$text: {$search: &quot;&quot;tappida Maga&quot;&quot;}})\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Perform a text search query to find documents containing the phrase &quot;maga&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">db.catalog.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({$text: {$search: <\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #79B8FF\">&quot;<\/span><span style=\"color: #9ECBFF\">tappida Maga<\/span><span style=\"color: #79B8FF\">&quot;<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #E1E4E8\">}})<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  {\n    _id: ObjectId('667f29b50c118ded9b39bd11'),\n    name: 'Daari Tappida Maga',\n    year: 1975,\n    duration: '138 min',\n    rating: 7.6,\n    genre: 'Crime, Drama            ',\n    lang: 'kannada'\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bd11&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Daari Tappida Maga&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">1975<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;138 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">7.6<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Crime, Drama            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Inserting Documents<\/strong>: We insert several documents into the <code>catalog<\/code> collection with fields <code>name<\/code>,<code>year<\/code>,<code>duration<\/code>,<code>rating<\/code>,<code>genre<\/code>, and <code>lang<\/code>.<\/li>\n\n\n\n<li><strong>Creating a Text Index<\/strong>: We create a text index on the <code>name<\/code> and <code>description<\/code> fields to enable text search.<\/li>\n\n\n\n<li><strong>Performing a Text Search<\/strong>: We use the <code>$text<\/code> operator with the <code>$search<\/code> parameter to find documents that contain the word &#8220;raju&#8221; in either the <code>name<\/code> or <code>genre<\/code> fields.<\/li>\n<\/ol>\n\n\n\n<p>This script sets up the <code>catalog<\/code> collection, creates a text index, and demonstrates a text search query to find documents containing a specific word.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P09b\">b. Develop queries to illustrate excluding documents with certain words and phrases<\/h2>\n\n\n\n<p>To exclude documents containing certain words or phrases in MongoDB, you can use the <code>$text<\/code> operator combined with the <code>$search<\/code> parameter and the negation (<code>-<\/code>) operator. This allows you to perform text searches that exclude specific terms.<\/p>\n\n\n\n<p>A&nbsp;<em>negated<\/em>&nbsp;term is a term that is prefixed by a minus sign&nbsp;<code>-<\/code>. If you negate a term, the&nbsp;<code>$text<\/code>&nbsp;operator excludes the documents that contain those terms from the results.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step-by-Step Process<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Set up the <code>catalog<\/code> collection<\/strong>: Insert sample documents.<\/li>\n\n\n\n<li><strong>Create a text index<\/strong>: Enable text search.<\/li>\n\n\n\n<li><strong>Perform queries to exclude documents<\/strong>: Use the <code>$text<\/code> operator with negation.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create a <code>catalog<\/code> collection<\/h3>\n\n\n\n<p>For this we will use the same <code>catalog<\/code> collection from our previous example. You can follow the same steps as earlier to create the collection.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create a Text Index<\/h3>\n\n\n\n<p>Create a text index on the <code>name<\/code> and <code>description<\/code> fields.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Create a text index on the name and description fields\ndb.catalog.createIndex({ name: &quot;text&quot;, description: &quot;text&quot; })\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Create a text index on the name and description fields<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">db.catalog.<\/span><span style=\"color: #B392F0\">createIndex<\/span><span style=\"color: #E1E4E8\">({ name: <\/span><span style=\"color: #9ECBFF\">&quot;text&quot;<\/span><span style=\"color: #E1E4E8\">, description: <\/span><span style=\"color: #9ECBFF\">&quot;text&quot;<\/span><span style=\"color: #E1E4E8\"> })<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Perform Queries to Exclude Documents<\/h3>\n\n\n\n<p>Use the <code>$text<\/code> operator with negation to exclude documents containing specific words or phrases.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example 1: Exclude Documents Containing the Word &#8220;action&#8221;<\/h4>\n\n\n\n<p>Suppose we want to list movies that belong to <em><strong>crime<\/strong><\/em> or <em><strong>romance<\/strong><\/em> (or both) genre but not belonging to the <em><strong>action<\/strong><\/em> genre. Since this will yield too many results we will restrict the search to the year 2021.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Exclude documents containing the word &quot;action&quot;\ndb.catalog.find({ $text: { $search: &quot;crime romance -action&quot; }, year:2021 } )\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Exclude documents containing the word &quot;action&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">db.catalog.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({ $text: { $search: <\/span><span style=\"color: #9ECBFF\">&quot;crime romance -action&quot;<\/span><span style=\"color: #E1E4E8\"> }, year:<\/span><span style=\"color: #79B8FF\">2021<\/span><span style=\"color: #E1E4E8\"> } )<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  {\n    _id: ObjectId('667f29b50c118ded9b39bcaa'),\n    name: 'Raktha Gulabi',\n    year: 2021,\n    duration: '132 min',\n    rating: 9.4,\n    genre: 'Crime',\n    lang: 'kannada'\n  },\n  {\n    _id: ObjectId('667f29b50c118ded9b39bd82'),\n    name: 'Laddu',\n    year: 2021,\n    duration: '127 min',\n    rating: 8.6,\n    genre: 'Comedy, Romance            ',\n    lang: 'kannada'\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bcaa&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Raktha Gulabi&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2021<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;132 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">9.4<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Crime&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bd82&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Laddu&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2021<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;127 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">8.6<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Comedy, Romance            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Example 2: Exclude Documents Containing the Phrase &#8220;da maga&#8221;<\/h4>\n\n\n\n<p>We display those documents that have the word <code>maga<\/code> but not the phrase <code>da maga<\/code>.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ Exclude documents containing the phrase &quot;da maga&quot;\ndb.catalog.find({$text: {$search: &quot;maga -&quot;da maga&quot;&quot;}})\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A737D\">\/\/ Exclude documents containing the phrase &quot;da maga&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">db.catalog.<\/span><span style=\"color: #B392F0\">find<\/span><span style=\"color: #E1E4E8\">({$text: {$search: <\/span><span style=\"color: #9ECBFF\">&quot;maga -<\/span><span style=\"color: #79B8FF\">&quot;<\/span><span style=\"color: #9ECBFF\">da maga<\/span><span style=\"color: #79B8FF\">&quot;<\/span><span style=\"color: #9ECBFF\">&quot;<\/span><span style=\"color: #E1E4E8\">}})<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading has-e-1-e-4-e-8-color has-text-color\">Output<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"[\n  {\n    _id: ObjectId('667f29b50c118ded9b39bd44'),\n    name: 'Jayammana Maga',\n    year: 2013,\n    duration: '139 min',\n    rating: 7.1,\n    genre: 'Drama',\n    lang: 'kannada'\n  },\n  {\n    _id: ObjectId('667f29b50c118ded9b39bc7b'),\n    name: 'Rajannana Maga',\n    year: 2018,\n    duration: '143 min',\n    rating: 7.8,\n    genre: 'Action',\n    lang: 'kannada'\n  },\n  {\n    _id: ObjectId('667f29b50c118ded9b39beea'),\n    name: 'Thayige thakka maga',\n    year: 2018,\n    duration: '147 min',\n    rating: 5.4,\n    genre: 'Drama',\n    lang: 'kannada'\n  },\n  {\n    _id: ObjectId('667f29b50c118ded9b39bd97'),\n    name: 'Bhootayyana Maga Ayyu',\n    year: 1974,\n    duration: '155 min',\n    rating: 8.3,\n    genre: 'Drama',\n    lang: 'kannada'\n  }\n]\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bd44&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Jayammana Maga&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2013<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;139 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">7.1<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Drama&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bc7b&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Rajannana Maga&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2018<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;143 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">7.8<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Action&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39beea&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Thayige thakka maga&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">2018<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;147 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">5.4<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Drama&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #B392F0\">ObjectId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&#39;667f29b50c118ded9b39bd97&#39;<\/span><span style=\"color: #E1E4E8\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    name: <\/span><span style=\"color: #9ECBFF\">&#39;Bhootayyana Maga Ayyu&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    year: <\/span><span style=\"color: #79B8FF\">1974<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    duration: <\/span><span style=\"color: #9ECBFF\">&#39;155 min&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    rating: <\/span><span style=\"color: #79B8FF\">8.3<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    genre: <\/span><span style=\"color: #9ECBFF\">&#39;Drama&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    lang: <\/span><span style=\"color: #9ECBFF\">&#39;kannada&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Note:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The negated word excludes documents that contain the negated word from the result set.<\/li>\n\n\n\n<li>When passed a string that only contains negated words,&nbsp;<code>$text<\/code>&nbsp;does not match any documents.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id=\"P10\">Question 10<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"P10a\">Aggregation Pipeline to illustrate Text search on Catalog data collection<\/h2>\n\n\n\n<p><strong>Develop an aggregation pipeline to illustrate Text search on Catalog data collection.<\/strong><\/p>\n\n\n\n<p>The aggregation framework in MongoDB is a powerful tool for data processing and transformation. It consists of a series of stages, each stage performing an operation on the input documents and passing the results to the next stage. This sequence of operations is called an aggregation pipeline.<\/p>\n\n\n\n<p>Here is a step-by-step guide to using the aggregation pipeline in MongoDB, with examples of various stages such as <code>$match<\/code>, <code>$group<\/code>, <code>$sort<\/code>, <code>$project<\/code>, <code>$skip<\/code>, and others.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example Aggregation Pipeline<\/h3>\n\n\n\n<p>Let&#8217;s create an aggregation pipeline that includes various stages:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>$match<\/code>: Filter documents to include only those in the year <strong>2017<\/strong>.<\/li>\n\n\n\n<li><code>$group<\/code>: Group documents by <code>genre<\/code> and calculate the average rating for each genre.<\/li>\n\n\n\n<li><code>$sort<\/code>: Sort the results by <code>avgRating<\/code> in descending order.<\/li>\n\n\n\n<li><code>$project<\/code>: Include specific fields in the output<\/li>\n\n\n\n<li><code>$limit<\/code>: Limit the output to 5 results.<\/li>\n\n\n\n<li><code>$skip<\/code>: Skip the first two results.<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"result = db.catalog.aggregate([\n  \/\/ 1. Match stage: Filter documents by year 2017\n{$match:{year :2017}}, \n  \/\/ 2. Group stage: Group by genre and calculate average rating\n{$group:{_id: &quot;$genre&quot;, avgRating:{$avg: &quot;$rating&quot;}}}, \n  \/\/ 3. Sort stage: Sort by avgRating in descending order\n{$sort: {avgRating:-1}},\n  \/\/ 4. Project stage: Include specific fields\n{$project:{year:&quot;$year&quot;, avgRating:1, genre:1} }, \n  \/\/ 5. Limit stage: Limit the output to 5 results\n{$limit:5} ]).toArray()\nprint(&quot;Top 5 rated movie genres with their average rating&quot;)\nprintjson(result)\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">result <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> db.catalog.<\/span><span style=\"color: #B392F0\">aggregate<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #6A737D\">\/\/ 1. Match stage: Filter documents by year 2017<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{$match:{year :<\/span><span style=\"color: #79B8FF\">2017<\/span><span style=\"color: #E1E4E8\">}}, <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #6A737D\">\/\/ 2. Group stage: Group by genre and calculate average rating<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{$group:{_id: <\/span><span style=\"color: #9ECBFF\">&quot;$genre&quot;<\/span><span style=\"color: #E1E4E8\">, avgRating:{$avg: <\/span><span style=\"color: #9ECBFF\">&quot;$rating&quot;<\/span><span style=\"color: #E1E4E8\">}}}, <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #6A737D\">\/\/ 3. Sort stage: Sort by avgRating in descending order<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{$sort: {avgRating:<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">}},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #6A737D\">\/\/ 4. Project stage: Include specific fields<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{$project:{year:<\/span><span style=\"color: #9ECBFF\">&quot;$year&quot;<\/span><span style=\"color: #E1E4E8\">, avgRating:<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, genre:<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">} }, <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #6A737D\">\/\/ 5. Limit stage: Limit the output to 5 results<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{$limit:<\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\">} ]).<\/span><span style=\"color: #B392F0\">toArray<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Top 5 rated movie genres with their average rating&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">printjson<\/span><span style=\"color: #E1E4E8\">(result)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Top 5 rated movie genres with their average rating\n[\n  {\n    _id: 'Mystery',\n    avgRating: 7.9\n  },\n  {\n    _id: 'Comedy, Drama            ',\n    avgRating: 7.9\n  },\n  {\n    _id: 'Adventure, Family            ',\n    avgRating: 7.8\n  },\n  {\n    _id: 'Drama, Romance, Thriller            ',\n    avgRating: 7.7\n  },\n  {\n    _id: 'Drama',\n    avgRating: 7.616666666666667\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Top <\/span><span style=\"color: #79B8FF\">5<\/span><span style=\"color: #E1E4E8\"> rated movie genres <\/span><span style=\"color: #F97583\">with<\/span><span style=\"color: #E1E4E8\"> their average rating<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #9ECBFF\">&#39;Mystery&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    avgRating: <\/span><span style=\"color: #79B8FF\">7.9<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #9ECBFF\">&#39;Comedy, Drama            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    avgRating: <\/span><span style=\"color: #79B8FF\">7.9<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #9ECBFF\">&#39;Adventure, Family            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    avgRating: <\/span><span style=\"color: #79B8FF\">7.8<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #9ECBFF\">&#39;Drama, Romance, Thriller            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    avgRating: <\/span><span style=\"color: #79B8FF\">7.7<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #9ECBFF\">&#39;Drama&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    avgRating: <\/span><span style=\"color: #79B8FF\">7.616666666666667<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Adding another stage using <code>$skip<\/code><\/h3>\n\n\n\n<p>To find the remaining five genres among the top-rated seven genres after skipping the first two, we can use the <code>$skip<\/code> stage in the aggregation pipeline.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"result2 = db.catalog.aggregate([\n  \/\/ 1. Match stage: Filter documents by year 2017\n{$match:{year :2017}}, \n  \/\/ 2. Group stage: Group by genre and calculate average rating\n{$group:{_id: &quot;$genre&quot;, avgRating:{$avg: &quot;$rating&quot;}}}, \n  \/\/ 3. Sort stage: Sort by avgRating in descending order\n{$sort: {avgRating:-1}},\n  \/\/ 4. Project stage: Include specific fields\n{$project:{year:&quot;$year&quot;, avgRating:1, genre:1} }, \n  \/\/ 5. Limit stage: Limit the output to 7 results\n{$limit:7},\n  \/\/ 6. Skip stage: Skip the first two results\n{$skip:2} ]).toArray()\nprint(&quot;Top 7 rated movie genres with their average rating with he firsttwo skipped&quot;)\nprintjson(result2)\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">result2 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #E1E4E8\"> db.catalog.<\/span><span style=\"color: #B392F0\">aggregate<\/span><span style=\"color: #E1E4E8\">([<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #6A737D\">\/\/ 1. Match stage: Filter documents by year 2017<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{$match:{year :<\/span><span style=\"color: #79B8FF\">2017<\/span><span style=\"color: #E1E4E8\">}}, <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #6A737D\">\/\/ 2. Group stage: Group by genre and calculate average rating<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{$group:{_id: <\/span><span style=\"color: #9ECBFF\">&quot;$genre&quot;<\/span><span style=\"color: #E1E4E8\">, avgRating:{$avg: <\/span><span style=\"color: #9ECBFF\">&quot;$rating&quot;<\/span><span style=\"color: #E1E4E8\">}}}, <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #6A737D\">\/\/ 3. Sort stage: Sort by avgRating in descending order<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{$sort: {avgRating:<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">}},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #6A737D\">\/\/ 4. Project stage: Include specific fields<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{$project:{year:<\/span><span style=\"color: #9ECBFF\">&quot;$year&quot;<\/span><span style=\"color: #E1E4E8\">, avgRating:<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">, genre:<\/span><span style=\"color: #79B8FF\">1<\/span><span style=\"color: #E1E4E8\">} }, <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #6A737D\">\/\/ 5. Limit stage: Limit the output to 7 results<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{$limit:<\/span><span style=\"color: #79B8FF\">7<\/span><span style=\"color: #E1E4E8\">},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  <\/span><span style=\"color: #6A737D\">\/\/ 6. Skip stage: Skip the first two results<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{$skip:<\/span><span style=\"color: #79B8FF\">2<\/span><span style=\"color: #E1E4E8\">} ]).<\/span><span style=\"color: #B392F0\">toArray<\/span><span style=\"color: #E1E4E8\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">print<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">&quot;Top 7 rated movie genres with their average rating with he firsttwo skipped&quot;<\/span><span style=\"color: #E1E4E8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">printjson<\/span><span style=\"color: #E1E4E8\">(result2)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#24292e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"Top 7 rated movie genres with their average rating with he firsttwo skipped\nkannadaMoviesDB&gt; printjson(result2)\n[\n  {\n    _id: 'Adventure, Family            ',\n    avgRating: 7.8\n  },\n  {\n    _id: 'Drama, Romance, Thriller            ',\n    avgRating: 7.7\n  },\n  {\n    _id: 'Drama',\n    avgRating: 7.616666666666667\n  },\n  {\n    _id: 'Drama, History, Musical            ',\n    avgRating: 7.5\n  },\n  {\n    _id: 'Drama, Family, History            ',\n    avgRating: 7.5\n  }\n]\n\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">Top <\/span><span style=\"color: #79B8FF\">7<\/span><span style=\"color: #E1E4E8\"> rated movie genres <\/span><span style=\"color: #F97583\">with<\/span><span style=\"color: #E1E4E8\"> their average rating <\/span><span style=\"color: #F97583\">with<\/span><span style=\"color: #E1E4E8\"> he firsttwo skipped<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">kannadaMoviesDB<\/span><span style=\"color: #F97583\">&gt;<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">printjson<\/span><span style=\"color: #E1E4E8\">(result2)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #9ECBFF\">&#39;Adventure, Family            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    avgRating: <\/span><span style=\"color: #79B8FF\">7.8<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #9ECBFF\">&#39;Drama, Romance, Thriller            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    avgRating: <\/span><span style=\"color: #79B8FF\">7.7<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #9ECBFF\">&#39;Drama&#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    avgRating: <\/span><span style=\"color: #79B8FF\">7.616666666666667<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #9ECBFF\">&#39;Drama, History, Musical            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    avgRating: <\/span><span style=\"color: #79B8FF\">7.5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    _id: <\/span><span style=\"color: #9ECBFF\">&#39;Drama, Family, History            &#39;<\/span><span style=\"color: #E1E4E8\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    avgRating: <\/span><span style=\"color: #79B8FF\">7.5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">]<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>The aggregation pipeline in MongoDB provides a flexible and powerful framework for data processing. By chaining multiple stages, you can filter, group, sort, project, and transform your data to suit your specific requirements.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<\/div>\n\n\n\n<p>If you are also looking for other Lab Manuals, head over to my following blog :<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-myblogosphere wp-block-embed-myblogosphere\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"2ToOO1W65z\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/vtu-lab-manuals-using-foss\/\">VTU Lab Manuals using FOSS<\/a><\/blockquote><iframe class=\"wp-embedded-content lazyload\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;VTU Lab Manuals using FOSS&#8221; &#8212; MyBlogosphere\" data-src=\"https:\/\/moodle.sit.ac.in\/blog\/vtu-lab-manuals-using-foss\/embed\/#?secret=RglKfKAW6M#?secret=2ToOO1W65z\" data-secret=\"2ToOO1W65z\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<div class=\"wp-block-query is-layout-flow wp-block-query-is-layout-flow\"><ul class=\"wp-block-post-template is-layout-flow wp-block-post-template-is-layout-flow\"><li class=\"wp-block-post post-1258 post type-post status-publish format-standard has-post-thumbnail hentry category-programming tag-21cs42 tag-21csl46 tag-basics-of-java-programming tag-bcs358d tag-bcsl305 tag-besck104e-204e tag-besck204e tag-bmats101 tag-bplck105a tag-bplck105a-205a tag-bplck105b tag-bplck105b-205b tag-bplck105c tag-bplck105c-205c tag-bplck105d tag-bplck105d-205d-2 tag-bplck205a tag-bplck205b tag-bplck205c tag-bplck205d tag-bpops103 tag-bpops103-203-2 tag-bpops103-203 tag-bpops203 tag-c tag-c-2 tag-codeblocks tag-computer-programming tag-cse tag-data-structures-laboratory tag-data-structures-laboratory-bcsl305 tag-data-visualization-with-python tag-data-visualization-with-python-bcs358d tag-design-analysis-of-algorithms-lab-manual-21cs42 tag-first-year-vtu tag-foss tag-gcc-compiler tag-introduction-to-c-programming-2 tag-introduction-to-python-programming tag-introduction-to-web-programming tag-java tag-lab-manual tag-mathematics-i-for-computer-science-and-engineering-stream tag-principles-of-programming-using-c tag-python tag-python-programming-laboratory-21csl46 tag-vtu\">\n\n<div class=\"wp-block-columns are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:25%\"><figure class=\"wp-block-post-featured-image\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/vtu-lab-manuals-using-foss\/\" target=\"_self\"  ><img data-recalc-dims=\"1\" decoding=\"async\" width=\"1200\" height=\"675\" data-src=\"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/10\/gnulogo3.png?resize=1200%2C675&#038;ssl=1\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image lazyload\" alt=\"VTU Lab Manuals using FOSS\" style=\"--smush-placeholder-width: 1200px; --smush-placeholder-aspect-ratio: 1200\/675;object-fit:cover;\" data-srcset=\"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/10\/gnulogo3.png?w=1200&amp;ssl=1 1200w, https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/10\/gnulogo3.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/10\/gnulogo3.png?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2023\/10\/gnulogo3.png?resize=768%2C432&amp;ssl=1 768w\" data-sizes=\"(max-width: 1000px) 100vw, 1000px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><\/a><\/figure><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\"><h2 class=\"wp-block-post-title\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/vtu-lab-manuals-using-foss\/\" target=\"_self\" >VTU Lab Manuals using FOSS<\/a><\/h2><\/div>\n<\/div>\n\n<\/li><li class=\"wp-block-post post-2837 post type-post status-publish format-standard has-post-thumbnail hentry category-programming tag-4th-sem tag-4th-semester tag-bds456b tag-cse tag-database tag-foss tag-iv-semester tag-lab-manual tag-mongodb-lab-manual tag-mongodb-lab-manual-bds456b tag-spyder tag-vtu\">\n\n<div class=\"wp-block-columns are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:25%\"><figure class=\"wp-block-post-featured-image\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/mongodb-lab-manual-bds456b-2\/\" target=\"_self\"  ><img data-recalc-dims=\"1\" decoding=\"async\" width=\"683\" height=\"144\" data-src=\"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/gnuMongoDB.png?resize=683%2C144&#038;ssl=1\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image lazyload\" alt=\"MongoDB Lab Manual &#8211; BDS456B\" style=\"--smush-placeholder-width: 683px; --smush-placeholder-aspect-ratio: 683\/144;object-fit:cover;\" data-srcset=\"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/gnuMongoDB.png?w=683&amp;ssl=1 683w, https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/gnuMongoDB.png?resize=300%2C63&amp;ssl=1 300w\" data-sizes=\"(max-width: 683px) 100vw, 683px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><\/a><\/figure><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\"><h2 class=\"wp-block-post-title\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/mongodb-lab-manual-bds456b-2\/\" target=\"_self\" >MongoDB Lab Manual &#8211; BDS456B<\/a><\/h2><\/div>\n<\/div>\n\n<\/li><li class=\"wp-block-post post-2324 post type-post status-publish format-standard has-post-thumbnail hentry category-programming tag-21cs62 tag-cse tag-django tag-foss tag-full-stack-web-development tag-fullstack-development tag-html tag-lab-manual tag-python tag-vi-semester tag-vtu\">\n\n<div class=\"wp-block-columns are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:25%\"><figure class=\"wp-block-post-featured-image\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/full-stack-web-development-21cs62\/\" target=\"_self\"  ><img data-recalc-dims=\"1\" decoding=\"async\" width=\"654\" height=\"368\" data-src=\"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/06\/FULLSTACK-DJANGO-COURSE.png?resize=654%2C368&#038;ssl=1\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image lazyload\" alt=\"Full Stack Web Development &#8211; 21CS62\" style=\"--smush-placeholder-width: 654px; --smush-placeholder-aspect-ratio: 654\/368;object-fit:cover;\" data-srcset=\"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/06\/FULLSTACK-DJANGO-COURSE.png?w=654&amp;ssl=1 654w, https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/06\/FULLSTACK-DJANGO-COURSE.png?resize=300%2C169&amp;ssl=1 300w\" data-sizes=\"(max-width: 654px) 100vw, 654px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><\/a><\/figure><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\"><h2 class=\"wp-block-post-title\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/full-stack-web-development-21cs62\/\" target=\"_self\" >Full Stack Web Development &#8211; 21CS62<\/a><\/h2><\/div>\n<\/div>\n\n<\/li><li class=\"wp-block-post post-2328 post type-post status-publish format-standard has-post-thumbnail hentry category-programming tag-21csl66 tag-6th-semester tag-computer-graphics tag-computer-graphics-and-image-processing-laboratory tag-computer-graphics-and-image-processing-laboratory-21csl66 tag-cse tag-foss tag-image-processing tag-lab-manual tag-opengl tag-python tag-vi-semester tag-vtu\">\n\n<div class=\"wp-block-columns are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:25%\"><figure class=\"wp-block-post-featured-image\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/computer-graphics-and-image-processing-laboratory-21csl66\/\" target=\"_self\"  ><img data-recalc-dims=\"1\" decoding=\"async\" width=\"1095\" height=\"213\" data-src=\"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/cg-2.png?resize=1095%2C213&#038;ssl=1\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image lazyload\" alt=\"COMPUTER GRAPHICS AND IMAGE PROCESSING LABORATORY &#8211; 21CSL66\" style=\"--smush-placeholder-width: 1095px; --smush-placeholder-aspect-ratio: 1095\/213;object-fit:cover;\" data-srcset=\"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/cg-2.png?w=1095&amp;ssl=1 1095w, https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/cg-2.png?resize=300%2C58&amp;ssl=1 300w, https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/cg-2.png?resize=1024%2C199&amp;ssl=1 1024w, https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/cg-2.png?resize=768%2C149&amp;ssl=1 768w\" data-sizes=\"(max-width: 1000px) 100vw, 1000px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><\/a><\/figure><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:75%\"><h2 class=\"wp-block-post-title\"><a href=\"https:\/\/moodle.sit.ac.in\/blog\/computer-graphics-and-image-processing-laboratory-21csl66\/\" target=\"_self\" >COMPUTER GRAPHICS AND IMAGE PROCESSING LABORATORY &#8211; 21CSL66<\/a><\/h2><\/div>\n<\/div>\n\n<\/li><\/ul><\/div>\n","protected":false},"excerpt":{"rendered":"<p>MongoDB Laboratory (BDS456B) In this blog post, you will find solutions for the MongoDB Laboratory (BDS456B) course work for the IV semester of VTU university. To follow along, you will need to have up a machine running any flavour of GNULinux OS. This blog provides instructions to get MongoDB installed on your system. The solutions [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2179,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","_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","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3],"tags":[358,92,371,78,372,26,338,35,374,373,81,43],"class_list":["post-2837","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming","tag-4th-sem","tag-4th-semester","tag-bds456b","tag-cse","tag-database","tag-foss","tag-iv-semester","tag-lab-manual","tag-mongodb-lab-manual","tag-mongodb-lab-manual-bds456b","tag-spyder","tag-vtu"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/moodle.sit.ac.in\/blog\/wp-content\/uploads\/2024\/05\/gnuMongoDB.png?fit=683%2C144&ssl=1","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/posts\/2837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/comments?post=2837"}],"version-history":[{"count":12,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/posts\/2837\/revisions"}],"predecessor-version":[{"id":2862,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/posts\/2837\/revisions\/2862"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/media\/2179"}],"wp:attachment":[{"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/media?parent=2837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/categories?post=2837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/moodle.sit.ac.in\/blog\/wp-json\/wp\/v2\/tags?post=2837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}