url
stringlengths
36
137
content
stringlengths
1.21k
7.75M
https://www.mongodb.com/docs/manual/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> What is MongoDB? <a class="headerlink leafygreen-ui-1kepx47" href="#what-is-mongodb-" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="what-is-mongodb-"> </div> </a> </h1> <div class="introduction css-l93vwo ewg622w0"> <p class="leafygreen-ui-1kp3ins"> MongoDB is a document database designed for ease of application development and scaling. </p> <p class="leafygreen-ui-1kp3ins"> You can run MongoDB in the following environments: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self"> <span> MongoDB Atlas <span> <svg alt="" aria-hidden="true" class="leafygreen-ui-1st74h4" height="12" role="presentation" viewbox="0 0 16 16" width="12"> <path d="M3 6.83212L9.94442 6.83212L8.40941 5.29711C8.01888 4.90659 8.01889 4.27342 8.40941 3.8829L8.64833 3.64398C9.03885 3.25346 9.67201 3.25345 10.0625 3.64398L13.4452 7.02661C13.4544 7.03518 13.4635 7.04395 13.4725 7.05292L13.7114 7.29184C14.1019 7.68237 14.1019 8.31553 13.7114 8.70605L10.0602 12.3572C9.66972 12.7477 9.03656 12.7477 8.64603 12.3572L8.40712 12.1183C8.01659 11.7278 8.01659 11.0946 8.40712 10.7041L9.9412 9.17L3 9.17C2.44771 9.17 2 8.72228 2 8.17L2 7.83212C2 7.27983 2.44772 6.83212 3 6.83212Z" fill="currentColor"> </path> </svg> </span> </span> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise"> MongoDB Enterprise <span> <svg alt="" aria-hidden="true" class="leafygreen-ui-1st74h4" height="12" role="presentation" viewbox="0 0 16 16" width="12"> <path d="M3 6.83212L9.94442 6.83212L8.40941 5.29711C8.01888 4.90659 8.01889 4.27342 8.40941 3.8829L8.64833 3.64398C9.03885 3.25346 9.67201 3.25345 10.0625 3.64398L13.4452 7.02661C13.4544 7.03518 13.4635 7.04395 13.4725 7.05292L13.7114 7.29184C14.1019 7.68237 14.1019 8.31553 13.7114 8.70605L10.0602 12.3572C9.66972 12.7477 9.03656 12.7477 8.64603 12.3572L8.40712 12.1183C8.01659 11.7278 8.01659 11.0946 8.40712 10.7041L9.9412 9.17L3 9.17C2.44771 9.17 2 8.72228 2 8.17L2 7.83212C2 7.27983 2.44772 6.83212 3 6.83212Z" fill="currentColor"> </path> </svg> </span> </a> : The subscription-based, self-managed version of MongoDB </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition"> MongoDB Community <span> <svg alt="" aria-hidden="true" class="leafygreen-ui-1st74h4" height="12" role="presentation" viewbox="0 0 16 16" width="12"> <path d="M3 6.83212L9.94442 6.83212L8.40941 5.29711C8.01888 4.90659 8.01889 4.27342 8.40941 3.8829L8.64833 3.64398C9.03885 3.25346 9.67201 3.25345 10.0625 3.64398L13.4452 7.02661C13.4544 7.03518 13.4635 7.04395 13.4725 7.05292L13.7114 7.29184C14.1019 7.68237 14.1019 8.31553 13.7114 8.70605L10.0602 12.3572C9.66972 12.7477 9.03656 12.7477 8.64603 12.3572L8.40712 12.1183C8.01659 11.7278 8.01659 11.0946 8.40712 10.7041L9.9412 9.17L3 9.17C2.44771 9.17 2 8.72228 2 8.17L2 7.83212C2 7.27983 2.44772 6.83212 3 6.83212Z" fill="currentColor"> </path> </svg> </span> </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> <a aria-disabled="false" class="lg-ui-0001 lg-ui-button-0000 button leafygreen-ui-cn6xft" data-lgid="lg-button" href="https://www.mongodb.com/cloud?tck=docs_server" target="_self"> <span> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> Get started with MongoDB Atlas </div> </span> </a> </div> <img alt="Homepage hero image" class="leafygreen-ui-1qnf57e" height="1444" src="/docs/manual/static/4b1986c728e4ba0b47222fe837fa98e8/e0e5a/hero.webp" srcset="/docs/manual/static/4b1986c728e4ba0b47222fe837fa98e8/3d215/hero.webp 506w, /docs/manual/static/4b1986c728e4ba0b47222fe837fa98e8/ab1e8/hero.webp 1012w, /docs/manual/static/4b1986c728e4ba0b47222fe837fa98e8/e0e5a/hero.webp 2024w" style="--border-color:#C1C7C6" width="2024"/> <div class="leafygreen-ui-xvo2tu"> What You Can Do </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Work with your data in MongoDB <a class="headerlink leafygreen-ui-1kepx47" href="#work-with-your-data-in-mongodb" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="work-with-your-data-in-mongodb"> </div> </a> </h2> <div aria-hidden="true"> </div> <div class="leafygreen-ui-gglyyn" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-16"> <div aria-label="Tabs to describe usage of create/deploy/store/transform" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_r68v18w1p" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_6wnr10jcz" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Store and query your data </div> </button> <button aria-controls="_jq5hzs3s0" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_vx2ukr7me" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Transform data with Aggregations </div> </button> <button aria-controls="_d8eo6yxa0" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_dtxlrd58r" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Secure access to your data </div> </button> <button aria-controls="_lutedas52" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_fxqxupuaw" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Deploy and scale your database </div> </button> </div> <div class="leafygreen-ui-ov1ktg"> <div class="leafygreen-ui-1sg2lsz"> </div> </div> </div> <div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels"> <div> <div aria-labelledby="_3cs02ese9" class="" id="_32g61vcz9" role="tabpanel"> <div class="leafygreen-ui-5xwxvr"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create a cluster in the MongoDB Atlas UI or the Atlas CLI\nquickly and easily. To learn more, see\nCreate a Cluster\nin the MongoDB Atlas documentation\nand Get Started with Atlas in the Atlas CLI\ndocumentation.For self-hosted deployments,\nsee Replication in the MongoDB manual\nto create a replica\nset.","name":"Deploy MongoDB"},{"@type":"HowToStep","text":"Access deployments in the\nMongoDB Atlas UI or connect with drivers or the\nMongoDB Shell (mongosh) in the MongoDB\nmanual.To learn more, see Find Your Connection String in the MongoDB manual.","name":"Connect to your deployment"},{"@type":"HowToStep","text":"Perform CRUD operations in the MongoDB Atlas UI or by using the\nMongoDB Query API - with or without transactions.To learn more, see\nCreate, View, Update, and Delete Documents in the MongoDB Atlas documentation and\nMongoDB CRUD Operations in the MongoDB manual.","name":"Insert, query, update, or delete documents"},{"@type":"HowToStep","text":"Design your data schema to support frequent access patterns.\nYou can update or enforce your schema at any point.To learn more, see Data Modeling Introduction in the MongoDB manual.","name":"Model your data"}],"name":"Work with your data in MongoDB - Store and query your data","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-qum8nr eccljxs0"> <div class="css-vq8pj5 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-18jxsvu e1ckbxcu2"> 1 </div> </div> <div class="css-clrhqf"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Deploy MongoDB <a class="headerlink leafygreen-ui-1kepx47" href="#deploy-mongodb" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="deploy-mongodb"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Create a cluster in the MongoDB Atlas UI or the Atlas CLI quickly and easily. To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/tutorial/create-new-cluster/" target="_self"> <span> Create a Cluster </span> </a> in the MongoDB Atlas documentation and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/cli/stable/atlas-cli-getting-started/" target="_self"> <span> Get Started with Atlas </span> </a> in the Atlas CLI documentation. </p> <p class="leafygreen-ui-1kp3ins"> For self-hosted deployments, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/#std-label-replication"> Replication </a> in the MongoDB manual to create a replica set. </p> </section> </div> </div> <div class="css-vq8pj5 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-18jxsvu e1ckbxcu2"> 2 </div> </div> <div class="css-clrhqf"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Connect to your deployment <a class="headerlink leafygreen-ui-1kepx47" href="#connect-to-your-deployment" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="connect-to-your-deployment"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Access deployments in the MongoDB Atlas UI or connect with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> drivers </span> </a> or the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self"> <span> MongoDB Shell (mongosh) </span> </a> in the MongoDB manual. </p> <p class="leafygreen-ui-1kp3ins"> To learn more, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string/#std-label-find-connection-string"> Find Your Connection String </a> in the MongoDB manual. </p> </section> </div> </div> <div class="css-vq8pj5 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-18jxsvu e1ckbxcu2"> 3 </div> </div> <div class="css-clrhqf"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Insert, query, update, or delete documents <a class="headerlink leafygreen-ui-1kepx47" href="#insert--query--update--or-delete-documents" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="insert--query--update--or-delete-documents"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Perform CRUD operations in the MongoDB Atlas UI or by using the MongoDB Query API - with or without transactions. </p> <p class="leafygreen-ui-1kp3ins"> To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/documents/" target="_self"> <span> Create, View, Update, and Delete Documents </span> </a> in the MongoDB Atlas documentation and <a class="leafygreen-ui-tqgtui" href="/docs/manual/crud/#std-label-crud"> MongoDB CRUD Operations </a> in the MongoDB manual. </p> </section> </div> </div> <div class="css-vq8pj5 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-18jxsvu e1ckbxcu2"> 4 </div> </div> <div class="css-clrhqf"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Model your data <a class="headerlink leafygreen-ui-1kepx47" href="#model-your-data" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="model-your-data"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Design your data schema to support frequent access patterns. You can update or enforce your schema at any point. </p> <p class="leafygreen-ui-1kp3ins"> To learn more, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/#std-label-manual-data-modeling-intro"> Data Modeling Introduction </a> in the MongoDB manual. </p> </section> </div> </div> </div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"➜ atlas setup\n? Do you want to setup your Atlas database with default settings? (Y/n)\n➜ Y\n\nWe are deploying Cluster9876543...\nPlease store your database authentication access details in a secure location.\nDatabase User Username: Cluster9876543\nDatabase User Password: abcdef12345\nCreating your cluster... [Its safe to 'Ctrl + C']","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">➜ atlas setup</td></tr><tr class=""><td class="leafygreen-ui-7razhx">? <span class="lg-highlight-title lg-highlight-class">Do</span> you want to setup your <span class="lg-highlight-title lg-highlight-class">Atlas</span> database <span class="lg-highlight-keyword">with</span> <span class="lg-highlight-keyword">default</span> settings<!-- -->? <!-- -->(<!-- -->Y<!-- -->/<!-- -->n)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">➜ Y</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">We</span> are deploying <span class="lg-highlight-title lg-highlight-class">Cluster9876543</span>...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Please</span> store your database authentication access details <span class="lg-highlight-keyword">in</span> a secure location.</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Database</span> <span class="lg-highlight-title lg-highlight-class">User</span> <span class="lg-highlight-title lg-highlight-class">Username</span>: <span class="lg-highlight-title lg-highlight-class">Cluster9876543</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Database</span> <span class="lg-highlight-title lg-highlight-class">User</span> <span class="lg-highlight-title lg-highlight-class">Password</span>: <!-- -->abcdef12345</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Creating</span> your cluster<!-- -->...<!-- --> <!-- -->[<span class="lg-highlight-title lg-highlight-class">Its</span> safe to <span class="lg-highlight-string">'Ctrl + C'</span>]</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel"> <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0"> <div class="leafygreen-ui-xhlipt"> <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16"> <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd"> </path> </svg> </div> </button> </div> </div> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_f91did36n" class="leafygreen-ui-38lglc" id="_7iplyxvvh" role="tabpanel"> <div class="leafygreen-ui-5xwxvr"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Import data from a CSV or JSON file with database tools.To learn more, see\nMigrate or Import Data in the MongoDB Atlas\ndocumentation and mongoimport in the database tools documentation.","name":"Import your data"},{"@type":"HowToStep","text":"Use aggregation pipelines to process your data in multiple\nstages and return the computed results. You can\npreview the results at each pipeline stage when you\nrun aggregation pipelines in MongoDB Atlas.To learn more, see Run Aggregation Pipelines in the MongoDB Atlas documentation\nand Aggregation Operations in the MongoDB manual.","name":"Aggregate your data"}],"name":"Work with your data in MongoDB - Transform data with Aggregations","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-qum8nr eccljxs0"> <div class="css-vq8pj5 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-18jxsvu e1ckbxcu2"> 1 </div> </div> <div class="css-clrhqf"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Import your data <a class="headerlink leafygreen-ui-1kepx47" href="#import-your-data" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="import-your-data"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Import data from a CSV or JSON file with database tools. </p> <p class="leafygreen-ui-1kp3ins"> To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/import/" target="_self"> <span> Migrate or Import Data </span> </a> in the MongoDB Atlas documentation and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/" target="_self"> <span> mongoimport </span> </a> in the database tools documentation. </p> </section> </div> </div> <div class="css-vq8pj5 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-18jxsvu e1ckbxcu2"> 2 </div> </div> <div class="css-clrhqf"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Aggregate your data <a class="headerlink leafygreen-ui-1kepx47" href="#aggregate-your-data" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="aggregate-your-data"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Use aggregation pipelines to process your data in multiple stages and return the computed results. You can preview the results at each pipeline stage when you run aggregation pipelines in MongoDB Atlas. </p> <p class="leafygreen-ui-1kp3ins"> To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/agg-pipeline/" target="_self"> <span> Run Aggregation Pipelines </span> </a> in the MongoDB Atlas documentation and <a class="leafygreen-ui-tqgtui" href="/docs/manual/aggregation/#std-label-aggregation"> Aggregation Operations </a> in the MongoDB manual. </p> </section> </div> </div> </div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"test&gt; db.orders.insertMany([\n { \"item\" : \"almonds\", \"price\" : 12, \"quantity\" : 2 },\n { \"item\" : \"pecans\", \"price\" : 20, \"quantity\" : 1 },\n])\n\ntest&gt; db.inventory.insertMany([\n { \"sku\" : \"almonds\", \"description\": \"product 1\", \"instock\" : 120 },\n { \"sku\" : \"cashews\", \"description\": \"product 3\", \"instock\" : 60 },\n { \"sku\" : \"pecans\", \"description\": \"product 4\", \"instock\" : 70 }\n])\n\ntest&gt; db.orders.aggregate([\n { $match: { price: { $lt: 15 } } },\n { $lookup: {\n from: \"inventory\",\n localField: \"item\",\n foreignField: \"sku\",\n as: \"inventory_docs\"\n } },\n { $sort: { price: 1 } },\n])","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">test<!-- -->&gt; <!-- -->db.<span class="lg-highlight-property">orders</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"almonds"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">12</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"pecans"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">test<!-- -->&gt; <!-- -->db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-string">"almonds"</span>, <span class="lg-highlight-string">"description"</span>: <span class="lg-highlight-string">"product 1"</span>, <span class="lg-highlight-string">"instock"</span> <!-- -->: <span class="lg-highlight-number">120</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-string">"cashews"</span>, <span class="lg-highlight-string">"description"</span>: <span class="lg-highlight-string">"product 3"</span>, <span class="lg-highlight-string">"instock"</span> <!-- -->: <span class="lg-highlight-number">60</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-string">"pecans"</span>, <span class="lg-highlight-string">"description"</span>: <span class="lg-highlight-string">"product 4"</span>, <span class="lg-highlight-string">"instock"</span> <!-- -->: <span class="lg-highlight-number">70</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">test<!-- -->&gt; <!-- -->db.<span class="lg-highlight-property">orders</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-attr">price</span>: <!-- -->{ <span class="lg-highlight-attr">$lt</span>: <span class="lg-highlight-number">15</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$lookup</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">from</span>: <span class="lg-highlight-string">"inventory"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">localField</span>: <span class="lg-highlight-string">"item"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">foreignField</span>: <span class="lg-highlight-string">"sku"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">as</span>: <span class="lg-highlight-string">"inventory_docs"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">1</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel"> <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0"> <div class="leafygreen-ui-xhlipt"> <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16"> <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd"> </path> </svg> </div> </button> </div> </div> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_qs5evp70q" class="leafygreen-ui-38lglc" id="_hzdo61hok" role="tabpanel"> <div class="leafygreen-ui-5xwxvr"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Verify the identity of a user, replica set member, or\nsharded cluster member with authentication.To learn more, see Atlas UI Authenication in the MongoDB Atlas documentation\nand Authentication in the MongoDB\nmanual.","name":"Authenticate a client"},{"@type":"HowToStep","text":"Enable Role-Based Access Controls to manage user privileges\non your entire database cluster or individual collections.To learn more, see Atlas UI Authorization in the MongoDB Atlas documentation\nand Role-Based Access Controls\nin the MongoDB manual.","name":"Control access to your database"},{"@type":"HowToStep","text":"Client-Side Field Level Encryption protects data while it is\nin-use by the database. Fields are encrypted before they\nleave your application, protecting them over the network, in\nmemory and at rest.To learn more, see Client-Side Field Level Encryption in the MongoDB manual.","name":"Encrypt your most sensitive data"}],"name":"Work with your data in MongoDB - Secure access to your data","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-qum8nr eccljxs0"> <div class="css-vq8pj5 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-18jxsvu e1ckbxcu2"> 1 </div> </div> <div class="css-clrhqf"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Authenticate a client <a class="headerlink leafygreen-ui-1kepx47" href="#authenticate-a-client" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="authenticate-a-client"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Verify the identity of a user, replica set member, or sharded cluster member with authentication. </p> <p class="leafygreen-ui-1kp3ins"> To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui-authentication/" target="_self"> <span> Atlas UI Authenication </span> </a> in the MongoDB Atlas documentation and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication"> Authentication </a> in the MongoDB manual. </p> </section> </div> </div> <div class="css-vq8pj5 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-18jxsvu e1ckbxcu2"> 2 </div> </div> <div class="css-clrhqf"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Control access to your database <a class="headerlink leafygreen-ui-1kepx47" href="#control-access-to-your-database" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="control-access-to-your-database"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Enable Role-Based Access Controls to manage user privileges on your entire database cluster or individual collections. </p> <p class="leafygreen-ui-1kp3ins"> To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui-authorization/" target="_self"> <span> Atlas UI Authorization </span> </a> in the MongoDB Atlas documentation and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization"> Role-Based Access Controls </a> in the MongoDB manual. </p> </section> </div> </div> <div class="css-vq8pj5 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-18jxsvu e1ckbxcu2"> 3 </div> </div> <div class="css-clrhqf"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Encrypt your most sensitive data <a class="headerlink leafygreen-ui-1kepx47" href="#encrypt-your-most-sensitive-data" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="encrypt-your-most-sensitive-data"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Client-Side Field Level Encryption protects data while it is in-use by the database. Fields are encrypted before they leave your application, protecting them over the network, in memory and at rest. </p> <p class="leafygreen-ui-1kp3ins"> To learn more, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/#std-label-manual-csfle-feature"> Client-Side Field Level Encryption </a> in the MongoDB manual. </p> </section> </div> </div> </div> <img alt="MongoDB Security" class="leafygreen-ui-1qnf57e" height="327.8" src="/docs/manual/images/security.bakedsvg.svg" style="--border-color:#C1C7C6" width="361"/> </div> </div> </div> <div> <div aria-labelledby="_za5y2gpsv" class="leafygreen-ui-38lglc" id="_nrqftuj0x" role="tabpanel"> <div class="leafygreen-ui-5xwxvr"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create a free cluster, an auto-scaling cluster, or a\nserverless instance in the MongoDB Atlas UI. To learn\nmore, see\nChoose a Cluster Type in the MongoDB Atlas\ndocumentation.For self-hosted deployments, provide redundancy and\nresilience for your database by deploying a replica set. To\nlearn more, see Replication in the\nMongoDB manual.","name":"Create a cluster"},{"@type":"HowToStep","text":"Use sharding to horizontally scale your database or to\nensure location-based separation of data.To learn more, see Shard a Collection in the MongoDB Atlas\ndocumentation and Sharding\nin the MongoDB manual.","name":"Scale out your database"}],"name":"Work with your data in MongoDB - Deploy and scale your database","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-qum8nr eccljxs0"> <div class="css-vq8pj5 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-18jxsvu e1ckbxcu2"> 1 </div> </div> <div class="css-clrhqf"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create a cluster <a class="headerlink leafygreen-ui-1kepx47" href="#create-a-cluster" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="create-a-cluster"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Create a free cluster, an auto-scaling cluster, or a serverless instance in the MongoDB Atlas UI. To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/create-database-deployment/#std-label-ref-deployment-types" target="_self"> <span> Choose a Cluster Type </span> </a> in the MongoDB Atlas documentation. </p> <p class="leafygreen-ui-1kp3ins"> For self-hosted deployments, provide redundancy and resilience for your database by deploying a replica set. To learn more, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/#std-label-replication"> Replication </a> in the MongoDB manual. </p> </section> </div> </div> <div class="css-vq8pj5 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-18jxsvu e1ckbxcu2"> 2 </div> </div> <div class="css-clrhqf"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Scale out your database <a class="headerlink leafygreen-ui-1kepx47" href="#scale-out-your-database" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="scale-out-your-database"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Use sharding to horizontally scale your database or to ensure location-based separation of data. </p> <p class="leafygreen-ui-1kp3ins"> To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/collections/#shard-a-collection" target="_self"> <span> Shard a Collection </span> </a> in the MongoDB Atlas documentation and <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/#std-label-sharding-introduction"> Sharding </a> in the MongoDB manual. </p> </section> </div> </div> </div> <img alt="MongoDB Deploy and Scale" class="leafygreen-ui-1qnf57e" height="327.8" src="/docs/manual/images/scaling.bakedsvg.svg" style="--border-color:#C1C7C6" width="387"/> </div> </div> </div> </div> </div> <div class="leafygreen-ui-xvo2tu"> Related Products &amp; Resources </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Go Further with MongoDB <a class="headerlink leafygreen-ui-1kepx47" href="#go-further-with-mongodb" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="go-further-with-mongodb"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Explore libraries and tools for MongoDB. </p> <div class="card-group css-1yg8enk ejknxgy0"> <div class="leafygreen-ui-godkom"> <img alt="MongoDB Atlas icon" class="" height="32px" src="https://webimages.mongodb.com/_com_assets/icons/atlas_drivers.svg" width="32px"/> <div class="css-lh5e7u e1s2l6cq0"> <div> <p class="leafygreen-ui-1kp3ins"> Use MongoDB in your application's language </p> <p class="leafygreen-ui-t6hkhy"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> Learn about Drivers </span> </a> </p> </div> </div> </div> <div class="leafygreen-ui-godkom"> <img alt="MongoDB University icon" class="" height="32px" src="https://webimages.mongodb.com/_com_assets/icons/mdb_compass.svg" width="32px"/> <div class="css-lh5e7u e1s2l6cq0"> <div> <p class="leafygreen-ui-1kp3ins"> Visually explore your data with MongoDB Compass </p> <p class="leafygreen-ui-t6hkhy"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/compass/current/" target="_self"> <span> View Compass Docs </span> </a> </p> </div> </div> </div> <div class="leafygreen-ui-godkom"> <img alt="MongoDB Server icon" class="" height="32px" src="https://webimages.mongodb.com/_com_assets/icons/mdb_ops_manager.svg" width="32px"/> <div class="css-lh5e7u e1s2l6cq0"> <div> <p class="leafygreen-ui-1kp3ins"> Manage and monitor your deployments </p> <p class="leafygreen-ui-t6hkhy"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/ops-manager/current/" target="_self"> <span> View Ops Manager </span> </a> </p> </div> </div> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/sharding/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Sharding <a class="headerlink leafygreen-ui-1kepx47" href="#sharding" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="sharding"> </div> </a> </h1> <div class="leafygreen-ui-a5yxub"> <p class="css-1cmx2d4 ef7gu8j0"> On this page </p> <ul class="css-1qb0mst ef7gu8j1"> <li class="leafygreen-ui-1e7a0ei"> <a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#sharded-cluster" target="_self"> <span> Sharded Cluster </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#shard-keys" target="_self"> <span> Shard Keys </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#chunks" target="_self"> <span> Chunks </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#balancer-and-even-data-distribution" target="_self"> <span> Balancer and Even Data Distribution </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#advantages-of-sharding" target="_self"> <span> Advantages of Sharding </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations-before-sharding" target="_self"> <span> Considerations Before Sharding </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#sharded-and-non-sharded-collections" target="_self"> <span> Sharded and Non-Sharded Collections </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#connecting-to-a-sharded-cluster" target="_self"> <span> Connecting to a Sharded Cluster </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#sharding-strategy" target="_self"> <span> Sharding Strategy </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#zones-in-sharded-clusters" target="_self"> <span> Zones in Sharded Clusters </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#collations-in-sharding" target="_self"> <span> Collations in Sharding </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#change-streams" target="_self"> <span> Change Streams </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#transactions" target="_self"> <span> Transactions </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self"> <span> Learn More </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharding"> Sharding </a> is a method for distributing data across multiple machines. MongoDB uses sharding to support deployments with very large data sets and high throughput operations. </p> <p class="leafygreen-ui-1kp3ins"> Database systems with large data sets or high throughput applications can challenge the capacity of a single server. For example, high query rates can exhaust the CPU capacity of the server. Working set sizes larger than the system's RAM stress the I/O capacity of disk drives. </p> <p class="leafygreen-ui-1kp3ins"> There are two methods for addressing system growth: vertical and horizontal scaling. </p> <p class="leafygreen-ui-1kp3ins"> <em> Vertical Scaling </em> involves increasing the capacity of a single server, such as using a more powerful CPU, adding more RAM, or increasing the amount of storage space. Limitations in available technology may restrict a single machine from being sufficiently powerful for a given workload. Additionally, Cloud-based providers have hard ceilings based on available hardware configurations. As a result, there is a practical maximum for vertical scaling. </p> <p class="leafygreen-ui-1kp3ins"> <em> Horizontal Scaling </em> involves dividing the system dataset and load over multiple servers, adding additional servers to increase capacity as required. While the overall speed or capacity of a single machine may not be high, each machine handles a subset of the overall workload, potentially providing better efficiency than a single high-speed high-capacity server. Expanding the capacity of the deployment only requires adding additional servers as needed, which can be a lower overall cost than high-end hardware for a single machine. The trade off is increased complexity in infrastructure and maintenance for the deployment. </p> <p class="leafygreen-ui-1kp3ins"> MongoDB supports <em> horizontal scaling </em> through <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharding"> sharding. </a> </p> <a class="css-53dzkk" href="https://www.mongodb.com/docs/atlas/atlas-ui/collections/#shard-a-collection"> <div class="css-z0l49d"> <div class="css-fw7ipj"> <svg aria-label="Cloud Icon" class="leafygreen-ui-1t2jgtk" fill="none" height="16" role="img" viewbox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"> <path d="M12.571 8.143c0 1.775-.899 3.34-2.267 4.264l-.014.01a5.12 5.12 0 0 1-2.861.869H2.857a2.857 2.857 0 0 1-.545-5.663 5.144 5.144 0 0 1 10.26.52ZM13.821 8.143a6.38 6.38 0 0 1-2.358 4.96 3.429 3.429 0 1 0 2.17-6.506c.123.494.188 1.013.188 1.546Z" fill="currentColor"> </path> </svg> </div> <p class="leafygreen-ui-1kp3ins"> You can <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/collections/#shard-a-collection" target="_self"> <span> shard collections in the UI </span> </a> for deployments hosted in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self"> <span> MongoDB Atlas. </span> </a> </p> </div> </a> <span class="leafygreen-ui-1qnjd6d" id="std-label-sharded-cluster"> </span> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Sharded Cluster <a class="headerlink leafygreen-ui-1kepx47" href="#sharded-cluster" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="sharded-cluster"> </div> </a> </h2> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> A MongoDB <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster </a> consists of the following components: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-shards/#std-label-shards-concepts"> shard </a> : Each shard contains a subset of the sharded data. Each shard must be deployed as a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set"> replica set. </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/"> mongos </a> : The <code class="leafygreen-ui-1l06pbn"> mongos </code> acts as a query router, providing an interface between client applications and the sharded cluster. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-config-servers/#std-label-sharding-config-server"> config servers </a> : Config servers store metadata and configuration settings for the cluster. Config servers must be deployed as a replica set (CSRS). </p> </li> </ul> </div> </div> <p class="leafygreen-ui-1kp3ins"> The following graphic describes the interaction of components within a sharded cluster: </p> <div class="figure css-5vkxs0" style="width: 600px;"> <img alt="Diagram of a sample sharded cluster for production purposes. Contains exactly 3 config servers, 2 or more ``mongos`` query routers, and at least 2 shards. The shards are replica sets." class="leafygreen-ui-1qnf57e" height="440" src="/docs/manual/images/sharded-cluster-production-architecture.bakedsvg.svg" style="--border-color: #C1C7C6;" width="620"/> </div> <p class="leafygreen-ui-1kp3ins"> MongoDB shards data at the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-collection"> collection </a> level, distributing the collection data across the shards in the cluster. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Shard Keys <a class="headerlink leafygreen-ui-1kepx47" href="#shard-keys" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="shard-keys"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key"> shard key </a> to distribute the collection's documents across shards. The shard key consists of a field or multiple fields in the documents. </p> <p class="leafygreen-ui-1kp3ins"> Documents in sharded collections can be missing the shard key fields. Missing shard key fields are treated as having null values when distributing the documents across shards but not when routing queries. For more information, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key-missing"> Missing Shard Key Fields. </a> </p> <p class="leafygreen-ui-1kp3ins"> You select the shard key when <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-a-collection/#std-label-sharding-shard-key-creation"> sharding a collection. </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, you can <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> reshard a collection </a> by changing a collection's shard key. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You can <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-refine-a-shard-key/#std-label-shard-key-refine"> refine a shard key </a> by adding a suffix field or fields to the existing shard key. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> A document's shard key value determines its distribution across the shards. You can update a document's shard key value unless your shard key field is the immutable <code class="leafygreen-ui-1l06pbn"> _id </code> field. For more information, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-change-shard-key-value/#std-label-update-shard-key"> Change a Document's Shard Key Value. </a> </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Shard Key Index <a class="headerlink leafygreen-ui-1kepx47" href="#shard-key-index" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="shard-key-index"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To shard a populated collection, the collection must have an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-index"> index </a> that starts with the shard key. When sharding an empty collection, MongoDB creates the supporting index if the collection does not already have an appropriate index for the specified shard key. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key-indexes"> Shard Key Indexes. </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Shard Key Strategy <a class="headerlink leafygreen-ui-1kepx47" href="#shard-key-strategy" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="shard-key-strategy"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The choice of shard key affects the performance, efficiency, and scalability of a sharded cluster. A cluster with the best possible hardware and infrastructure can be bottlenecked by the choice of shard key. The choice of shard key and its backing index can also affect the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-strategy" target="_self"> <span> sharding strategy </span> </a> that your cluster can use. </p> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> See also: </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-shard-key-selection"> Choose a Shard Key </a> </p> </div> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Chunks <a class="headerlink leafygreen-ui-1kepx47" href="#chunks" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="chunks"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB partitions sharded data into <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk"> chunks </a> . Each chunk has an inclusive lower and exclusive upper range based on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key. </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Balancer and Even Data Distribution <a class="headerlink leafygreen-ui-1kepx47" href="#balancer-and-even-data-distribution" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="balancer-and-even-data-distribution"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> In an attempt to achieve an even distribution of data across all shards in the cluster, a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing"> balancer </a> runs in the background to migrate <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-range"> ranges </a> across the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard"> shards. </a> </p> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> See also: </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-range-migration"> Range Migration </a> </p> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Advantages of Sharding <a class="headerlink leafygreen-ui-1kepx47" href="#advantages-of-sharding" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="advantages-of-sharding"> </div> </a> </h2> <span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-shard-key-write-scaling"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Reads / Writes <a class="headerlink leafygreen-ui-1kepx47" href="#reads---writes" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="reads---writes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB distributes the read and write workload across the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard"> shards </a> in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster </a> , allowing each shard to process a subset of cluster operations. Both read and write workloads can be scaled horizontally across the cluster by adding more shards. </p> <p class="leafygreen-ui-1kp3ins"> For queries that include the shard key or the prefix of a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-compound-index"> compound </a> shard key, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> can target the query at a specific shard or set of shards. These <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-sharding-mongos-targeted"> targeted operations </a> are generally more efficient than <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-sharding-mongos-broadcast"> broadcasting </a> to every shard in the cluster. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Storage Capacity <a class="headerlink leafygreen-ui-1kepx47" href="#storage-capacity" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="storage-capacity"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharding"> Sharding </a> distributes data across the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard"> shards </a> in the cluster, allowing each shard to contain a subset of the total cluster data. As the data set grows, additional shards increase the storage capacity of the cluster. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-availability"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> High Availability <a class="headerlink leafygreen-ui-1kepx47" href="#high-availability" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="high-availability"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The deployment of config servers and shards as replica sets provide increased availability. </p> <p class="leafygreen-ui-1kp3ins"> Even if one or more shard replica sets become completely unavailable, the sharded cluster can continue to perform partial reads and writes. That is, while data on the unavailable shard(s) cannot be accessed, reads or writes directed at the available shards can still succeed. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations Before Sharding <a class="headerlink leafygreen-ui-1kepx47" href="#considerations-before-sharding" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="considerations-before-sharding"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Sharded cluster infrastructure requirements and complexity require careful planning, execution, and maintenance. </p> <p class="leafygreen-ui-1kp3ins"> While you can <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> reshard your collection </a> later, it is important to carefully consider your shard key choice to avoid scalability and performance issues. </p> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> See also: </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-shard-key-selection"> Choose a Shard Key </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> To understand the operational requirements and restrictions for sharding your collection, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-requirements/"> Operational Restrictions in Sharded Clusters. </a> </p> <p class="leafygreen-ui-1kp3ins"> If queries do <em> not </em> include the shard key or the prefix of a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-compound-index"> compound </a> shard key, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> performs a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-sharding-mongos-broadcast"> broadcast operation </a> , querying <em> all </em> shards in the sharded cluster. These scatter/gather queries can be long running operations. </p> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.1, when starting, restarting or adding a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-components/#std-label-sharding-shards"> shard server </a> with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShard/#mongodb-method-sh.addShard"> <code class="leafygreen-ui-1l06pbn"> sh.addShard() </code> </a> the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#std-label-set_global_default_write_concern"> Cluster Wide Write Concern (CWWC) </a> must be set. </p> <p class="leafygreen-ui-1kp3ins"> If the <code class="leafygreen-ui-1l06pbn"> CWWC </code> is not set and the shard is configured such that the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern"> default write concern </a> is <code class="leafygreen-ui-1l06pbn"> { w : 1 } </code> the shard server will fail to start or be added and returns an error. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-defaults/#std-label-default-wc-formula"> default write concern calculations </a> for details on how the default write concern is calculated. </p> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> If you have an active support contract with MongoDB, consider contacting your account representative for assistance with sharded cluster planning and deployment. </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-sharded-vs-non-sharded-collections"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Sharded and Non-Sharded Collections <a class="headerlink leafygreen-ui-1kepx47" href="#sharded-and-non-sharded-collections" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="sharded-and-non-sharded-collections"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> A database can have a mixture of sharded and unsharded collections. Sharded collections are <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-data-partition"> partitioned </a> and distributed across the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard"> shards </a> in the cluster. Unsharded collections can be located on any shard but cannot span across shards. </p> <div class="figure css-5vkxs0" style="width: 400px;"> <img alt="Diagram of a primary shard. A primary shard contains non-sharded collections as well as chunks of documents from sharded collections. Shard A is the primary shard." class="leafygreen-ui-1qnf57e" height="360" src="/docs/manual/images/sharded-cluster-primary-shard.bakedsvg.svg" style="--border-color: #C1C7C6;" width="330"/> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Connecting to a Sharded Cluster <a class="headerlink leafygreen-ui-1kepx47" href="#connecting-to-a-sharded-cluster" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="connecting-to-a-sharded-cluster"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> You must connect to a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-mongos"> mongos </a> router to interact with any collection in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster </a> . This includes sharded <em> and </em> unsharded collections. Clients should <em> never </em> connect to a single shard in order to perform read or write operations. </p> <div class="figure css-5vkxs0" style="width: 700px;"> <img alt="Diagram of applications/drivers issuing queries to mongos for unsharded collection as well as sharded collection. Config servers not shown." class="leafygreen-ui-1qnf57e" height="360" src="/docs/manual/images/sharded-cluster-mixed.bakedsvg.svg" style="--border-color: #C1C7C6;" width="680"/> </div> <p class="leafygreen-ui-1kp3ins"> You can connect to a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> the same way you connect to a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> using the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongosh </code> </span> </a> or a MongoDB <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/?jump=docs" target="_self"> <span> driver. </span> </a> </p> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 8.0, you can only run <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/supported-shard-direct-commands/#std-label-shard-direct-commands"> certain commands </a> on shards. If you attempt to connect directly to a shard and run an unsupported command, MongoDB returns an error: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"You are connecting to a sharded cluster improperly by connecting directly\nto a shard. Please connect to the cluster via a router (mongos).\""} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">"You are connecting to a sharded cluster improperly by connecting directly</td></tr><tr class=""><td class="leafygreen-ui-7razhx">to a shard. Please connect to the cluster via a router (mongos)."</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel"> <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0"> <div class="leafygreen-ui-xhlipt"> <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16"> <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd"> </path> </svg> </div> </button> </div> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> To run a non-supported database command directly against a shard, you must either connect to <code class="leafygreen-ui-1l06pbn"> mongos </code> or have the maintenance-only <code class="leafygreen-ui-1l06pbn"> directShardOperations </code> role. </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-strategy"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Sharding Strategy <a class="headerlink leafygreen-ui-1kepx47" href="#sharding-strategy" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="sharding-strategy"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB supports two sharding strategies for distributing data across <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded clusters. </a> </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Hashed Sharding <a class="headerlink leafygreen-ui-1kepx47" href="#hashed-sharding" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="hashed-sharding"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Hashed Sharding involves computing a hash of the shard key field's value. Each <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk"> chunk </a> is then assigned a range based on the hashed shard key values. </p> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> MongoDB automatically computes the hashes when resolving queries using hashed indexes. Applications do <strong> not </strong> need to compute hashes. </p> </div> </div> <div class="figure css-5vkxs0" style="width: 700px;"> <img alt="Diagram of the hashed based segmentation." class="leafygreen-ui-1qnf57e" height="250" src="/docs/manual/images/sharding-hash-based.bakedsvg.svg" style="--border-color: #C1C7C6;" width="700"/> </div> <p class="leafygreen-ui-1kp3ins"> While a range of shard keys may be "close", their hashed values are unlikely to be on the same <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk"> chunk </a> . Data distribution based on hashed values facilitates more even data distribution, especially in data sets where the shard key changes <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-monotonic"> monotonically. </a> </p> <p class="leafygreen-ui-1kp3ins"> However, hashed distribution means that range-based queries on the shard key are less likely to target a single shard, resulting in more cluster wide <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-sharding-mongos-broadcast"> broadcast operations </a> </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/"> Hashed Sharding </a> for more information. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Ranged Sharding <a class="headerlink leafygreen-ui-1kepx47" href="#ranged-sharding" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="ranged-sharding"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Ranged sharding involves dividing data into ranges based on the shard key values. Each <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk"> chunk </a> is then assigned a range based on the shard key values. </p> <div class="figure css-5vkxs0" style="width: 700px;"> <img alt="Diagram of the shard key value space segmented into smaller ranges or chunks." class="leafygreen-ui-1qnf57e" height="250" src="/docs/manual/images/sharding-range-based.bakedsvg.svg" style="--border-color: #C1C7C6;" width="760"/> </div> <p class="leafygreen-ui-1kp3ins"> A range of shard keys whose values are "close" are more likely to reside on the same <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk"> chunk </a> . This allows for <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-sharding-mongos-targeted"> targeted operations </a> as a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> can route the operations to only the shards that contain the required data. </p> <p class="leafygreen-ui-1kp3ins"> The efficiency of ranged sharding depends on the shard key chosen. Poorly considered shard keys can result in uneven distribution of data, which can negate some benefits of sharding or can cause performance bottlenecks. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/ranged-sharding/#std-label-sharding-ranged-shard-key"> shard key selection for range-based sharding. </a> </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/ranged-sharding/"> Ranged Sharding </a> for more information. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-zone-sharding"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Zones in Sharded Clusters <a class="headerlink leafygreen-ui-1kepx47" href="#zones-in-sharded-clusters" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="zones-in-sharded-clusters"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Zones can help improve the locality of data for sharded clusters that span multiple data centers. </p> <p class="leafygreen-ui-1kp3ins"> In sharded clusters, you can create <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zone"> zones </a> of sharded data based on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> . You can associate each zone with one or more shards in the cluster. A shard can associate with any number of zones. In a balanced cluster, MongoDB migrates <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk"> chunks </a> covered by a zone only to those shards associated with the zone. </p> <p class="leafygreen-ui-1kp3ins"> Each zone covers one or more ranges of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> values. Each range a zone covers is always inclusive of its lower boundary and exclusive of its upper boundary. </p> <div class="css-y1v7l ej97su30"> <div role="button" tabindex="-1"> <img alt="Diagram of data distribution based on zones in a sharded cluster" class="leafygreen-ui-1qnf57e" height="600" src="/docs/manual/images/sharded-cluster-zones.bakedsvg.svg" style="--border-color: #C1C7C6;" width="1200"/> <div class="css-19pi7x2 ej97su31" style="--color: #444;"> click to enlarge </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> You must use fields contained in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> when defining a new range for a zone to cover. If using a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-compound-index"> compound </a> shard key, the range must include the prefix of the shard key. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding-shard-key"> shard keys in zones </a> for more information. </p> <p class="leafygreen-ui-1kp3ins"> The possible use of zones in the future should be taken into consideration when choosing a shard key. </p> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Setting up zones and zone ranges <em> before </em> you shard an empty or a non-existing collection allows for a faster setup of zoned sharding. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding"> zones </a> for more information. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Collations in Sharding <a class="headerlink leafygreen-ui-1kepx47" href="#collations-in-sharding" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="collations-in-sharding"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/shardCollection/#mongodb-dbcommand-dbcmd.shardCollection"> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </a> command with the <code class="leafygreen-ui-1l06pbn"> collation : { locale : "simple" } </code> option to shard a collection which has a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> default collation </a> . Successful sharding requires that: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The collection must have an index whose prefix is the shard key </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The index must have the collation <code class="leafygreen-ui-1l06pbn"> { locale: "simple" } </code> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> When creating new collections with a collation, ensure these conditions are met prior to sharding the collection. </p> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Queries on the sharded collection continue to use the default collation configured for the collection. To use the shard key index's <code class="leafygreen-ui-1l06pbn"> simple </code> collation, specify <code class="leafygreen-ui-1l06pbn"> {locale : "simple"} </code> in the query's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> collation document. </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/shardCollection/#mongodb-dbcommand-dbcmd.shardCollection"> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </a> for more information about sharding and collation. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Change Streams <a class="headerlink leafygreen-ui-1kepx47" href="#change-streams" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="change-streams"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams"> Change streams </a> are available for replica sets and sharded clusters. Change streams allow applications to access real-time data changes without the complexity and risk of tailing the oplog. Applications can use change streams to subscribe to all data changes on a collection or collections. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Transactions <a class="headerlink leafygreen-ui-1kepx47" href="#transactions" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="transactions"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> With the introduction of <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> distributed transactions </a> , multi-document transactions are available on sharded clusters. </p> <p class="leafygreen-ui-1kp3ins"> Until a transaction commits, the data changes made in the transaction are not visible outside the transaction. </p> <p class="leafygreen-ui-1kp3ins"> However, when a transaction writes to multiple shards, not all outside read operations need to wait for the result of the committed transaction to be visible across the shards. For example, if a transaction is committed and write 1 is visible on shard A but write 2 is not yet visible on shard B, an outside read at read concern <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-"> <code class="leafygreen-ui-1l06pbn"> "local" </code> </a> can read the results of write 1 without seeing write 2. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Learn More <a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="learn-more"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Practical MongoDB Aggregations E-Book <a class="headerlink leafygreen-ui-1kepx47" href="#practical-mongodb-aggregations-e-book" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="practical-mongodb-aggregations-e-book"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> For more information on how sharding works with <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregations </a> , read the sharding chapter in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.practical-mongodb-aggregations.com/guides/sharding.html" rel="noopener noreferrer"> <span> Practical MongoDB Aggregations </span> <svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor"> </path> <path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor"> </path> </svg> </a> e-book. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Additional Information <a class="headerlink leafygreen-ui-1kepx47" href="#additional-information" title="Permalink to this heading"> <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg"> <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor"> </path> <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor"> </path> </svg> <div class="css-1btu0w3 evvkmar0" id="additional-information"> </div> </a> </h3> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/"> Transactions </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-production-consideration/"> Production Considerations </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-sharded-clusters/"> Production Considerations (Sharded Clusters) </a> </p> </li> </ul> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/shardCollection/
"<section>\n <h1 class=\"contains-headerlink leafygreen-ui-41fr9s\" weight=\"medium\">\n shardColle(...TRUNCATED)
https://www.mongodb.com/docs/manual/reference/command/nav-crud/
"<section>\n <h1 class=\"contains-headerlink leafygreen-ui-41fr9s\" weight=\"medium\">\n Query and (...TRUNCATED)
https://www.mongodb.com/docs/manual/reference/command/balancerStop/
"<section>\n <h1 class=\"contains-headerlink leafygreen-ui-41fr9s\" weight=\"medium\">\n balancerSt(...TRUNCATED)
https://www.mongodb.com/docs/manual/reference/command/transitionFromDedicatedConfigServer/
"<section>\n <h1 class=\"contains-headerlink leafygreen-ui-41fr9s\" weight=\"medium\">\n transition(...TRUNCATED)
https://www.mongodb.com/docs/manual/reference/command/cleanupOrphaned/
"<section>\n <h1 class=\"contains-headerlink leafygreen-ui-41fr9s\" weight=\"medium\">\n cleanupOrp(...TRUNCATED)
https://www.mongodb.com/docs/manual/reference/command/setAllowMigrations/
"<section>\n <h1 class=\"contains-headerlink leafygreen-ui-41fr9s\" weight=\"medium\">\n setAllowMi(...TRUNCATED)
https://www.mongodb.com/docs/manual/reference/command/findAndModify/
"<section>\n <h1 class=\"contains-headerlink leafygreen-ui-41fr9s\" weight=\"medium\">\n findAndMod(...TRUNCATED)
https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/
"<section>\n <h1 class=\"contains-headerlink leafygreen-ui-41fr9s\" weight=\"medium\">\n $unset (ag(...TRUNCATED)

Dataset Card for "mongo_manual_8_0_en"

More Information needed

Downloads last month
15
Edit dataset card