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> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> shardCollection <a class="headerlink leafygreen-ui-1kepx47" href="#shardcollection" 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="shardcollection"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self"> <span> Command Fields </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self"> <span> Considerations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="dbcommand"> <dt> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.shardCollection" title="Permalink to this definition"> <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="mongodb-dbcommand-dbcmd.shardCollection"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/#std-label-sharding-background"> Shards </a> a collection to distribute its documents across shards. The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </span> </a> command must be run against the <code class="leafygreen-ui-1l06pbn"> admin </code> database. </p> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <div> <p> <em> Changed <!-- --> in version <!-- --> 6.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 6.0, sharding a collection does <strong> not </strong> require you to first run the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/enableSharding/#mongodb-dbcommand-dbcmd.enableSharding"> <code class="leafygreen-ui-1l06pbn"> enableSharding </code> </a> command to configure the database. </p> </div> </div> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> In <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongosh </code> </span> </a> , this command can also be run through the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection"> <code class="leafygreen-ui-1l06pbn"> sh.shardCollection() </code> </a> helper method <!-- --> . </p> <p class="leafygreen-ui-1kp3ins"> Helper methods are convenient for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongosh </code> </span> </a> users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command. </p> </div> </div> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This command is available in deployments hosted 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> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command is not supported in serverless instances. For more information, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self"> <span> Unsupported Commands <!-- --> . </span> </a> </p> </div> </div> <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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To run <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </span> </a> , use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.runCommand/#mongodb-method-db.runCommand"> <code class="leafygreen-ui-1l06pbn"> db.runCommand( { &lt;command&gt; } ) </code> </a> method. </p> <p class="leafygreen-ui-1kp3ins"> The command has the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n shardCollection: \"&lt;database&gt;.&lt;collection&gt;\",\n key: { &lt;field1&gt;: &lt;1|\"hashed\"&gt;, ... },\n unique: &lt;boolean&gt;,\n numInitialChunks: &lt;integer&gt;,\n presplitHashedZones: &lt;boolean&gt;,\n collation: { locale: \"simple\" },\n timeseries: &lt;object&gt;\n }\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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">shardCollection</span>: <span class="lg-highlight-string">"&lt;database&gt;.&lt;collection&gt;"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ &lt;<!-- -->field1<!-- -->&gt;<!-- -->: <!-- -->&lt;1|"hashed"&gt;, ... },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> unique: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> numInitialChunks: &lt;integer&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> presplitHashedZones: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> collation: { locale: "simple" },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> timeseries: &lt;object&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Command Fields <a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" 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="command-fields"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command takes the following fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace"> namespace </a> of the collection to shard in the form <code class="leafygreen-ui-1l06pbn"> &lt;database&gt;.&lt;collection&gt; </code> . </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> key </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> The document that specifies the field or fields to use as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key"> shard key <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { &lt;field1&gt;: &lt;1|"hashed"&gt;, ... } </code> </p> <p class="leafygreen-ui-1kp3ins"> Set the field values to either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> 1 </code> for <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/ranged-sharding/#std-label-sharding-ranged"> range-based sharding </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "hashed" </code> to specify a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-hashed-shard-keys" target="_self"> <span> hashed shard key <!-- --> . </span> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key"> shard key </a> must be supported by an index. Unless the collection is empty, the index must exist prior to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </span> </a> command. If the collection is empty, MongoDB creates the index prior to sharding the collection if the index that can support the shard key does not already exist. </p> <p class="leafygreen-ui-1kp3ins"> See also <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key-indexes"> Shard Key Indexes </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> unique </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Specify <code class="leafygreen-ui-1l06pbn"> true </code> to ensure that the underlying index enforces a unique constraint. Defaults to <code class="leafygreen-ui-1l06pbn"> false </code> . </p> <p class="leafygreen-ui-1kp3ins"> You cannot specify <code class="leafygreen-ui-1l06pbn"> true </code> when using <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/#std-label-sharding-hashed"> hashed shard keys <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> numInitialChunks </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> integer </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Specifies the initial number of chunks to create across all shards in the cluster when sharding an <em> empty </em> collection with a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/#std-label-sharding-hashed-sharding"> hashed shard key </a> . MongoDB will then create and balance chunks across the cluster. The <code class="leafygreen-ui-1l06pbn"> numInitialChunks </code> must result in less than <code class="leafygreen-ui-1l06pbn"> 8192 </code> per shard. </p> <p class="leafygreen-ui-1kp3ins"> If the collection is not empty or the shard key does not contain a hashed field, the operation returns an error. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If sharding with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-presplitHashedZones" target="_self"> <span> presplitHashedZones: true </span> </a> , MongoDB attempts to evenly distribute the specified number of chunks across the zones in the cluster. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If sharding with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-presplitHashedZones" target="_self"> <span> presplitHashedZones: false </span> </a> or omitted and no zones and zone ranges are defined for the empty collection, MongoDB attempts to evenly distributed the specified number of chunks across the shards in the cluster. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If sharding with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-presplitHashedZones" target="_self"> <span> presplitHashedZones: false </span> </a> or omitted and zones and zone ranges have been defined for the empty collection, <code class="leafygreen-ui-1l06pbn"> numInitialChunks </code> has no effect. </p> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> collation </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Optional. If the collection specified to <code class="leafygreen-ui-1l06pbn"> shardCollection </code> has a default <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> collation </a> , you <em> must </em> include a collation document with <code class="leafygreen-ui-1l06pbn"> { locale : "simple" } </code> , or the <code class="leafygreen-ui-1l06pbn"> shardCollection </code> command fails. At least one of the indexes whose fields support the shard key pattern must have the simple collation. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-presplitHashedZones" target="_self"> <span> presplitHashedZones </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-cmd-shard-collection-presplitHashedZones"> </span> <p class="leafygreen-ui-1kp3ins"> Optional. Specify <code class="leafygreen-ui-1l06pbn"> true </code> to perform initial chunk creation and distribution for an empty or non-existing collection based on the defined zones and zone ranges for the collection. For <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/#std-label-sharding-hashed"> hashed sharding </a> only. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> with <code class="leafygreen-ui-1l06pbn"> presplitHashedZones: true </code> returns an error if any of the following are true: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The shard key does not contain a hashed field (i.e. is not a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/#std-label-index-hashed-index"> single field hashed index </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed"> compound hashed index </a> ). </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The collection has no defined zones or zone ranges. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The defined zone range or ranges do not meet the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-shardCollection-zones" target="_self"> <span> requirements <!-- --> . </span> </a> </p> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-timeseries" target="_self"> <span> timeseries </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> object </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-cmd-shard-collection-timeseries"> </span> <p class="leafygreen-ui-1kp3ins"> Optional. Specify this option to create a new sharded <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection"> time series collection <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> To shard an existing time series collection, omit this parameter. </p> <p class="leafygreen-ui-1kp3ins"> When the collection specified to <code class="leafygreen-ui-1l06pbn"> shardCollection </code> is a time series collection and the <code class="leafygreen-ui-1l06pbn"> timeseries </code> option is not specified, MongoDB uses the values that define the existing time series collection to populate the <code class="leafygreen-ui-1l06pbn"> timeseries </code> field. </p> <p class="leafygreen-ui-1kp3ins"> For detailed syntax, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-sharded-time-series-collection-options" target="_self"> <span> Time Series Options <!-- --> . </span> </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.1 </em> . </p> </div> </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-cmd-sharded-time-series-collection-options"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Time Series Options <a class="headerlink leafygreen-ui-1kepx47" href="#time-series-options" 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="time-series-options"> </div> </a> </h3> <div> <p> <em> New <!-- --> in version <!-- --> 5.1 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> To create a new <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection"> time series collection </a> that is sharded, specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-timeseries" target="_self"> <span> timeseries </span> </a> option to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-timeseries" target="_self"> <span> timeseries </span> </a> option takes the following fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> timeField </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Required. The name of the field which contains the date in each time series document. Documents in a time series collection must have a valid BSON date as the value for the <code class="leafygreen-ui-1l06pbn"> timeField </code> . </p> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 8.0, use of the <code class="leafygreen-ui-1l06pbn"> timeField </code> as a shard key in a time series collection is deprecated. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> metaField </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. The name of the field which contains metadata in each time series document. The metadata in the specified field should be data that is used to label a unique series of documents. The metadata should rarely, if ever, change The name of the specified field may not be <code class="leafygreen-ui-1l06pbn"> _id </code> or the same as the <code class="leafygreen-ui-1l06pbn"> timeseries.timeField </code> . The field can be of any data type. </p> <p class="leafygreen-ui-1kp3ins"> Although the <code class="leafygreen-ui-1l06pbn"> metaField </code> field is optional, using metadata can improve query optimization. For example, MongoDB automatically <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-secondary-index/#std-label-timeseries-add-secondary-index"> creates a compound index </a> on the <code class="leafygreen-ui-1l06pbn"> metaField </code> and <code class="leafygreen-ui-1l06pbn"> timeField </code> fields for new collections. If you do not provide a value for this field, the data is bucketed solely based on time. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> granularity </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. Possible values are: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "seconds" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "minutes" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "hours" </code> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> By default, MongoDB sets the <code class="leafygreen-ui-1l06pbn"> granularity </code> to <code class="leafygreen-ui-1l06pbn"> "seconds" </code> for high-frequency ingestion. </p> <p class="leafygreen-ui-1kp3ins"> Manually set the <code class="leafygreen-ui-1l06pbn"> granularity </code> parameter to improve performance by optimizing how data in the time series collection is stored internally. To select a value for <code class="leafygreen-ui-1l06pbn"> granularity </code> , choose the closest match to the time span between consecutive incoming measurements. </p> <p class="leafygreen-ui-1kp3ins"> If you specify the <code class="leafygreen-ui-1l06pbn"> timeseries.metaField </code> , consider the time span between consecutive incoming measurements that have the same unique value for the <code class="leafygreen-ui-1l06pbn"> metaField </code> field. Measurements often have the same unique value for the <code class="leafygreen-ui-1l06pbn"> metaField </code> field if they come from the same source. </p> <p class="leafygreen-ui-1kp3ins"> If you do not specify <code class="leafygreen-ui-1l06pbn"> timeseries.metaField </code> , consider the time span between all measurements that are inserted in the collection. </p> <p class="leafygreen-ui-1kp3ins"> If you set the <code class="leafygreen-ui-1l06pbn"> granularity </code> parameter, you can't set the <code class="leafygreen-ui-1l06pbn"> bucketMaxSpanSeconds </code> and <code class="leafygreen-ui-1l06pbn"> bucketRoundingSeconds </code> parameters. </p> </div> </div> </td> </tr> </tbody> </table> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" 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> </h3> <p class="leafygreen-ui-1kp3ins"> While you can <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-change-a-shard-key/#std-label-change-a-shard-key"> change your shard key </a> later, it is important to carefully consider your shard key choice to avoid scalability and perfomance 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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key"> Shard Keys </a> </p> </li> </ul> </div> </div> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Shard Keys on Time Series Collections <a class="headerlink leafygreen-ui-1kepx47" href="#shard-keys-on-time-series-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="shard-keys-on-time-series-collections"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> When sharding time series collections, you can only specify the following fields in the shard key: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> metaField </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Sub-fields of <code class="leafygreen-ui-1l06pbn"> metaField </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> timeField </code> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You may specify combinations of these fields in the shard key. No other fields, including <code class="leafygreen-ui-1l06pbn"> _id </code> , are allowed in the shard key pattern. </p> <p class="leafygreen-ui-1kp3ins"> When you specify the shard key: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> metaField </code> can be either a: </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/hashed-sharding/#std-label-sharding-hashed-sharding"> Hashed shard key </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/ranged-sharding/#std-label-sharding-ranged"> Ranged shard key </a> </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> timeField </code> must be: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/ranged-sharding/#std-label-sharding-ranged"> ranged shard key </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> At the end of the shard key pattern </p> </li> </ul> </li> </ul> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Avoid specifying <strong> only </strong> the <code class="leafygreen-ui-1l06pbn"> timeField </code> as the shard key. Since the <code class="leafygreen-ui-1l06pbn"> timeField </code> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-monotonic"> increases monotonically </a> , it may result in all writes appearing on a single chunk within the cluster. Ideally, data is evenly distributed across chunks. </p> <p class="leafygreen-ui-1kp3ins"> To learn how to best choose a shard key, see: </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/sharding-choose-a-shard-key/#std-label-sharding-shard-key-requirements"> Choose a Shard Key </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/blog/post/on-selecting-a-shard-key-for-mongodb?tck=docs_server" target="_self"> <span> MongoDB Blog: On Selecting a Shard Key for MongoDB <!-- --> . </span> </a> </p> </li> </ul> </div> </div> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 8.0, use of the <code class="leafygreen-ui-1l06pbn"> timeField </code> as a shard key in a time series collection is deprecated. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-hashed-shard-keys"> </span> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Hashed Shard Keys <a class="headerlink leafygreen-ui-1kepx47" href="#hashed-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="hashed-shard-keys"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/#std-label-sharding-hashed-sharding"> Hashed shard keys </a> use a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/#std-label-index-type-hashed"> hashed index </a> or a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed"> compound hashed index </a> as the shard key. </p> <p class="leafygreen-ui-1kp3ins"> Use the form <code class="leafygreen-ui-1l06pbn"> field: "hashed" </code> to specify a hashed shard key field. </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 chunk migrations are in progress while creating a hashed shard key collection, the initial chunk distribution may be uneven until the balancer automatically balances the collection. </p> </div> </div> <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/hashed-sharding/"> Hashed Sharding </a> </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-shardCollection-zones"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Zone Sharding and Initial Chunk Distribution <a class="headerlink leafygreen-ui-1kepx47" href="#zone-sharding-and-initial-chunk-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="zone-sharding-and-initial-chunk-distribution"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The shard collection operation (i.e. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </span> </a> command and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection"> <code class="leafygreen-ui-1l06pbn"> sh.shardCollection() </code> </a> helper) can perform initial chunk creation and distribution for an empty or a non-existing collection if <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/"> zones and zone ranges </a> have been defined for the collection. Initial chunk distribution allows for a faster setup of zoned sharding. After the initial distribution, the balancer manages the chunk distribution going forward per usual. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-example"> Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection </a> for an example. If sharding a collection using a ranged or single-field hashed shard key, the <code class="leafygreen-ui-1l06pbn"> numInitialChunks </code> option has no effect if zones and zone ranges have been defined for the empty collection. </p> <p class="leafygreen-ui-1kp3ins"> To shard a collection using a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed"> compound hashed index </a> , see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-shardCollection-zones-compound-hashed" target="_self"> <span> Zone Sharding and Compound Hashed Indexes <!-- --> . </span> </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-shardCollection-zones-compound-hashed"> </span> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Zone Sharding and Compound Hashed Indexes <a class="headerlink leafygreen-ui-1kepx47" href="#zone-sharding-and-compound-hashed-indexes" 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="zone-sharding-and-compound-hashed-indexes"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> MongoDB supports sharding collections on <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed"> compound hashed indexes </a> . When sharding an empty or non-existing collection using a compound hashed shard key, additional requirements apply in order for MongoDB to perform initial chunk creation and distribution. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> numInitialChunks </code> option has no effect if zones and zone ranges have been defined for the empty collection <em> and </em> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-presplitHashedZones" target="_self"> <span> presplitHashedZones </span> </a> is <code class="leafygreen-ui-1l06pbn"> false </code> . </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-hashed-example"> Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection </a> for an example. </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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-initial-chunks"> Initial Chunks </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/balancerCollectionStatus/#mongodb-dbcommand-dbcmd.balancerCollectionStatus"> <code class="leafygreen-ui-1l06pbn"> balancerCollectionStatus </code> </a> </p> </li> </ul> </div> </div> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Uniqueness <a class="headerlink leafygreen-ui-1kepx47" href="#uniqueness" 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="uniqueness"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If specifying <code class="leafygreen-ui-1l06pbn"> unique: true </code> : </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the collection is empty, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </span> </a> creates the unique index on the shard key if such an index does not already exist. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the collection is not empty, you must create the index first before using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> . </span> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Although you can have a unique <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-compound-index"> compound index </a> where the shard key is a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-compound/#std-label-compound-index-prefix"> prefix </a> , if using <code class="leafygreen-ui-1l06pbn"> unique </code> parameter, the collection must have a unique index that is on the shard key. </p> <p class="leafygreen-ui-1kp3ins"> See also <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key-unique"> Sharded Collection and Unique Indexes </a> </p> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Collation <a class="headerlink leafygreen-ui-1kepx47" href="#collation" 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="collation"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> If the collection has a default <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> collation </a> , the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </span> </a> command must include a <code class="leafygreen-ui-1l06pbn"> collation </code> parameter with the value <code class="leafygreen-ui-1l06pbn"> { locale: "simple" } </code> . For non-empty collections with a default collation, you must have at least one index with the simple collation whose fields support the shard key pattern. </p> <p class="leafygreen-ui-1kp3ins"> You do not need to specify the <code class="leafygreen-ui-1l06pbn"> collation </code> option for collections without a collation. If you do specify the collation option for a collection with no collation, it will have no effect. </p> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Write Concern <a class="headerlink leafygreen-ui-1kepx47" href="#write-concern" 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="write-concern"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> for the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern"> write concern </a> of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </span> </a> command, its helper <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection"> <code class="leafygreen-ui-1l06pbn"> sh.shardCollection() </code> </a> , and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardAndDistributeCollection/#mongodb-method-sh.shardAndDistributeCollection"> <code class="leafygreen-ui-1l06pbn"> sh.shardAndDistributeCollection() </code> </a> method. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following operation enables sharding for the <code class="leafygreen-ui-1l06pbn"> people </code> collection in the <code class="leafygreen-ui-1l06pbn"> records </code> database and uses the <code class="leafygreen-ui-1l06pbn"> zipcode </code> field as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key"> shard key <!-- --> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { shardCollection: \"records.people\", key: { zipcode: 1 } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">shardCollection</span>: <span class="lg-highlight-string">"records.people"</span>, <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-attr">zipcode</span>: <span class="lg-highlight-number">1</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 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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/refineCollectionShardKey/#mongodb-dbcommand-dbcmd.refineCollectionShardKey"> <code class="leafygreen-ui-1l06pbn"> refineCollectionShardKey </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.balancerCollectionStatus/#mongodb-method-sh.balancerCollectionStatus"> <code class="leafygreen-ui-1l06pbn"> sh.balancerCollectionStatus() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection"> <code class="leafygreen-ui-1l06pbn"> sh.shardCollection() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/"> Sharding </a> </p> </li> </ul> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/nav-crud/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Query and Write Operation Commands <a class="headerlink leafygreen-ui-1kepx47" href="#query-and-write-operation-commands" 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="query-and-write-operation-commands"> </div> </a> </h1> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> For details on a specific command, including syntax and examples, click on the link to the command's reference page. </p> </div> </div> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/delete/#mongodb-dbcommand-dbcmd.delete"> <code class="leafygreen-ui-1l06pbn"> delete </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Deletes one or more documents. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/find/#mongodb-dbcommand-dbcmd.find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Selects documents in a collection or a view. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/findAndModify/#mongodb-dbcommand-dbcmd.findAndModify"> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns and modifies a single document. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getLastError/#mongodb-dbcommand-dbcmd.getLastError"> <code class="leafygreen-ui-1l06pbn"> getLastError </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Removed in MongoDB 5.1. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getMore/#mongodb-dbcommand-dbcmd.getMore"> <code class="leafygreen-ui-1l06pbn"> getMore </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns batches of documents currently pointed to by the cursor. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/insert/#mongodb-dbcommand-dbcmd.insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Inserts one or more documents. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/resetError/#mongodb-dbcommand-dbcmd.resetError"> <code class="leafygreen-ui-1l06pbn"> resetError </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <em> Removed in MongoDB 5.0. </em> Resets the last error status. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/update/#mongodb-dbcommand-dbcmd.update"> <code class="leafygreen-ui-1l06pbn"> update </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Updates one or more documents. </div> </div> </td> </tr> </tbody> </table> </div> </section>
https://www.mongodb.com/docs/manual/reference/command/balancerStop/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> balancerStop <a class="headerlink leafygreen-ui-1kepx47" href="#balancerstop" 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="balancerstop"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="dbcommand"> <dt> <code class="leafygreen-ui-1l06pbn"> balancerStop </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.balancerStop" title="Permalink to this definition"> <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="mongodb-dbcommand-dbcmd.balancerStop"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Disables the balancer in a sharded cluster. If a balancing round is in progress, the operation waits for balancing to complete. </p> <p class="leafygreen-ui-1kp3ins"> You can only issue the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.balancerStop" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> balancerStop </code> </span> </a> against the <code class="leafygreen-ui-1l06pbn"> admin </code> database on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instance. </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Leaving the balancer disabled for extended periods of time can lead to unbalanced shards, which degrade cluster performance. Only disable the balancer if necessary, and ensure that you <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-sharding-balancing-re-enable"> re-enable the balancer </a> when maintenance is complete. </p> </div> </div> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> In <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongosh </code> </span> </a> , this command can also be run through the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.stopBalancer/#mongodb-method-sh.stopBalancer"> <code class="leafygreen-ui-1l06pbn"> sh.stopBalancer() </code> </a> helper method <!-- --> . </p> <p class="leafygreen-ui-1kp3ins"> Helper methods are convenient for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongosh </code> </span> </a> users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation. </p> <p class="leafygreen-ui-1kp3ins"> In MongoDB versions earlier than 6.1, the command disables auto-splitting for the sharded cluster. To enable auto-splitting when the balancer is disabled, you can use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.enableAutoSplit/#mongodb-method-sh.enableAutoSplit"> <code class="leafygreen-ui-1l06pbn"> sh.enableAutoSplit() </code> . </a> </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This command is available in deployments hosted 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> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command is not supported in serverless instances. For more information, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self"> <span> Unsupported Commands <!-- --> . </span> </a> </p> </div> </div> <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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n balancerStop: 1,\n maxTimeMS: &lt;number&gt;\n }\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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">balancerStop</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">maxTimeMS</span>: &lt;<!-- -->number<!-- -->&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</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> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Command Fields <a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" 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="command-fields"> </div> </a> </h3> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> balancerStop </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> any </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Any value. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> maxTimeMS </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> integer </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Time limit for disabling the balancer. </p> <p class="leafygreen-ui-1kp3ins"> Defaults to 60000 milliseconds. </p> </div> </div> </td> </tr> </tbody> </table> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To stop the balancer thread, 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> instance and issue the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { balancerStop: 1 } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">balancerStop</span>: <span class="lg-highlight-number">1</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> </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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.stopBalancer/#mongodb-method-sh.stopBalancer"> <code class="leafygreen-ui-1l06pbn"> sh.stopBalancer() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/balancerStart/#mongodb-dbcommand-dbcmd.balancerStart"> <code class="leafygreen-ui-1l06pbn"> balancerStart </code> </a> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/transitionFromDedicatedConfigServer/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> transitionFromDedicatedConfigServer <a class="headerlink leafygreen-ui-1kepx47" href="#transitionfromdedicatedconfigserver" 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="transitionfromdedicatedconfigserver"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#access-control" target="_self"> <span> Access Control </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="dbcommand"> <dt> <code class="leafygreen-ui-1l06pbn"> transitionFromDedicatedConfigServer </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.transitionFromDedicatedConfigServer" title="Permalink to this definition"> <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="mongodb-dbcommand-dbcmd.transitionFromDedicatedConfigServer"> </div> </a> </dt> <dd> </dd> </dl> <div> <p> <em> New <!-- --> in version <!-- --> 8.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 8.0, you can: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Configure a config server to store your application data in addition to the usual <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster </a> metadata. A config server that stores application data is called a <em> config shard </em> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Transition a config server between being a config shard and a dedicated config server. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> A cluster requires a config server, but it can be a config shard instead of a dedicated config server. Using a config shard reduces the number of nodes required and can simplify your deployment. </p> <p class="leafygreen-ui-1kp3ins"> If your application has demanding availability and resiliency requirements, consider deploying a dedicated config server. A dedicated config server provides isolation, dedicated resources, and consistent performance for critical cluster operations. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> transitionFromDedicatedConfigServer </code> command configures a dedicated config server to run as a config shard. </p> <p class="leafygreen-ui-1kp3ins"> Before you run <code class="leafygreen-ui-1l06pbn"> transitionFromDedicatedConfigServer </code> , connect to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> and use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-admin-database"> admin database <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> The sharded cluster must have <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv"> featureCompatibilityVersion </a> set to at least <code class="leafygreen-ui-1l06pbn"> 8.0 </code> . </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Command syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( {\n transitionFromDedicatedConfigServer: 1\n} )","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">transitionFromDedicatedConfigServer</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} )</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> transitionFromDedicatedConfigServer </code> command adds the config server as a shard in the cluster. Internally, <code class="leafygreen-ui-1l06pbn"> transitionFromDedicatedConfigServer </code> runs the <code class="leafygreen-ui-1l06pbn"> addShard </code> command. You can see the config shard entry in the <code class="leafygreen-ui-1l06pbn"> admin.system.version </code> collection with <code class="leafygreen-ui-1l06pbn"> shardName: 'config' </code> . </p> <p class="leafygreen-ui-1kp3ins"> To see a list of the shards in the cluster, run the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/listShards/#mongodb-dbcommand-dbcmd.listShards"> <code class="leafygreen-ui-1l06pbn"> listShards </code> </a> command. </p> <p class="leafygreen-ui-1kp3ins"> If you must downgrade the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv"> feature compatibility version </a> below 8.0, first run the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/transitionToDedicatedConfigServer/#mongodb-dbcommand-dbcmd.transitionToDedicatedConfigServer"> <code class="leafygreen-ui-1l06pbn"> transitionToDedicatedConfigServer </code> </a> command. For downgrade details, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-config-servers/#std-label-sharded-cluster-config-server-config-shards-downgrade"> Downgrade Feature Compatibility Version <!-- --> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Access Control <a class="headerlink leafygreen-ui-1kepx47" href="#access-control" 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="access-control"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> If access control is enabled, the <code class="leafygreen-ui-1l06pbn"> transitionFromDedicatedConfigServer </code> command requires the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-transitionFromDedicatedConfigServer"> <code class="leafygreen-ui-1l06pbn"> transitionFromDedicatedConfigServer </code> </a> authorization action for the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-document"> cluster <!-- --> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n resource: { cluster : true },\n actions: [ \"transitionFromDedicatedConfigServer\" ]\n}","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">resource</span>: <!-- -->{ <!-- -->cluster <!-- -->: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">actions</span>: <!-- -->[ <span class="lg-highlight-string">"transitionFromDedicatedConfigServer"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterManager"> <code class="leafygreen-ui-1l06pbn"> clusterManager </code> </a> role has <code class="leafygreen-ui-1l06pbn"> transitionFromDedicatedConfigServer </code> authorization action and can be assigned to a user. </p> <p class="leafygreen-ui-1kp3ins"> The following example assigns the <code class="leafygreen-ui-1l06pbn"> clusterManager </code> role to a user named <code class="leafygreen-ui-1l06pbn"> testUser </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.grantRolesToUser(\n \"testUser\",\n [ \"clusterManager\" ]\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">db.<span class="lg-highlight-title lg-highlight-function">grantRolesToUser</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"testUser"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <span class="lg-highlight-string">"clusterManager"</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following example configures a dedicated config server to run as a config shard: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( {\n transitionFromDedicatedConfigServer: 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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">transitionFromDedicatedConfigServer</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> </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> <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-config-servers/#std-label-sharded-cluster-config-server-config-shards"> Config Shards </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-users-and-roles/#std-label-modify-existing-user-access"> Modify Access for an Existing User </a> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/cleanupOrphaned/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> cleanupOrphaned <a class="headerlink leafygreen-ui-1kepx47" href="#cleanuporphaned" 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="cleanuporphaned"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#required-access" target="_self"> <span> Required Access </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#output" target="_self"> <span> Output </span> </a> </li> </ul> </div> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 6.0.3, you should run an aggregation using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/shardedDataDistribution/#mongodb-pipeline-pipe.-shardedDataDistribution"> <code class="leafygreen-ui-1l06pbn"> $shardedDataDistribution </code> </a> stage to confirm no orphaned documents remain. For details, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/shardedDataDistribution/#std-label-shardedDataDistribution-no-orphaned-docs"> Confirm No Orphaned Documents Remain <!-- --> . </a> </p> </div> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="dbcommand"> <dt> <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.cleanupOrphaned" title="Permalink to this definition"> <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="mongodb-dbcommand-dbcmd.cleanupOrphaned"> </div> </a> </dt> <dd> <div> <p> <em> Deprecated <!-- --> since version <!-- --> 8.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Use this command to wait for orphaned documents in a chunk range from a shard key's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MinKey"> <code class="leafygreen-ui-1l06pbn"> MinKey </code> </a> to its <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MaxKey"> <code class="leafygreen-ui-1l06pbn"> MaxKey </code> </a> for a specified namespace to be cleaned up from a majority of a shard's members. </p> <p class="leafygreen-ui-1kp3ins"> To run, issue <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> in the <code class="leafygreen-ui-1l06pbn"> admin </code> database directly on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instance that is the primary replica set member of the shard. You do not need to disable the balancer before running <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> . </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"> Do not run <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instance. </p> </div> </div> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This command is available in deployments hosted 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> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command is not supported in M0, M2, and M5 clusters. For more information, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self"> <span> Unsupported Commands <!-- --> . </span> </a> </p> </div> </div> <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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n cleanupOrphaned: \"&lt;database&gt;.&lt;collection&gt;\",\n startingFromKey: &lt;minimumshardkeyvalue&gt;, // deprecated\n secondaryThrottle: &lt;boolean&gt;, // deprecated\n writeConcern: &lt;document&gt; // deprecated\n }\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cleanupOrphaned</span>: <span class="lg-highlight-string">"&lt;database&gt;.&lt;collection&gt;"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">startingFromKey</span>: &lt;<!-- -->minimumShardKeyValue<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-comment">// deprecated</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">secondaryThrottle</span>: &lt;<!-- -->boolean<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-comment">// deprecated</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">writeConcern</span>: &lt;<span class="lg-highlight-variable lg-highlight-language">document</span>&gt; <span class="lg-highlight-comment">// deprecated</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</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> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Command Fields <a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" 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="command-fields"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> has the following fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The namespace, i.e. both the database and the collection name, of the sharded collection for which to wait for cleanup of the orphaned data. </div> </div> </td> </tr> </tbody> </table> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <span class="leafygreen-ui-1qnjd6d" id="std-label-cleanupOrphaned-determine-range"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Determine Range <a class="headerlink leafygreen-ui-1kepx47" href="#determine-range" 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="determine-range"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The value of this field is not used to determine the bounds of the cleanup range. The <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> command waits until all orphaned documents in all ranges in the namespace are cleaned up from the shard before completing, regardless of the presence of or value of <code class="leafygreen-ui-1l06pbn"> startingFromKey </code> . </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Required Access <a class="headerlink leafygreen-ui-1kepx47" href="#required-access" 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="required-access"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> On systems running with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.authorization"> <code class="leafygreen-ui-1l06pbn"> authorization </code> </a> , you must have <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterAdmin"> <code class="leafygreen-ui-1l06pbn"> clusterAdmin </code> </a> privileges to run <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> . </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-cleanupOrphaned-output"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Output <a class="headerlink leafygreen-ui-1kepx47" href="#output" 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="output"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Return Document <a class="headerlink leafygreen-ui-1kepx47" href="#return-document" 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="return-document"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Each <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> command returns a document containing a subset of the following fields: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned.ok </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-cleanupOrphaned.ok" title="Permalink to this definition"> <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="mongodb-data-cleanupOrphaned.ok"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Equal to <code class="leafygreen-ui-1l06pbn"> 1 </code> on success. </p> <p class="leafygreen-ui-1kp3ins"> A value of <code class="leafygreen-ui-1l06pbn"> 1 </code> indicates that either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> No orphaned documents remain in the <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> namespace on the shard, or </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The collection referenced in the <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> namespace is not sharded. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> A value of <code class="leafygreen-ui-1l06pbn"> 0 </code> indicates that an error has occurred. </p> </dd> </dl> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/setAllowMigrations/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> setAllowMigrations <a class="headerlink leafygreen-ui-1kepx47" href="#setallowmigrations" 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="setallowmigrations"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self"> <span> Command Fields </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="dbcommand"> <dt> <code class="leafygreen-ui-1l06pbn"> setAllowMigrations </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.setAllowMigrations" title="Permalink to this definition"> <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="mongodb-dbcommand-dbcmd.setAllowMigrations"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Prevents the start of new <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration-automatic"> automatic migrations </a> on a collection, prevents in-flight <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration-manual"> manual migrations </a> from committing, and excludes the collection from new balancer rounds. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This command is available in deployments hosted 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> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command is not supported in serverless instances. For more information, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self"> <span> Unsupported Commands <!-- --> . </span> </a> </p> </div> </div> <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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n setAllowMigrations: \"&lt;db&gt;.&lt;collection&gt;\",\n allowMigrations: &lt;true|false&gt;\n }\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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">setAllowMigrations</span>: <span class="lg-highlight-string">"&lt;db&gt;.&lt;collection&gt;"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowMigrations</span>: <span class="lg-highlight-xml">&lt;true|false&gt;</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-xml"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-xml">)</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Command Fields <a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" 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="command-fields"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command takes the following parameters: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:60%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-setAllowMigrations-cmd-coll" target="_self"> <span> setAllowMigrations </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> string </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-setAllowMigrations-cmd-coll"> </span> <p class="leafygreen-ui-1kp3ins"> The collection to modify. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-setAllowMigrations-cmd-flag" target="_self"> <span> allowMigrations </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> boolean </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-setAllowMigrations-cmd-flag"> </span> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> false </code> : </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> MongoDB prevents new <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration-automatic"> automatic migrations </a> on the collection </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> in-flight <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration-manual"> manual migrations </a> will not be committed </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the collection will be excluded from new balancer rounds </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> true </code> : </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> MongoDB allows new <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration-automatic"> automatic migrations </a> on the collection </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> in-flight <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration-manual"> manual migrations </a> will be committed </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the collection will be included in new balancer rounds </p> </li> </ul> </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.setAllowMigrations" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> setAllowMigrations </code> </span> </a> requires the same privileges as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-moveChunk"> <code class="leafygreen-ui-1l06pbn"> moveChunk </code> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This operation prevents migrations on the <code class="leafygreen-ui-1l06pbn"> store.inventory </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( {\n setAllowMigrations: \"store.inventory\",\n allowMigrations: false\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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">setAllowMigrations</span>: <span class="lg-highlight-string">"store.inventory"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowMigrations</span>: <span class="lg-highlight-literal">false</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> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/findAndModify/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> findAndModify <a class="headerlink leafygreen-ui-1kepx47" href="#findandmodify" 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="findandmodify"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self"> <span> Command Fields </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#output" target="_self"> <span> Output </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="dbcommand"> <dt> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.findAndModify" title="Permalink to this definition"> <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="mongodb-dbcommand-dbcmd.findAndModify"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> command updates and returns a single document. By default, the returned document does not include the modifications made on the update. To return the document with the modifications made on the update, use the <code class="leafygreen-ui-1l06pbn"> new </code> option. </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"> In <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongosh </code> </span> </a> , this command can also be run through the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify"> <code class="leafygreen-ui-1l06pbn"> db.collection.findAndModify() </code> </a> helper method <!-- --> . </p> <p class="leafygreen-ui-1kp3ins"> Helper methods are convenient for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongosh </code> </span> </a> users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command. </p> </div> </div> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This command is available in deployments hosted 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> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self"> <span> Unsupported Commands <!-- --> . </span> </a> </p> </div> </div> <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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> <div> <p> <em> Changed <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n findAndModify: &lt;collection-name&gt;,\n query: &lt;document&gt;,\n sort: &lt;document&gt;,\n remove: &lt;boolean&gt;,\n update: &lt;document&gt;,\n new: &lt;boolean&gt;,\n fields: &lt;document&gt;,\n upsert: &lt;boolean&gt;,\n bypassDocumentValidation: &lt;boolean&gt;,\n writeConcern: &lt;document&gt;,\n maxTimeMS: &lt;integer&gt;,\n collation: &lt;document&gt;,\n arrayFilters: &lt;array&gt;,\n hint: &lt;document|string&gt;,\n comment: &lt;any&gt;,\n let: &lt;document&gt; // Added in MongoDB 5.0\n }\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: &lt;<!-- -->collection<!-- -->-<!-- -->name<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: &lt;<span class="lg-highlight-variable lg-highlight-language">document</span>&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sort</span>: &lt;<span class="lg-highlight-variable lg-highlight-language">document</span>&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">remove</span>: &lt;<!-- -->boolean<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->&lt;document or aggregation pipeline&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> new: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> fields: &lt;document&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> upsert: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> bypassDocumentValidation: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> writeConcern: &lt;document&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> maxTimeMS: &lt;integer&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> collation: &lt;document&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> arrayFilters: &lt;array&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> hint: &lt;document|string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> comment: &lt;any&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> let: &lt;document&gt; // Added in MongoDB 5.0</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Command Fields <a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" 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="command-fields"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command takes the following fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> query </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. The selection criteria for the modification. The <code class="leafygreen-ui-1l06pbn"> query </code> field employs the same <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/#std-label-query-selectors"> query selectors </a> as used in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find"> <code class="leafygreen-ui-1l06pbn"> db.collection.find() </code> </a> method. Although the query may match multiple documents, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> <strong> will only select one document to update </strong> . </p> <p class="leafygreen-ui-1kp3ins"> If unspecified, defaults to an empty document. </p> <p class="leafygreen-ui-1kp3ins"> If the query argument is not a document, the operation errors. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-findandmodify-command-consistent-sorting"> </span> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> sort </code> </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. Determines which document the operation updates if the query selects multiple documents. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> updates the first document in the sort order specified by this argument. </p> <p class="leafygreen-ui-1kp3ins"> If the sort argument is not a document, the operation errors. </p> <p class="leafygreen-ui-1kp3ins"> MongoDB does not store documents in a collection in a particular order. When sorting on a field which contains duplicate values, documents containing those values may be returned in any order. </p> <p class="leafygreen-ui-1kp3ins"> If consistent sort order is desired, include at least one field in your sort that contains unique values. The easiest way to guarantee this is to include the <code class="leafygreen-ui-1l06pbn"> _id </code> field in your sort query. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#std-label-sort-cursor-consistent-sorting"> Sort Consistency </a> for more information. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> remove </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Must specify either the <code class="leafygreen-ui-1l06pbn"> remove </code> or the <code class="leafygreen-ui-1l06pbn"> update </code> field. Removes the document specified in the <code class="leafygreen-ui-1l06pbn"> query </code> field. Set this to <code class="leafygreen-ui-1l06pbn"> true </code> to remove the selected document . The default is <code class="leafygreen-ui-1l06pbn"> false </code> . </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> update </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document or array </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Must specify either the <code class="leafygreen-ui-1l06pbn"> remove </code> or the <code class="leafygreen-ui-1l06pbn"> update </code> field. Performs an update of the selected document. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If passed a document with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/#std-label-update-operators"> update operator expressions </a> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> performs the specified modification. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If passed a replacement document <code class="leafygreen-ui-1l06pbn"> { &lt;field1&gt;: &lt;value1&gt;, ...} </code> , the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> performs a replacement. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If passed an <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline </a> <code class="leafygreen-ui-1l06pbn"> [ &lt;stage1&gt;, &lt;stage2&gt;, ... ] </code> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> updates the document per the pipeline. The pipeline can consist of the following stages: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceRoot/#mongodb-pipeline-pipe.-replaceRoot"> <code class="leafygreen-ui-1l06pbn"> $replaceRoot </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith"> <code class="leafygreen-ui-1l06pbn"> $replaceWith </code> . </a> </p> </li> </ul> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> new </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Optional. When <code class="leafygreen-ui-1l06pbn"> true </code> , returns the updated document rather than the original. The default is <code class="leafygreen-ui-1l06pbn"> false </code> . </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> fields </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A subset of fields to return. The <code class="leafygreen-ui-1l06pbn"> fields </code> document specifies an inclusion of a field with <code class="leafygreen-ui-1l06pbn"> 1 </code> , as in: <code class="leafygreen-ui-1l06pbn"> fields: { &lt;field1&gt;: 1, &lt;field2&gt;: 1, ... } </code> . See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#std-label-find-projection"> Projection <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> If the fields argument is not a document, the operation errors. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> upsert </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. Used in conjunction with the <code class="leafygreen-ui-1l06pbn"> update </code> field. </p> <p class="leafygreen-ui-1kp3ins"> When <code class="leafygreen-ui-1l06pbn"> true </code> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Creates a new document if no documents match the <code class="leafygreen-ui-1l06pbn"> query </code> . For more details see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.update/#std-label-upsert-behavior"> upsert behavior <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Updates a single document that matches the <code class="leafygreen-ui-1l06pbn"> query </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> To avoid multiple <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert"> upserts </a> , ensure that the <code class="leafygreen-ui-1l06pbn"> query </code> field(s) are <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique"> uniquely indexed </a> . See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-upsert-and-unique-index-dbcommand" target="_self"> <span> Upsert with Unique Index </span> </a> for an example. </p> <p class="leafygreen-ui-1kp3ins"> Defaults to <code class="leafygreen-ui-1l06pbn"> false </code> , which does <em> not </em> insert a new document when no match is found. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Optional. Enables <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> to bypass document validation during the operation. This lets you update documents that do not meet the validation requirements. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> writeConcern </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A document expressing the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern"> write concern </a> . Omit to use the default write concern. </p> <p class="leafygreen-ui-1kp3ins"> Do not explicitly set the write concern for the operation if run in a transaction. To use write concern with transactions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern"> Transactions and Write Concern <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> maxTimeMS </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> non-negative integer </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. </p> <p class="leafygreen-ui-1kp3ins"> Specifies a time limit in milliseconds. If you do not specify a value for <code class="leafygreen-ui-1l06pbn"> maxTimeMS </code> , operations will not time out. A value of <code class="leafygreen-ui-1l06pbn"> 0 </code> explicitly specifies the default unbounded behavior. </p> <p class="leafygreen-ui-1kp3ins"> MongoDB terminates operations that exceed their allotted time limit using the same mechanism as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.killOp/#mongodb-method-db.killOp"> <code class="leafygreen-ui-1l06pbn"> db.killOp() </code> </a> . MongoDB only terminates an operation at one of its designated <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-interrupt-point"> interrupt points <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The collection against which to run the command. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> collation </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. </p> <p class="leafygreen-ui-1kp3ins"> Specifies the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> collation </a> to use for the operation. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> Collation </a> allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks. </p> <p class="leafygreen-ui-1kp3ins"> The collation option has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"collation: {\n locale: &lt;string&gt;,\n caseLevel: &lt;boolean&gt;,\n caseFirst: &lt;string&gt;,\n strength: &lt;int&gt;,\n numericOrdering: &lt;boolean&gt;,\n alternate: &lt;string&gt;,\n maxVariable: &lt;string&gt;,\n backwards: &lt;boolean&gt;\n}"} </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">collation: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> locale: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> caseLevel: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> caseFirst: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> strength: &lt;int&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> numericOrdering: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> alternate: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> maxVariable: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> backwards: &lt;boolean&gt;</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> <p class="leafygreen-ui-1kp3ins"> When specifying collation, the <code class="leafygreen-ui-1l06pbn"> locale </code> field is mandatory; all other collation fields are optional. For descriptions of the fields, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation-document-fields"> Collation Document <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> If the collation is unspecified but the collection has a default collation (see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.createCollection/#mongodb-method-db.createCollection"> <code class="leafygreen-ui-1l06pbn"> db.createCollection() </code> </a> ), the operation uses the collation specified for the collection. </p> <p class="leafygreen-ui-1kp3ins"> If no collation is specified for the collection or for the operations, MongoDB uses the simple binary comparison used in prior versions for string comparisons. </p> <p class="leafygreen-ui-1kp3ins"> You cannot specify multiple collations for an operation. For example, you cannot specify different collations per field, or if performing a find with a sort, you cannot use one collation for the find and another for the sort. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> array </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. An array of filter documents that determine which array elements to modify for an update operation on an array field. </p> <p class="leafygreen-ui-1kp3ins"> In the update document, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/positional-filtered/#mongodb-update-up.---identifier--"> <code class="leafygreen-ui-1l06pbn"> $[&lt;identifier&gt;] </code> </a> filtered positional operator to define an identifier, which you then reference in the array filter documents. You cannot have an array filter document for an identifier if the identifier is not included in the update document. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> &lt;identifier&gt; </code> must begin with a lowercase letter and contain only alphanumeric characters. </p> <p class="leafygreen-ui-1kp3ins"> You can include the same identifier multiple times in the update document; however, for each distinct identifier ( <code class="leafygreen-ui-1l06pbn"> $[identifier] </code> ) in the update document, you must specify <strong> exactly one </strong> corresponding array filter document. That is, you cannot specify multiple array filter documents for the same identifier. For example, if the update statement includes the identifier <code class="leafygreen-ui-1l06pbn"> x </code> (possibly multiple times), you cannot specify the following for <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> that includes 2 separate filter documents for <code class="leafygreen-ui-1l06pbn"> x </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// INVALID\n\n[\n { \"x.a\": { $gt: 85 } },\n { \"x.b\": { $gt: 80 } }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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"><span class="lg-highlight-comment">// INVALID</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"x.a"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"x.b"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> However, you can specify compound conditions on the same identifier in a single filter document, such as in the following examples: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// Example 1\n[\n { $or: [{\"x.a\": {$gt: 85}}, {\"x.b\": {$gt: 80}}] }\n]\n// Example 2\n[\n { $and: [{\"x.a\": {$gt: 85}}, {\"x.b\": {$gt: 80}}] }\n]\n// Example 3\n[\n { \"x.a\": { $gt: 85 }, \"x.b\": { $gt: 80 } }\n]","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// Example 1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$or</span>: <!-- -->[<!-- -->{<span class="lg-highlight-string">"x.a"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span>}}<!-- -->, <!-- -->{<span class="lg-highlight-string">"x.b"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</span>}}] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// Example 2</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$and</span>: <!-- -->[<!-- -->{<span class="lg-highlight-string">"x.a"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span>}}<!-- -->, <!-- -->{<span class="lg-highlight-string">"x.b"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</span>}}] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// Example 3</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"x.a"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span> }<!-- -->, <span class="lg-highlight-string">"x.b"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</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> <p class="leafygreen-ui-1kp3ins"> For examples, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-findAndModify-command-arrayFilters" target="_self"> <span> Array Update Operations with <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> is not available for updates that use an aggregation pipeline. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> hint </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document or string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A document or string that specifies the <a class="leafygreen-ui-tqgtui" href="/docs/manual/indexes/#std-label-indexes"> index </a> to use to support the <code class="leafygreen-ui-1l06pbn"> query </code> . </p> <p class="leafygreen-ui-1kp3ins"> The option can take an index specification document or the index name string. </p> <p class="leafygreen-ui-1kp3ins"> If you specify an index that does not exist, the operation errors. </p> <p class="leafygreen-ui-1kp3ins"> For an example, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-ex-findAndModify-hint" target="_self"> <span> Specify <code class="leafygreen-ui-1l06pbn"> hint </code> for <code class="leafygreen-ui-1l06pbn"> findAndModify </code> Operations <!-- --> . </span> </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> comment </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> any </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref"> mongod log messages </a> , in the <code class="leafygreen-ui-1l06pbn"> attr.command.cursor.comment </code> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler"> Database profiler </a> output, in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#mongodb-data-system.profile.command"> <code class="leafygreen-ui-1l06pbn"> command.comment </code> </a> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp"> <code class="leafygreen-ui-1l06pbn"> currentOp </code> </a> output, in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.command"> <code class="leafygreen-ui-1l06pbn"> command.comment </code> </a> field. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> A comment can be any valid <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types"> BSON type </a> (string, integer, object, array, etc). </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-findAndModify-let-syntax" target="_self"> <span> let </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-findAndModify-let-syntax"> </span> <p class="leafygreen-ui-1kp3ins"> Optional. </p> <p class="leafygreen-ui-1kp3ins"> Specifies a document with a list of variables. This allows you to improve command readability by separating the variables from the query text. </p> <p class="leafygreen-ui-1kp3ins"> The document syntax is: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n &lt;variable_name_1&gt;: &lt;expression_1&gt;,\n ...,\n &lt;variable_name_n&gt;: &lt;expression_n&gt;\n}","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> &lt;<!-- -->variable_name_1<!-- -->&gt;<!-- -->: &lt;<!-- -->expression_1<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> &lt;<!-- -->variable_name_n<!-- -->&gt;<!-- -->: &lt;<!-- -->expression_n<!-- -->&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> The variable is set to the value returned by the expression, and cannot be changed afterwards. </p> <p class="leafygreen-ui-1kp3ins"> To access the value of a variable in the command, use the double dollar sign prefix ( <code class="leafygreen-ui-1l06pbn"> $$ </code> ) together with your variable name in the form <code class="leafygreen-ui-1l06pbn"> $$&lt;variable_name&gt; </code> . For example: <code class="leafygreen-ui-1l06pbn"> $$targetTotal </code> . </p> <p class="leafygreen-ui-1kp3ins"> To use a variable to filter results, you must access the variable within the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr"> <code class="leafygreen-ui-1l06pbn"> $expr </code> </a> operator. </p> <p class="leafygreen-ui-1kp3ins"> For a complete example using <code class="leafygreen-ui-1l06pbn"> let </code> and variables, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-findAndModify-let-example" target="_self"> <span> Use Variables in <code class="leafygreen-ui-1l06pbn"> let </code> . </span> </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Output <a class="headerlink leafygreen-ui-1kepx47" href="#output" 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="output"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> command returns a document with the following fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> value </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the command's returned value. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-findandmodify-value-field" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> value </code> </span> </a> for details. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> lastErrorObject </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains information about updated documents. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-findandmodify-lastErrorObject" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> lastErrorObject </code> </span> </a> for details. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> ok </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> number </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the command's execution status. <code class="leafygreen-ui-1l06pbn"> 1 </code> on success, or <code class="leafygreen-ui-1l06pbn"> 0 </code> if an error occurred. </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-findandmodify-lastErrorObject"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> lastErrorObject </code> <a class="headerlink leafygreen-ui-1kepx47" href="#lasterrorobject" 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="lasterrorobject"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> lastErrorObject </code> embedded document contains the following fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> n </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> integer </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the number of documents that matched the update predicate or the number of documents that the command inserted or deleted. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> updatedExisting </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Contains <code class="leafygreen-ui-1l06pbn"> true </code> if an <code class="leafygreen-ui-1l06pbn"> update </code> operation: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Updated an existing document. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Found the document, but it was already in the desired destination state so no update actually occurred. </p> </li> </ul> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> upserted </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-objectid"> ObjectId </a> of the inserted document if an <code class="leafygreen-ui-1l06pbn"> update </code> operation with <code class="leafygreen-ui-1l06pbn"> upsert: true </code> resulted in a new document. </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-findandmodify-value-field"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> value </code> <a class="headerlink leafygreen-ui-1kepx47" href="#value" 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="value"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> For <code class="leafygreen-ui-1l06pbn"> remove </code> operations, <code class="leafygreen-ui-1l06pbn"> value </code> contains the removed document if the query matches a document. If the query does not match a document to remove, <code class="leafygreen-ui-1l06pbn"> value </code> contains <code class="leafygreen-ui-1l06pbn"> null </code> . </p> <p class="leafygreen-ui-1kp3ins"> For <code class="leafygreen-ui-1l06pbn"> update </code> operations, the <code class="leafygreen-ui-1l06pbn"> value </code> embedded document contains the following: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the <code class="leafygreen-ui-1l06pbn"> new </code> parameter is not set or is <code class="leafygreen-ui-1l06pbn"> false </code> : </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the pre-modification document if the query matches a document; </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> otherwise, <code class="leafygreen-ui-1l06pbn"> null </code> . </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> new </code> is <code class="leafygreen-ui-1l06pbn"> true </code> : </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the updated document if the query returns a match; </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the inserted document if <code class="leafygreen-ui-1l06pbn"> upsert: true </code> and no document matches the query; </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> otherwise, <code class="leafygreen-ui-1l06pbn"> null </code> . </p> </li> </ul> </li> </ul> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <span class="leafygreen-ui-1qnjd6d" id="std-label-upsert-and-unique-index-dbcommand"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Upsert with Unique Index <a class="headerlink leafygreen-ui-1kepx47" href="#upsert-with-unique-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="upsert-with-unique-index"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Upserts can create duplicate documents, unless there is a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique"> unique index </a> to prevent duplicates. </p> <p class="leafygreen-ui-1kp3ins"> Consider an example where no document with the name <code class="leafygreen-ui-1l06pbn"> Andy </code> exists and multiple clients issue the following command at roughly the same time: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n findAndModify: \"people\",\n query: { name: \"Andy\" },\n update: { $inc: { score: 1 } },\n upsert: true\n }\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <span class="lg-highlight-string">"people"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Andy"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">1</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> If all <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> operations finish the query phase before any client successfully inserts data, <strong> and </strong> there is no unique index on the <code class="leafygreen-ui-1l06pbn"> name </code> field, each <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> operation may result in an insert, creating multiple documents with <code class="leafygreen-ui-1l06pbn"> name: Andy </code> . </p> <p class="leafygreen-ui-1kp3ins"> A unique index on the <code class="leafygreen-ui-1l06pbn"> name </code> field ensures that only one document is created. With a unique index in place, the multiple <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> operations now exhibit the following behavior: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Exactly one <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> operation will successfully insert a new document. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Other <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> operations either update the newly-inserted document or fail due to a unique key collision. </p> <p class="leafygreen-ui-1kp3ins"> In order for other <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> operations to update the newly-inserted document, <strong> all </strong> of the following conditions must be met: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The target collection has a unique index that would cause a duplicate key error. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The update operation is not <code class="leafygreen-ui-1l06pbn"> updateMany </code> or <code class="leafygreen-ui-1l06pbn"> multi </code> is <code class="leafygreen-ui-1l06pbn"> false </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The update match condition is either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A single equality predicate. For example <code class="leafygreen-ui-1l06pbn"> { "fieldA" : "valueA" } </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A logical AND of equality predicates. For example <code class="leafygreen-ui-1l06pbn"> { "fieldA" : "valueA", "fieldB" : "valueB" } </code> </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The fields in the equality predicate match the fields in the unique index key pattern. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The update operation does not modify any fields in the unique index key pattern. </p> </li> </ul> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The following table shows examples of <code class="leafygreen-ui-1l06pbn"> upsert </code> operations that, when a key collision occurs, either result in an update or fail. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:40%"/> <col style="width:30%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Unique Index Key Pattern </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Update Operation </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Result </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ name : 1 }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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">{ <!-- -->name <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.updateOne(\n { name: \"Andy\" },\n { $inc: { score: 1 } },\n { upsert: true }\n)","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">people</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Andy"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">1</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The <code class="leafygreen-ui-1l06pbn"> score </code> field of the matched document is incremented by 1. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ name : 1 }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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">{ <!-- -->name <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.updateOne(\n { name: { $ne: \"Joe\" } },\n { $set: { name: \"Andy\" } },\n { upsert: true }\n )","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">people</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <!-- -->{ <span class="lg-highlight-attr">$ne</span>: <span class="lg-highlight-string">"Joe"</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Andy"</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> )</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The operation fails because it modifies the field in the unique index key pattern ( <code class="leafygreen-ui-1l06pbn"> name </code> ). </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ name : 1 }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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">{ <!-- -->name <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.updateOne(\n { name: \"Andy\", email: \"[email protected]\" },\n { $set: { active: false } },\n { upsert: true }\n)","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">people</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Andy"</span>, <span class="lg-highlight-attr">email</span>: <span class="lg-highlight-string">"[email protected]"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">active</span>: <span class="lg-highlight-literal">false</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The operation fails because the equality predicate fields ( <code class="leafygreen-ui-1l06pbn"> name </code> , <code class="leafygreen-ui-1l06pbn"> email </code> ) do not match the index key field ( <code class="leafygreen-ui-1l06pbn"> name </code> ). </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-cmd-findAndModify-sharded-collection"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Sharded Collections <a class="headerlink leafygreen-ui-1kepx47" href="#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-collections"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> on a sharded collection: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If you only target one shard, you can use a partial shard key in the <code class="leafygreen-ui-1l06pbn"> query </code> field or, </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You can provide an equality condition on a full shard key in the <code class="leafygreen-ui-1l06pbn"> query </code> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Starting in version 7.1, you do not need to provide the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> or <code class="leafygreen-ui-1l06pbn"> _id </code> field in the query specification. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Documents in a sharded collection can be <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key-missing"> missing the shard key fields </a> . To target a document that is missing the shard key, you can use the <code class="leafygreen-ui-1l06pbn"> null </code> equality match <strong class="css-4dei7l"> in conjunction with </strong> another filter condition (such as on the <code class="leafygreen-ui-1l06pbn"> _id </code> field). For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: &lt;value&gt;, &lt;shardkeyfield&gt;: null } // _id of the document missing shard key","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: &lt;<!-- -->value<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->shardkeyfield<!-- -->&gt;<!-- -->: <span class="lg-highlight-literal">null</span> } <span class="lg-highlight-comment">// _id of</span><span class="lg-highlight-comment"> the document missing </span><span class="lg-highlight-comment">shard key</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> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Shard Key Modification <a class="headerlink leafygreen-ui-1kepx47" href="#shard-key-modification" 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-modification"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can update a document's shard key value unless the shard key field is the immutable <code class="leafygreen-ui-1l06pbn"> _id </code> field. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Documents in sharded collections can be missing the shard key fields. Take precaution to avoid accidentally removing the shard key when changing a document's shard key value. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> To update the <strong> existing </strong> shard key value with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> : </span> </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> run on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> . Do <strong class="css-4dei7l"> not </strong> issue the operation directly on the shard. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> run either in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/"> transaction </a> or as a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/retryable-writes/"> retryable write <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> include an equality filter on the full shard key. </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-cmd-findAndModify-missing-shard-key"> </span> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Missing Shard Key <a class="headerlink leafygreen-ui-1kepx47" href="#missing-shard-key" 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="missing-shard-key"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Documents in a sharded collection can be <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key-missing"> missing the shard key fields </a> . To use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> to set the document's <strong> missing </strong> shard key: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> run on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> . Do <strong class="css-4dei7l"> not </strong> issue the operation directly on the shard. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> run either in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/"> transaction </a> or as a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/retryable-writes/"> retryable write </a> if the new shard key value is not <code class="leafygreen-ui-1l06pbn"> null </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> include an equality filter on the full shard key. </p> </li> </ul> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Since a missing key value is returned as part of a null equality match, to avoid updating a null-valued key, include additional query conditions (such as on the <code class="leafygreen-ui-1l06pbn"> _id </code> field) as appropriate. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> See also: </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/sharding-shard-key/#std-label-shard-key-missing"> Missing Shard Key Fields </a> </p> </li> </ul> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Document Validation <a class="headerlink leafygreen-ui-1kepx47" href="#document-validation" 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="document-validation"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> command adds support for the <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation </code> option, which lets you bypass <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/schema-validation/#std-label-schema-validation-overview"> document validation </a> when inserting or updating documents in a collection with validation rules. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-findAndModify-command-and-update"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Comparisons with the <code class="leafygreen-ui-1l06pbn"> update </code> Method <a class="headerlink leafygreen-ui-1kepx47" href="#comparisons-with-the-update-method" 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="comparisons-with-the-update-method"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> When updating a document, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne"> <code class="leafygreen-ui-1l06pbn"> updateOne() </code> </a> method operate differently: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If multiple documents match the update criteria, for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> , you can specify a <code class="leafygreen-ui-1l06pbn"> sort </code> to provide some measure of control on which document to update. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne"> <code class="leafygreen-ui-1l06pbn"> updateOne() </code> </a> updates the first document that matches. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> By default, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> returns <!-- --> an object that contains the pre-modified version of the document, as well as the status of the operation <!-- --> . To obtain the updated document, use the <code class="leafygreen-ui-1l06pbn"> new </code> option. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne"> <code class="leafygreen-ui-1l06pbn"> updateOne() </code> </a> method returns a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/WriteResult/#mongodb-method-WriteResult"> <code class="leafygreen-ui-1l06pbn"> WriteResult() </code> </a> object that contains the status of the operation. </p> <p class="leafygreen-ui-1kp3ins"> To return the updated document, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find"> <code class="leafygreen-ui-1l06pbn"> find() </code> </a> method. However, other updates may have modified the document between your update and the document retrieval. Also, if the update modified only a single document but multiple documents matched, you will need to use additional logic to identify the updated document. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> When modifying a <em> single </em> document, both <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne"> <code class="leafygreen-ui-1l06pbn"> updateOne() </code> </a> method <em> atomically </em> update the document. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/write-operations-atomicity/"> Atomicity and Transactions </a> for more details about interactions and order of operations of these methods. </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/dot-dollar-considerations/#std-label-crud-concepts-dot-dollar-considerations"> Considerations for field names </a> </p> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" 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> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> can be used inside <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> distributed transactions <!-- --> . </a> </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> In most cases, a distributed transaction incurs a greater performance cost over single document writes, and the availability of distributed transactions should not be a replacement for effective schema design. For many scenarios, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding"> denormalized data model (embedded documents and arrays) </a> will continue to be optimal for your data and use cases. That is, for many scenarios, modeling your data appropriately will minimize the need for distributed transactions. </p> <p class="leafygreen-ui-1kp3ins"> For additional transactions usage considerations (such as runtime limit and oplog size limit), see also <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-production-consideration/#std-label-production-considerations"> Production Considerations <!-- --> . </a> </p> </div> </div> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Upsert within Transactions <a class="headerlink leafygreen-ui-1kepx47" href="#upsert-within-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="upsert-within-transactions"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can create collections and indexes inside a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-create-collections-indexes"> distributed transaction </a> if the transaction is <strong class="css-4dei7l"> not </strong> a cross-shard write transaction. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> with <code class="leafygreen-ui-1l06pbn"> upsert: true </code> can be run on an existing collection or a non-existing collection. If run on a non-existing collection, the operation creates the collection. </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/transactions/#std-label-transactions-create-collections-indexes"> Create Collections and Indexes in a Transaction </a> </p> </div> </div> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Write Concerns and Transactions <a class="headerlink leafygreen-ui-1kepx47" href="#write-concerns-and-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="write-concerns-and-transactions"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Do not explicitly set the write concern for the operation if run in a transaction. To use write concern with transactions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern"> Transactions and Write Concern <!-- --> . </a> </p> </section> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Update and Return <a class="headerlink leafygreen-ui-1kepx47" href="#update-and-return" 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="update-and-return"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following command updates an existing document in the <code class="leafygreen-ui-1l06pbn"> people </code> collection where the document matches the <code class="leafygreen-ui-1l06pbn"> query </code> criteria: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n findAndModify: \"people\",\n query: { name: \"Tom\", state: \"active\", rating: { $gt: 10 } },\n sort: { rating: 1 },\n update: { $inc: { score: 1 } }\n }\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <span class="lg-highlight-string">"people"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Tom"</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"active"</span>, <span class="lg-highlight-attr">rating</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">10</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sort</span>: <!-- -->{ <span class="lg-highlight-attr">rating</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-attr">score</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">)</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"> This command performs the following actions: </p> <ol class="leafygreen-ui-rioki0" type="1"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> query </code> finds a document in the <code class="leafygreen-ui-1l06pbn"> people </code> collection where the <code class="leafygreen-ui-1l06pbn"> name </code> field has the value <code class="leafygreen-ui-1l06pbn"> Tom </code> , the <code class="leafygreen-ui-1l06pbn"> state </code> field has the value <code class="leafygreen-ui-1l06pbn"> active </code> and the <code class="leafygreen-ui-1l06pbn"> rating </code> field has a value <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/gt/#mongodb-expression-exp.-gt"> <code class="leafygreen-ui-1l06pbn"> greater than </code> </a> 10. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> sort </code> orders the results of the query in ascending order. If multiple documents meet the <code class="leafygreen-ui-1l06pbn"> query </code> condition, the command will select for modification the first document as ordered by this <code class="leafygreen-ui-1l06pbn"> sort </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> update </code> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/inc/#mongodb-update-up.-inc"> <code class="leafygreen-ui-1l06pbn"> increments </code> </a> the value of the <code class="leafygreen-ui-1l06pbn"> score </code> field by 1. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The command returns a document with the following fields: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> lastErrorObject </code> field that contains the details of the command, including the field <code class="leafygreen-ui-1l06pbn"> updatedExisting </code> which is <code class="leafygreen-ui-1l06pbn"> true </code> , and </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> value </code> field that contains the original (i.e. pre-modification) document selected for this update: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"lastErrorObject\" : {\n \"connectionId\" : 1,\n \"updatedExisting\" : true,\n \"n\" : 1,\n \"syncMillis\" : 0,\n \"writtenTo\" : null,\n \"err\" : null,\n \"ok\" : 1\n },\n value\" : {\n \"_id\" : ObjectId(\"54f62d2885e4be1f982b9c9c\"),\n \"name\" : \"Tom\",\n \"state\" : \"active\",\n \"rating\" : 100,\n \"score\" : 5\n },\n \"ok\" : 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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastErrorObject"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"connectionId"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"updatedExisting"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"syncMillis"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"writtenTo"</span> <!-- -->: <span class="lg-highlight-literal">null</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"err"</span> <!-- -->: <span class="lg-highlight-literal">null</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</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"> <!-- -->value<span class="lg-highlight-string">" : {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "</span>_id<span class="lg-highlight-string">" : ObjectId("</span>54f62d2885e4be1f982b9c9c<span class="lg-highlight-string">"),</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "</span>name<span class="lg-highlight-string">" : "</span><span class="lg-highlight-title lg-highlight-class">Tom</span><span class="lg-highlight-string">",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "</span>state<span class="lg-highlight-string">" : "</span>active<span class="lg-highlight-string">",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "</span>rating<span class="lg-highlight-string">" : 100,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "</span>score<span class="lg-highlight-string">" : 5</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> },</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "</span>ok<span class="lg-highlight-string">" : 1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">}</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> </li> </ul> </li> </ol> <p class="leafygreen-ui-1kp3ins"> To return the updated document in the <code class="leafygreen-ui-1l06pbn"> value </code> field, add the <code class="leafygreen-ui-1l06pbn"> new:true </code> option to the command. </p> <p class="leafygreen-ui-1kp3ins"> If no document match the <code class="leafygreen-ui-1l06pbn"> query </code> condition, the command returns a document that contains <code class="leafygreen-ui-1l06pbn"> null </code> in the <code class="leafygreen-ui-1l06pbn"> value </code> field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"value\" : null, \"ok\" : 1 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-string">"ok"</span> <!-- -->: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> <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> and many <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-driver"> drivers </a> provide a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify"> <code class="leafygreen-ui-1l06pbn"> findAndModify() </code> </a> helper method. Using the shell helper, this previous operation can take the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.findAndModify( {\n query: { name: \"Tom\", state: \"active\", rating: { $gt: 10 } },\n sort: { rating: 1 },\n update: { $inc: { score: 1 } }\n} );","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">people</span>.<span class="lg-highlight-title lg-highlight-function">findAndModify</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Tom"</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"active"</span>, <span class="lg-highlight-attr">rating</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">10</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sort</span>: <!-- -->{ <span class="lg-highlight-attr">rating</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-attr">score</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> <p class="leafygreen-ui-1kp3ins"> However, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify"> <code class="leafygreen-ui-1l06pbn"> findAndModify() </code> </a> shell helper method returns only the unmodified document, or if <code class="leafygreen-ui-1l06pbn"> new </code> is <code class="leafygreen-ui-1l06pbn"> true </code> , the updated document. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"54f62d2885e4be1f982b9c9c\"),\n \"name\" : \"Tom\",\n \"state\" : \"active\",\n \"rating\" : 100,\n \"score\" : 5\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"54f62d2885e4be1f982b9c9c"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Tom"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"active"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"rating"</span> <!-- -->: <span class="lg-highlight-number">100</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span> <!-- -->: <span class="lg-highlight-number">5</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> upsert: true </code> <a class="headerlink leafygreen-ui-1kepx47" href="#upsert--true" 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="upsert--true"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> command includes the <code class="leafygreen-ui-1l06pbn"> upsert: true </code> option for the <code class="leafygreen-ui-1l06pbn"> update </code> operation to either update a matching document or, if no matching document exists, create a new document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n findAndModify: \"people\",\n query: { name: \"Gus\", state: \"active\", rating: 100 },\n sort: { rating: 1 },\n update: { $inc: { score: 1 } },\n upsert: true\n }\n )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <span class="lg-highlight-string">"people"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Gus"</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"active"</span>, <span class="lg-highlight-attr">rating</span>: <span class="lg-highlight-number">100</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sort</span>: <!-- -->{ <span class="lg-highlight-attr">rating</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">1</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> If the command finds a matching document, the command performs an update. </p> <p class="leafygreen-ui-1kp3ins"> If the command does <strong> not </strong> find a matching document, the <code class="leafygreen-ui-1l06pbn"> update </code> with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert"> upsert: true </a> operation results in an insertion and returns a document with the following fields: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> lastErrorObject </code> field that contains the details of the command, including the field <code class="leafygreen-ui-1l06pbn"> upserted </code> that contains the <code class="leafygreen-ui-1l06pbn"> _id </code> value of the newly inserted document, and </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> value </code> field containing <code class="leafygreen-ui-1l06pbn"> null </code> . </p> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"value\" : null,\n \"lastErrorObject\" : {\n \"updatedExisting\" : false,\n \"n\" : 1,\n \"upserted\" : ObjectId(\"54f62c8bc85d4472eadea26f\")\n },\n \"ok\" : 1\n}","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value"</span> : null,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastErrorObject"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"updatedExisting"</span> : <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"n"</span> : 1,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"upserted"</span> : ObjectId(<span class="lg-highlight-string">"54f62c8bc85d4472eadea26f"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</span> : 1</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Return New Document <a class="headerlink leafygreen-ui-1kepx47" href="#return-new-document" 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="return-new-document"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> command includes both <code class="leafygreen-ui-1l06pbn"> upsert: true </code> option and the <code class="leafygreen-ui-1l06pbn"> new:true </code> option. The command either updates a matching document and returns the updated document or, if no matching document exists, inserts a document and returns the newly inserted document in the <code class="leafygreen-ui-1l06pbn"> value </code> field. </p> <p class="leafygreen-ui-1kp3ins"> In the following example, no document in the <code class="leafygreen-ui-1l06pbn"> people </code> collection matches the <code class="leafygreen-ui-1l06pbn"> query </code> condition: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n findAndModify: \"people\",\n query: { name: \"Pascal\", state: \"active\", rating: 25 },\n sort: { rating: 1 },\n update: { $inc: { score: 1 } },\n upsert: true,\n new: true\n }\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <span class="lg-highlight-string">"people"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Pascal"</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"active"</span>, <span class="lg-highlight-attr">rating</span>: <span class="lg-highlight-number">25</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sort</span>: <!-- -->{ <span class="lg-highlight-attr">rating</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">1</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">new</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The command returns the newly inserted document in the <code class="leafygreen-ui-1l06pbn"> value </code> field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"lastErrorObject\" : {\n \"connectionId\" : 1,\n \"updatedExisting\" : false,\n \"upserted\" : ObjectId(\"54f62bbfc85d4472eadea26d\"),\n \"n\" : 1,\n \"syncMillis\" : 0,\n \"writtenTo\" : null,\n \"err\" : null,\n \"ok\" : 1\n },\n \"value\" : {\n \"_id\" : ObjectId(\"54f62bbfc85d4472eadea26d\"),\n \"name\" : \"Pascal\",\n \"rating\" : 25,\n \"state\" : \"active\",\n \"score\" : 1\n },\n \"ok\" : 1\n}","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastErrorObject"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"connectionId"</span> : 1,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"updatedExisting"</span> : <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"upserted"</span> : ObjectId(<span class="lg-highlight-string">"54f62bbfc85d4472eadea26d"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"n"</span> : 1,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"syncMillis"</span> : 0,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"writtenTo"</span> : null,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"err"</span> : null,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</span> : 1</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"54f62bbfc85d4472eadea26d"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> : <span class="lg-highlight-string">"Pascal"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"rating"</span> : 25,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> : <span class="lg-highlight-string">"active"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span> : 1</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</span> : 1</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Sort and Remove <a class="headerlink leafygreen-ui-1kepx47" href="#sort-and-remove" 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="sort-and-remove"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> By including a <code class="leafygreen-ui-1l06pbn"> sort </code> specification on the <code class="leafygreen-ui-1l06pbn"> rating </code> field, the following example removes from the <code class="leafygreen-ui-1l06pbn"> people </code> collection a single document with the <code class="leafygreen-ui-1l06pbn"> state </code> value of <code class="leafygreen-ui-1l06pbn"> active </code> and the lowest <code class="leafygreen-ui-1l06pbn"> rating </code> among the matching documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n findAndModify: \"people\",\n query: { state: \"active\" },\n sort: { rating: 1 },\n remove: true\n }\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <span class="lg-highlight-string">"people"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"active"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sort</span>: <!-- -->{ <span class="lg-highlight-attr">rating</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">remove</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The command returns the deleted document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"lastErrorObject\" : {\n \"connectionId\" : 1,\n \"n\" : 1,\n \"syncMillis\" : 0,\n \"writtenTo\" : null,\n \"err\" : null,\n \"ok\" : 1\n },\n \"value\" : {\n \"_id\" : ObjectId(\"54f62a6785e4be1f982b9c9b\"),\n \"name\" : \"XYZ123\",\n \"score\" : 1,\n \"state\" : \"active\",\n \"rating\" : 3\n },\n \"ok\" : 1\n}","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastErrorObject"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"connectionId"</span> : 1,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"n"</span> : 1,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"syncMillis"</span> : 0,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"writtenTo"</span> : null,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"err"</span> : null,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</span> : 1</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"54f62a6785e4be1f982b9c9b"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> : <span class="lg-highlight-string">"XYZ123"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span> : 1,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> : <span class="lg-highlight-string">"active"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"rating"</span> : 3</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</span> : 1</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Specify Collation <a class="headerlink leafygreen-ui-1kepx47" href="#specify-collation" 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="specify-collation"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> Collation </a> allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks. </p> <p class="leafygreen-ui-1kp3ins"> A collection <code class="leafygreen-ui-1l06pbn"> myColl </code> has the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 1, category: \"café\", status: \"A\" }\n{ _id: 2, category: \"cafe\", status: \"a\" }\n{ _id: 3, category: \"cafE\", status: \"a\" }","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">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"café"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"A"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafe"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"a"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafE"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"a"</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> <p class="leafygreen-ui-1kp3ins"> The following operation includes the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> collation </a> option: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n findAndModify: \"myColl\",\n query: { category: \"cafe\", status: \"a\" },\n sort: { category: 1 },\n update: { $set: { status: \"Updated\" } },\n collation: { locale: \"fr\", strength: 1 }\n }\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <span class="lg-highlight-string">"myColl"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafe"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"a"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sort</span>: <!-- -->{ <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"Updated"</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">collation</span>: <!-- -->{ <span class="lg-highlight-attr">locale</span>: <span class="lg-highlight-string">"fr"</span>, <span class="lg-highlight-attr">strength</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">)</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"> The operation returns the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"lastErrorObject\" : {\n \"updatedExisting\" : true,\n \"n\" : 1\n },\n \"value\" : {\n \"_id\" : 1,\n \"category\" : \"café\",\n \"status\" : \"A\"\n },\n \"ok\" : 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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastErrorObject"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"updatedExisting"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"n"</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"> <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"category"</span> <!-- -->: <span class="lg-highlight-string">"café"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-findAndModify-command-arrayFilters"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Array Update Operations with <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> <a class="headerlink leafygreen-ui-1kepx47" href="#array-update-operations-with-arrayfilters" 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="array-update-operations-with-arrayfilters"> </div> </a> </h3> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> is not available for updates that use an aggregation pipeline. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> When updating an array field, you can specify <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> that determine which array elements to update. </p> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Update Elements Match <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> Criteria <a class="headerlink leafygreen-ui-1kepx47" href="#update-elements-match-arrayfilters-criteria" 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="update-elements-match-arrayfilters-criteria"> </div> </a> </h4> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> is not available for updates that use an aggregation pipeline. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Create a collection <code class="leafygreen-ui-1l06pbn"> students </code> with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.insertMany( [\n { \"_id\" : 1, \"grades\" : [ 95, 92, 90 ] },\n { \"_id\" : 2, \"grades\" : [ 98, 100, 102 ] },\n { \"_id\" : 3, \"grades\" : [ 95, 110, 100 ] }\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">db.<span class="lg-highlight-property">students</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">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">92</span>, <span class="lg-highlight-number">90</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">98</span>, <span class="lg-highlight-number">100</span>, <span class="lg-highlight-number">102</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">110</span>, <span class="lg-highlight-number">100</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> <p class="leafygreen-ui-1kp3ins"> To update all elements that are greater than or equal to <code class="leafygreen-ui-1l06pbn"> 100 </code> in the <code class="leafygreen-ui-1l06pbn"> grades </code> array, use the positional <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/positional-filtered/#mongodb-update-up.---identifier--"> <code class="leafygreen-ui-1l06pbn"> $[&lt;identifier&gt;] </code> </a> operator with the <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> option: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n findAndModify: \"students\",\n query: { grades: { $gte: 100 } },\n update: { $set: { \"grades.$[element]\" : 100 } },\n arrayFilters: [ { \"element\": { $gte: 100 } } ]\n }\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <span class="lg-highlight-string">"students"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">grades</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-number">100</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"grades.$[element]"</span> <!-- -->: <span class="lg-highlight-number">100</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">arrayFilters</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"element"</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-number">100</span> } } ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The operation updates the <code class="leafygreen-ui-1l06pbn"> grades </code> field for a single document, and after the operation, the collection has the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"grades\" : [ 95, 92, 90 ] }\n{ \"_id\" : 2, \"grades\" : [ 98, 100, 100 ] }\n{ \"_id\" : 3, \"grades\" : [ 95, 110, 100 ] }","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">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">92</span>, <span class="lg-highlight-number">90</span> ] }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">98</span>, <span class="lg-highlight-number">100</span>, <span class="lg-highlight-number">100</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">110</span>, <span class="lg-highlight-number">100</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> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Update Specific Elements of an Array of Documents <a class="headerlink leafygreen-ui-1kepx47" href="#update-specific-elements-of-an-array-of-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="update-specific-elements-of-an-array-of-documents"> </div> </a> </h4> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> is not available for updates that use an aggregation pipeline. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Create a collection <code class="leafygreen-ui-1l06pbn"> students2 </code> with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.insertMany( [\n {\n \"_id\" : 1,\n \"grades\" : [\n { \"grade\" : 80, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 85, \"mean\" : 90, \"std\" : 4 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 6 }\n ]\n },\n {\n \"_id\" : 2,\n \"grades\" : [\n { \"grade\" : 90, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 87, \"mean\" : 90, \"std\" : 3 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 4 }\n ]\n }\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">db.<span class="lg-highlight-property">students2</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">87</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The following operation finds a document where the <code class="leafygreen-ui-1l06pbn"> _id </code> field equals <code class="leafygreen-ui-1l06pbn"> 1 </code> and uses the filtered positional operator <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/positional-filtered/#mongodb-update-up.---identifier--"> <code class="leafygreen-ui-1l06pbn"> $[&lt;identifier&gt;] </code> </a> with the <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> to update the <code class="leafygreen-ui-1l06pbn"> mean </code> for all elements in the <code class="leafygreen-ui-1l06pbn"> grades </code> array where the grade is greater than or equal to <code class="leafygreen-ui-1l06pbn"> 85 </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n findAndModify: \"students2\",\n query: { _id : 1 },\n update: { $set: { \"grades.$[elem].mean\" : 100 } },\n arrayFilters: [ { \"elem.grade\": { $gte: 85 } } ]\n }\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <span class="lg-highlight-string">"students2"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"grades.$[elem].mean"</span> <!-- -->: <span class="lg-highlight-number">100</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">arrayFilters</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"elem.grade"</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-number">85</span> } } ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The operation updates the <code class="leafygreen-ui-1l06pbn"> grades </code> field for a single document, and after the operation, the collection has the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n \"grades\" : [\n { \"grade\" : 80, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 85, \"mean\" : 100, \"std\" : 4 },\n { \"grade\" : 85, \"mean\" : 100, \"std\" : 6 }\n ]\n}\n{\n \"_id\" : 2,\n \"grades\" : [\n { \"grade\" : 90, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 87, \"mean\" : 90, \"std\" : 3 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 4 }\n ]\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">100</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">100</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">87</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-cmdfindOneAndUpdate-agg-pipeline"> </span> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Use an Aggregation Pipeline for Updates <a class="headerlink leafygreen-ui-1kepx47" href="#use-an-aggregation-pipeline-for-updates" 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="use-an-aggregation-pipeline-for-updates"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.findAndModify" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </span> </a> can accept an aggregation pipeline for the update. The pipeline can consist of the following stages: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceRoot/#mongodb-pipeline-pipe.-replaceRoot"> <code class="leafygreen-ui-1l06pbn"> $replaceRoot </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith"> <code class="leafygreen-ui-1l06pbn"> $replaceWith </code> . </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Using the aggregation pipeline allows for a more expressive update statement, such as expressing conditional updates based on current field values or updating one field using the value of another field(s). </p> <p class="leafygreen-ui-1kp3ins"> For example, create a collection <code class="leafygreen-ui-1l06pbn"> students2 </code> with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.insertMany( [\n {\n \"_id\" : 1,\n \"grades\" : [\n { \"grade\" : 80, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 85, \"mean\" : 90, \"std\" : 4 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 6 }\n ]\n },\n {\n \"_id\" : 2,\n \"grades\" : [\n { \"grade\" : 90, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 87, \"mean\" : 90, \"std\" : 3 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 4 }\n ]\n }\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">db.<span class="lg-highlight-property">students2</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">87</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The following operation finds a document where the <code class="leafygreen-ui-1l06pbn"> _id </code> field equals <code class="leafygreen-ui-1l06pbn"> 1 </code> and uses an aggregation pipeline to calculate a new field <code class="leafygreen-ui-1l06pbn"> total </code> from the <code class="leafygreen-ui-1l06pbn"> grades </code> field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n findAndModify: \"students2\",\n query: { \"_id\" : 1 },\n update: [ { $set: { \"total\" : { $sum: \"$grades.grade\" } } } ],\n new: true\n }\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <span class="lg-highlight-string">"students2"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"total"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$grades.grade"</span> } } } ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">new</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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 class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $set </code> used in the pipeline refers to the aggregation stage <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> and not the update operator <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/set/#mongodb-update-up.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> . </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> After the operation, the collection has the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n \"grades\" : [ { \"grade\" : 80, \"mean\" : 75, \"std\" : 6 }, { \"grade\" : 85, \"mean\" : 90, \"std\" : 4 }, { \"grade\" : 85, \"mean\" :85, \"std\" : 6 } ],\n \"total\" : 250\n}\n{\n \"_id\" : 2,\n \"grades\" : [ { \"grade\" : 90, \"mean\" : 75, \"std\" : 6 }, { \"grade\" : 87, \"mean\" : 90, \"std\" : 3 }, { \"grade\" : 85, \"mean\" : 85,\"std\" : 4 } ]\n}","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->:<span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> } ]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">250</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">87</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">3</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>,<span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-ex-findAndModify-hint"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Specify <code class="leafygreen-ui-1l06pbn"> hint </code> for <code class="leafygreen-ui-1l06pbn"> findAndModify </code> Operations <a class="headerlink leafygreen-ui-1kepx47" href="#specify-hint-for-findandmodify-operations" 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="specify-hint-for-findandmodify-operations"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> In <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> , create a <code class="leafygreen-ui-1l06pbn"> members </code> collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.insertMany( [\n { \"_id\" : 1, \"member\" : \"abc123\", \"status\" : \"P\", \"points\" : 0, \"misc1\" : null, \"misc2\" : null },\n { \"_id\" : 2, \"member\" : \"xyz123\", \"status\" : \"A\", \"points\" : 60, \"misc1\" : \"reminder: ping me at 100pts\", \"misc2\" : \"Some random comment\" },\n { \"_id\" : 3, \"member\" : \"lmn123\", \"status\" : \"P\", \"points\" : 0, \"misc1\" : null, \"misc2\" : null },\n { \"_id\" : 4, \"member\" : \"pqr123\", \"status\" : \"D\", \"points\" : 20, \"misc1\" : \"Deactivated\", \"misc2\" : null },\n { \"_id\" : 5, \"member\" : \"ijk123\", \"status\" : \"P\", \"points\" : 0, \"misc1\" : null, \"misc2\" : null },\n { \"_id\" : 6, \"member\" : \"cde123\", \"status\" : \"A\", \"points\" : 86, \"misc1\" : \"reminder: ping me at 100pts\", \"misc2\" : \"Some random comment\" }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">members</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">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"member"</span> <!-- -->: <span class="lg-highlight-string">"abc123"</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"P"</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"misc1"</span> <!-- -->: <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-string">"misc2"</span> <!-- -->: <span class="lg-highlight-literal">null</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"member"</span> <!-- -->: <span class="lg-highlight-string">"xyz123"</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">60</span>, <span class="lg-highlight-string">"misc1"</span> <!-- -->: <span class="lg-highlight-string">"reminder: ping me at 100pts"</span>, <span class="lg-highlight-string">"misc2"</span> <!-- -->: <span class="lg-highlight-string">"Some random comment"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"member"</span> <!-- -->: <span class="lg-highlight-string">"lmn123"</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"P"</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"misc1"</span> <!-- -->: <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-string">"misc2"</span> <!-- -->: <span class="lg-highlight-literal">null</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"member"</span> <!-- -->: <span class="lg-highlight-string">"pqr123"</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"D"</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-string">"misc1"</span> <!-- -->: <span class="lg-highlight-string">"Deactivated"</span>, <span class="lg-highlight-string">"misc2"</span> <!-- -->: <span class="lg-highlight-literal">null</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"member"</span> <!-- -->: <span class="lg-highlight-string">"ijk123"</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"P"</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"misc1"</span> <!-- -->: <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-string">"misc2"</span> <!-- -->: <span class="lg-highlight-literal">null</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"member"</span> <!-- -->: <span class="lg-highlight-string">"cde123"</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">86</span>, <span class="lg-highlight-string">"misc1"</span> <!-- -->: <span class="lg-highlight-string">"reminder: ping me at 100pts"</span>, <span class="lg-highlight-string">"misc2"</span> <!-- -->: <span class="lg-highlight-string">"Some random comment"</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> <p class="leafygreen-ui-1kp3ins"> Create the following indexes on the collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.createIndex( { status: 1 } )\ndb.members.createIndex( { points: 1 } )","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">db.<span class="lg-highlight-property">members</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-number">1</span> } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">members</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-attr">points</span>: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> The following operation explicitly hints to use the index <code class="leafygreen-ui-1l06pbn"> { status: 1 } </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand({\n findAndModify: \"members\",\n query: { \"points\": { $lte: 20 }, \"status\": \"P\" },\n remove: true,\n hint: { status: 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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <span class="lg-highlight-string">"members"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-string">"points"</span>: <!-- -->{ <span class="lg-highlight-attr">$lte</span>: <span class="lg-highlight-number">20</span> }<!-- -->, <span class="lg-highlight-string">"status"</span>: <span class="lg-highlight-string">"P"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">remove</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">hint</span>: <!-- -->{ <span class="lg-highlight-attr">status</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 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 specify an index that does not exist, the operation errors. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> To see the index used, run <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/explain/#mongodb-dbcommand-dbcmd.explain"> <code class="leafygreen-ui-1l06pbn"> explain </code> </a> on the operation: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n explain: {\n findAndModify: \"members\",\n query: { \"points\": { $lte: 20 }, \"status\": \"P\" },\n remove: true,\n hint: { status: 1 }\n },\n verbosity: \"queryPlanner\"\n }\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">explain</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <span class="lg-highlight-string">"members"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-string">"points"</span>: <!-- -->{ <span class="lg-highlight-attr">$lte</span>: <span class="lg-highlight-number">20</span> }<!-- -->, <span class="lg-highlight-string">"status"</span>: <span class="lg-highlight-string">"P"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">remove</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">hint</span>: <!-- -->{ <span class="lg-highlight-attr">status</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"> <span class="lg-highlight-attr">verbosity</span>: <span class="lg-highlight-string">"queryPlanner"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-findAndModify-let-example"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Use Variables in <code class="leafygreen-ui-1l06pbn"> let </code> <a class="headerlink leafygreen-ui-1kepx47" href="#use-variables-in-let" 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="use-variables-in-let"> </div> </a> </h3> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> To define variables that you can access elsewhere in the command, use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-findAndModify-let-syntax" target="_self"> <span> let </span> </a> option. </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"> To filter results using a variable, you must access the variable within the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr"> <code class="leafygreen-ui-1l06pbn"> $expr </code> </a> operator. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Create a collection <code class="leafygreen-ui-1l06pbn"> cakeFlavors </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeFlavors.insertMany( [\n { _id: 1, flavor: \"chocolate\" },\n { _id: 2, flavor: \"strawberry\" },\n { _id: 3, flavor: \"cherry\" }\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">db.<span class="lg-highlight-property">cakeFlavors</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"chocolate"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"strawberry"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"cherry"</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> <p class="leafygreen-ui-1kp3ins"> The following example defines a <code class="leafygreen-ui-1l06pbn"> targetFlavor </code> variable in <code class="leafygreen-ui-1l06pbn"> let </code> and uses the variable to change the cake flavor from cherry to orange: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeFlavors.runCommand( {\n findAndModify: db.cakeFlavors.getName(),\n query: { $expr: { $eq: [ \"$flavor\", \"$$targetFlavor\" ] } },\n update: { flavor: \"orange\" },\n let: { targetFlavor: \"cherry\" }\n} )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">cakeFlavors</span>.<span class="lg-highlight-title lg-highlight-function">runCommand</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">findAndModify</span>: <!-- -->db.<span class="lg-highlight-property">cakeFlavors</span>.<span class="lg-highlight-title lg-highlight-function">getName</span>(<!-- -->)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">$expr</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <span class="lg-highlight-string">"$flavor"</span>, <span class="lg-highlight-string">"$$targetFlavor"</span> ] } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"orange"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">let</span>: <!-- -->{ <span class="lg-highlight-attr">targetFlavor</span>: <span class="lg-highlight-string">"cherry"</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> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $unset (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-unset--aggregation-" 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="-unset--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self"> <span> Considerations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Disambiguation </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The following page refers to the aggregation stage <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unset" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unset </code> </span> </a> . For the update operator <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/unset/#mongodb-update-up.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> , see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/unset/#mongodb-update-up.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> . </a> </p> </div> </div> <dl class="pipeline"> <dt> <code class="leafygreen-ui-1l06pbn"> $unset </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-pipeline-pipe.-unset" title="Permalink to this definition"> <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="mongodb-pipeline-pipe.-unset"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Removes/excludes fields from documents. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unset" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unset </code> </span> </a> stage has the following syntax: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To remove a single field, the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unset" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unset </code> </span> </a> takes a string that specifies the field to remove: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $unset: \"&lt;field&gt;\" }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$unset</span>: <span class="lg-highlight-string">"&lt;field&gt;"</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To remove multiple fields, the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unset" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unset </code> </span> </a> takes an array of fields to remove. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $unset: [ \"&lt;field1&gt;\", \"&lt;field2&gt;\", ... ] }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$unset</span>: <!-- -->[ <span class="lg-highlight-string">"&lt;field1&gt;"</span>, <span class="lg-highlight-string">"&lt;field2&gt;"</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> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> $unset </code> and <code class="leafygreen-ui-1l06pbn"> $project </code> <a class="headerlink leafygreen-ui-1kepx47" href="#-unset-and--project" 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="-unset-and--project"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unset" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unset </code> </span> </a> is an alias for the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> stage that removes/excludes fields: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $project: { \"&lt;field1&gt;\": 0, \"&lt;field2&gt;\": 0, ... } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-string">"&lt;field1&gt;"</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"&lt;field2&gt;"</span>: <span class="lg-highlight-number">0</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Embedded Fields <a class="headerlink leafygreen-ui-1kepx47" href="#embedded-fields" 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="embedded-fields"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To remove/exclude a field or fields within an embedded document, you can use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-dot-notation"> dot notation </a> , as in: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $unset: \"&lt;field.nestedfield&gt;\" }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$unset</span>: <span class="lg-highlight-string">"&lt;field.nestedfield&gt;"</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> <p class="leafygreen-ui-1kp3ins"> or </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $unset: [ \"&lt;field1.nestedfield&gt;\", ...] }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$unset</span>: <!-- -->[ <span class="lg-highlight-string">"&lt;field1.nestedfield&gt;"</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> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Create a sample <code class="leafygreen-ui-1l06pbn"> books </code> collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.insertMany([\n { \"_id\" : 1, title: \"Antelope Antics\", isbn: \"0001122223334\", author: { last:\"An\", first: \"Auntie\" }, copies: [ { warehouse: \"A\", qty: 5 }, { warehouse: \"B\", qty: 15 } ] },\n { \"_id\" : 2, title: \"Bees Babble\", isbn: \"999999999333\", author: { last:\"Bumble\", first: \"Bee\" }, copies: [ { warehouse: \"A\", qty: 2 }, { warehouse: \"B\", qty: 5 } ] }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">books</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">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"Antelope Antics"</span>, <span class="lg-highlight-attr">isbn</span>: <span class="lg-highlight-string">"0001122223334"</span>, <span class="lg-highlight-attr">author</span>: <!-- -->{ <span class="lg-highlight-attr">last</span>:<span class="lg-highlight-string">"An"</span>, <span class="lg-highlight-attr">first</span>: <span class="lg-highlight-string">"Auntie"</span> }<!-- -->, <span class="lg-highlight-attr">copies</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">warehouse</span>: <span class="lg-highlight-string">"A"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">5</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">warehouse</span>: <span class="lg-highlight-string">"B"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">15</span> } ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"Bees Babble"</span>, <span class="lg-highlight-attr">isbn</span>: <span class="lg-highlight-string">"999999999333"</span>, <span class="lg-highlight-attr">author</span>: <!-- -->{ <span class="lg-highlight-attr">last</span>:<span class="lg-highlight-string">"Bumble"</span>, <span class="lg-highlight-attr">first</span>: <span class="lg-highlight-string">"Bee"</span> }<!-- -->, <span class="lg-highlight-attr">copies</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">warehouse</span>: <span class="lg-highlight-string">"A"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">2</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">warehouse</span>: <span class="lg-highlight-string">"B"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">5</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> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Remove a Single Field <a class="headerlink leafygreen-ui-1kepx47" href="#remove-a-single-field" 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="remove-a-single-field"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following example removes the top-level field <code class="leafygreen-ui-1l06pbn"> copies </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.aggregate([ { $unset: \"copies\" } ])","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$unset</span>: <span class="lg-highlight-string">"copies"</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> <p class="leafygreen-ui-1kp3ins"> Alternatively, you can also use the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.aggregate([ { $unset: [ \"copies\" ] } ])","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$unset</span>: <!-- -->[ <span class="lg-highlight-string">"copies"</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> <p class="leafygreen-ui-1kp3ins"> Either operation returns the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"title\" : \"Antelope Antics\", \"isbn\" : \"0001122223334\", \"author\" : { \"last\" : \"An\", \"first\" : \"Auntie\" } }\n{ \"_id\" : 2, \"title\" : \"Bees Babble\", \"isbn\" : \"999999999333\", \"author\" : { \"last\" : \"Bumble\", \"first\" : \"Bee\" } }","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"Antelope Antics"</span>, <span class="lg-highlight-string">"isbn"</span> <!-- -->: <span class="lg-highlight-string">"0001122223334"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"An"</span>, <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"Auntie"</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"Bees Babble"</span>, <span class="lg-highlight-string">"isbn"</span> <!-- -->: <span class="lg-highlight-string">"999999999333"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"Bumble"</span>, <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"Bee"</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Remove Top-Level Fields <a class="headerlink leafygreen-ui-1kepx47" href="#remove-top-level-fields" 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="remove-top-level-fields"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following example removes the top-level fields <code class="leafygreen-ui-1l06pbn"> isbn </code> and <code class="leafygreen-ui-1l06pbn"> copies </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.aggregate([\n { $unset: [ \"isbn\", \"copies\" ] }\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">db.<span class="lg-highlight-property">books</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">$unset</span>: <!-- -->[ <span class="lg-highlight-string">"isbn"</span>, <span class="lg-highlight-string">"copies"</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> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unset" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unset </code> </span> </a> operation outputs the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"title\" : \"Antelope Antics\", \"author\" : { \"last\" : \"An\", \"first\" : \"Auntie\" } }\n{ \"_id\" : 2, \"title\" : \"Bees Babble\", \"author\" : { \"last\" : \"Bumble\", \"first\" : \"Bee\" } }","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"Antelope Antics"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"An"</span>, <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"Auntie"</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"Bees Babble"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"Bumble"</span>, <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"Bee"</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Remove Embedded Fields <a class="headerlink leafygreen-ui-1kepx47" href="#remove-embedded-fields" 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="remove-embedded-fields"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following example removes the top-level field <code class="leafygreen-ui-1l06pbn"> isbn </code> , the embedded field <code class="leafygreen-ui-1l06pbn"> first </code> (from the <code class="leafygreen-ui-1l06pbn"> name </code> document) and the embedded field <code class="leafygreen-ui-1l06pbn"> warehouse </code> (from the elements in the <code class="leafygreen-ui-1l06pbn"> copies </code> array): </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.aggregate([\n { $unset: [ \"isbn\", \"author.first\", \"copies.warehouse\" ] }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">books</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">$unset</span>: <!-- -->[ <span class="lg-highlight-string">"isbn"</span>, <span class="lg-highlight-string">"author.first"</span>, <span class="lg-highlight-string">"copies.warehouse"</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> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unset" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unset </code> </span> </a> operation outputs the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"title\" : \"Antelope Antics\", \"author\" : { \"last\" : \"An\" }, \"copies\" : [ { \"qty\" : 5 }, { \"qty\" : 15 } ] }\n{ \"_id\" : 2, \"title\" : \"Bees Babble\", \"author\" : { \"last\" : \"Bumble\" }, \"copies\" : [ { \"qty\" : 2 }, { \"qty\" : 5 } ] }","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"Antelope Antics"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"An"</span> }<!-- -->, <span class="lg-highlight-string">"copies"</span> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">5</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">15</span> } ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"Bees Babble"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"Bumble"</span> }<!-- -->, <span class="lg-highlight-string">"copies"</span> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">2</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">5</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> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/interface/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Aggregation Commands <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-commands" 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="aggregation-commands"> </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="#aggregation-commands-1" target="_self"> <span> Aggregation Commands </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#aggregation-methods" target="_self"> <span> Aggregation Methods </span> </a> </li> </ul> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> For details on a specific operator, including syntax and examples, click on the link to the operator's reference page. </p> </div> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Aggregation Commands <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-commands-1" 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="aggregation-commands-1"> </div> </a> </h2> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate"> <code class="leafygreen-ui-1l06pbn"> aggregate </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Performs <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation tasks </a> such as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> using an aggregation pipeline. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/count/#mongodb-dbcommand-dbcmd.count"> <code class="leafygreen-ui-1l06pbn"> count </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Counts the number of documents in a collection or a view. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/distinct/#mongodb-dbcommand-dbcmd.distinct"> <code class="leafygreen-ui-1l06pbn"> distinct </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Displays the distinct values found for a specified key in a collection or a view. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce"> <code class="leafygreen-ui-1l06pbn"> mapReduce </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Performs <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce"> map-reduce </a> aggregation for large data sets. </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Aggregation Methods <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-methods" 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="aggregation-methods"> </div> </a> </h2> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Provides access to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline <!-- --> . </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.mapReduce/#mongodb-method-db.collection.mapReduce"> <code class="leafygreen-ui-1l06pbn"> db.collection.mapReduce() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Performs <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce"> map-reduce </a> aggregation for large data sets. </div> </div> </td> </tr> </tbody> </table> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $unionWith (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-unionwith--aggregation-" 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="-unionwith--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self"> <span> Considerations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#duplicate-results" target="_self"> <span> Duplicate Results </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#-unionwith-a-sharded-collection" target="_self"> <span> <code class="css-1kekw28 e1wawog0"> $unionWith </code> a Sharded Collection </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#collation" target="_self"> <span> Collation </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#atlas-search-support" target="_self"> <span> Atlas Search Support </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#restrictions" target="_self"> <span> Restrictions </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-sales-reports-from-the-union-of-yearly-data-collections" target="_self"> <span> Create Sales Reports from the Union of Yearly Data Collections </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#report-1--all-sales-by-year-and-stores-and-items" target="_self"> <span> Report 1: All Sales by Year and Stores and Items </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#report-2--aggregated-sales-by-items" target="_self"> <span> Report 2: Aggregated Sales by Items </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-a-union-with-specified-documents" target="_self"> <span> Create a Union with Specified Documents </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#namespaces-in-subpipelines" target="_self"> <span> Namespaces in Subpipelines </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="pipeline"> <dt> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-pipeline-pipe.-unionWith" title="Permalink to this definition"> <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="mongodb-pipeline-pipe.-unionWith"> </div> </a> </dt> <dd> <div> <p> <em> Changed <!-- --> in version <!-- --> 8.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Combines two aggregations into a single result set. <code class="leafygreen-ui-1l06pbn"> $unionWith </code> outputs the combined result set (including duplicates) to the next stage. </p> <p class="leafygreen-ui-1kp3ins"> The order in which the combined result set documents are output is unspecified. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $unionWith </code> stage has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $unionWith: { coll: \"&lt;collection&gt;\", pipeline: [ &lt;stage1&gt;, ... ] } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$unionWith</span>: <!-- -->{ <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"&lt;collection&gt;"</span>, <span class="lg-highlight-attr">pipeline</span>: <!-- -->[ &lt;<!-- -->stage1<!-- -->&gt;<!-- -->,<!-- --> <!-- -->...<!-- --> ] } }</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 include all documents from the specified collection without any processing, you can use the simplified form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $unionWith: \"&lt;collection&gt;\" } // Include all documents from the specified collection","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$unionWith</span>: <span class="lg-highlight-string">"&lt;collection&gt;"</span> } <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Include all documents </span><span class="lg-highlight-comment">from the specified collection</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> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $unionWith </code> stage takes a document with the following fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:10%"/> <col style="width:10%"/> <col style="width:20%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Necessity </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-unionWith-coll" target="_self"> <span> coll </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Required if <code class="leafygreen-ui-1l06pbn"> pipeline </code> is omitted. Otherwise optional. </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-unionWith-coll"> </span> <p class="leafygreen-ui-1kp3ins"> The collection or view whose <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-unionWith-pipeline" target="_self"> <span> pipeline </span> </a> results you wish to include in the result set. </p> <p class="leafygreen-ui-1kp3ins"> If you omit the <code class="leafygreen-ui-1l06pbn"> coll </code> field, you must specify a <code class="leafygreen-ui-1l06pbn"> pipeline </code> field with a first stage of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/documents/#mongodb-pipeline-pipe.-documents"> <code class="leafygreen-ui-1l06pbn"> $documents </code> . </a> </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-unionWith-pipeline" target="_self"> <span> pipeline </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Required if <code class="leafygreen-ui-1l06pbn"> coll </code> is omitted. Otherwise optional. </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-unionWith-pipeline"> </span> <p class="leafygreen-ui-1kp3ins"> An aggregation pipeline to apply to the input documents. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If you specify <code class="leafygreen-ui-1l06pbn"> coll </code> , the pipeline applies to the documents in <code class="leafygreen-ui-1l06pbn"> coll </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If you omit <code class="leafygreen-ui-1l06pbn"> coll </code> , the pipeline applies to the documents in the pipeline's <code class="leafygreen-ui-1l06pbn"> $documents </code> stage. For an example, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-unionWith-example-specified-docs" target="_self"> <span> Create a Union with Specified Documents <!-- --> . </span> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The pipeline cannot include the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out"> <code class="leafygreen-ui-1l06pbn"> $out </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> stages. Starting in v6.0, the <code class="leafygreen-ui-1l06pbn"> pipeline </code> can contain the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self"> <span> Atlas Search </span> </a> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/search/#mongodb-pipeline-pipe.-search" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $search </code> </span> </a> stage as the first stage inside the pipeline. To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-fts-unionwith-behavior" target="_self"> <span> Atlas Search Support <!-- --> . </span> </a> </p> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unionWith" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </span> </a> operation would correspond to the following SQL statement: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"SELECT *\nFROM Collection1\nWHERE ...\nUNION ALL\nSELECT *\nFROM Collection2\nWHERE ...","programmingLanguage":"SQL"} </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 sql leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">SELECT</span> <span class="lg-highlight-operator">*</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">FROM</span> Collection1</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">WHERE</span> ...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">UNION</span> <span class="lg-highlight-keyword">ALL</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">SELECT</span> <span class="lg-highlight-operator">*</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">FROM</span> Collection2</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">WHERE</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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"> </div> </a> </h2> <span class="leafygreen-ui-1qnjd6d" id="std-label-unionWith-duplicate-results"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Duplicate Results <a class="headerlink leafygreen-ui-1kepx47" href="#duplicate-results" 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="duplicate-results"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The combined results from the previous stage and the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unionWith" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </span> </a> stage can include duplicates. </p> <p class="leafygreen-ui-1kp3ins"> For example, create a <code class="leafygreen-ui-1l06pbn"> suppliers </code> collection and a <code class="leafygreen-ui-1l06pbn"> warehouses </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.suppliers.insertMany([\n { _id: 1, supplier: \"Aardvark and Sons\", state: \"Texas\" },\n { _id: 2, supplier: \"Bears Run Amok.\", state: \"Colorado\"},\n { _id: 3, supplier: \"Squid Mark Inc. \", state: \"Rhode Island\" },\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">suppliers</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">supplier</span>: <span class="lg-highlight-string">"Aardvark and Sons"</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"Texas"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">supplier</span>: <span class="lg-highlight-string">"Bears Run Amok."</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"Colorado"</span>}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">supplier</span>: <span class="lg-highlight-string">"Squid Mark Inc. "</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"Rhode Island"</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> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.warehouses.insertMany([\n { _id: 1, warehouse: \"A\", region: \"West\", state: \"California\" },\n { _id: 2, warehouse: \"B\", region: \"Central\", state: \"Colorado\"},\n { _id: 3, warehouse: \"C\", region: \"East\", state: \"Florida\" },\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">warehouses</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">warehouse</span>: <span class="lg-highlight-string">"A"</span>, <span class="lg-highlight-attr">region</span>: <span class="lg-highlight-string">"West"</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"California"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">warehouse</span>: <span class="lg-highlight-string">"B"</span>, <span class="lg-highlight-attr">region</span>: <span class="lg-highlight-string">"Central"</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"Colorado"</span>}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">warehouse</span>: <span class="lg-highlight-string">"C"</span>, <span class="lg-highlight-attr">region</span>: <span class="lg-highlight-string">"East"</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"Florida"</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation combines the <code class="leafygreen-ui-1l06pbn"> state </code> field projection results from the <code class="leafygreen-ui-1l06pbn"> suppliers </code> and <code class="leafygreen-ui-1l06pbn"> warehouse </code> collections. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.suppliers.aggregate([\n { $project: { state: 1, _id: 0 } },\n { $unionWith: { coll: \"warehouses\", pipeline: [ { $project: { state: 1, _id: 0 } } ]} }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">suppliers</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">$project</span>: <!-- -->{ <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unionWith</span>: <!-- -->{ <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"warehouses"</span>, <span class="lg-highlight-attr">pipeline</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</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> <p class="leafygreen-ui-1kp3ins"> The result set contains duplicates: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"state\" : \"Texas\" }\n{ \"state\" : \"Colorado\" }\n{ \"state\" : \"Rhode Island\" }\n{ \"state\" : \"California\" }\n{ \"state\" : \"Colorado\" }\n{ \"state\" : \"Florida\" }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{ <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"Texas"</span> }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"Colorado"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"Rhode Island"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"California"</span> }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"Colorado"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"Florida"</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> To remove the duplicates, you can include a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage to group by the <code class="leafygreen-ui-1l06pbn"> state </code> field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.suppliers.aggregate([\n { $project: { state: 1, _id: 0 } },\n { $unionWith: { coll: \"warehouses\", pipeline: [ { $project: { state: 1, _id: 0 } } ]} },\n { $group: { _id: \"$state\" } }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">suppliers</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">$project</span>: <!-- -->{ <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unionWith</span>: <!-- -->{ <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"warehouses"</span>, <span class="lg-highlight-attr">pipeline</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span> } } ]} }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$state"</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> <p class="leafygreen-ui-1kp3ins"> The result set no longer contains duplicates: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":" { \"_id\" : \"California\" }\n { \"_id\" : \"Texas\" }\n { \"_id\" : \"Florida\" }\n { \"_id\" : \"Colorado\" }\n { \"_id\" : \"Rhode Island\" }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"California"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Texas"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Florida"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Colorado"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Rhode Island"</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> a Sharded Collection <a class="headerlink leafygreen-ui-1kepx47" href="#-unionwith-a-sharded-collection" 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="-unionwith-a-sharded-collection"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unionWith" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </span> </a> stage is part of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#std-label-lookup-join-pipeline"> $lookup pipeline </a> , the <code class="leafygreen-ui-1l06pbn"> $unionWith </code> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-unionWith-coll" target="_self"> <span> coll </span> </a> cannot be sharded. For example, in the following aggregation operation, the <code class="leafygreen-ui-1l06pbn"> inventory_q1 </code> collection cannot be sharded: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.suppliers.aggregate([\n {\n $lookup: {\n from: \"warehouses\",\n let: { order_item: \"$item\", order_qty: \"$ordered\" },\n pipeline: [\n ...\n { $unionWith: { coll: \"inventory_q1\", pipeline: [ ... ] } },\n ...\n ],\n as: \"stockdata\"\n }\n }\n])","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">suppliers</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</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">"warehouses"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">let</span>: <!-- -->{ <span class="lg-highlight-attr">order_item</span>: <span class="lg-highlight-string">"$item"</span>, <span class="lg-highlight-attr">order_qty</span>: <span class="lg-highlight-string">"$ordered"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pipeline</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unionWith</span>: <!-- -->{ <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"inventory_q1"</span>, <span class="lg-highlight-attr">pipeline</span>: <!-- -->[ <!-- -->...<!-- --> ] } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">as</span>: <span class="lg-highlight-string">"stockdata"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Collation <a class="headerlink leafygreen-ui-1kepx47" href="#collation" 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="collation"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> includes a <code class="leafygreen-ui-1l06pbn"> collation </code> document, that collation is used for the operation, ignoring any other collations. </p> <p class="leafygreen-ui-1kp3ins"> If the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> does not include a <code class="leafygreen-ui-1l06pbn"> collation </code> document, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> method uses the collation for the top-level collection/view on which the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> is run: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-unionWith-coll" target="_self"> <span> $unionWith coll </span> </a> is a collection, its collation is ignored. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-unionWith-coll" target="_self"> <span> $unionWith coll </span> </a> is a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/"> view </a> , then its collation must match that of the top-level collection/view. Otherwise, the operation errors. </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-fts-unionwith-behavior"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Atlas Search Support <a class="headerlink leafygreen-ui-1kepx47" href="#atlas-search-support" 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="atlas-search-support"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 6.0, you can specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self"> <span> Atlas Search </span> </a> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/search/#mongodb-pipeline-pipe.-search" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $search </code> </span> </a> or <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/searchMeta/#mongodb-pipeline-pipe.-searchMeta" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $searchMeta </code> </span> </a> stage in the <code class="leafygreen-ui-1l06pbn"> $unionWith </code> pipeline to search collections on the Atlas cluster. The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/search/#mongodb-pipeline-pipe.-search" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $search </code> </span> </a> or the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/searchMeta/#mongodb-pipeline-pipe.-searchMeta" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $searchMeta </code> </span> </a> stage must be the first stage inside the <code class="leafygreen-ui-1l06pbn"> $unionWith </code> pipeline. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-12"> <div aria-label="Tabs to describe usage of search/searchmeta" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_yirrfrtpn" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_e4w8bibwa" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> $search </div> </button> <button aria-controls="_2n53qiova" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ig6d74xqd" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> $searchMeta </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="_h1h9yjajf" class="" id="_ddx66keh3" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[{\n \"$unionWith\": {\n \"coll\": &lt;collection-name&gt;,\n \"pipeline\": [{\n \"$search\": {\n \"&lt;operator&gt;\": {\n &lt;operator-specification&gt;\n }\n },\n ...\n }]\n }\n}]"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "$unionWith": {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "coll": &lt;collection-name&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "pipeline": [{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> "$search": {</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> "&lt;operator&gt;": {</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> &lt;operator-specification&gt;</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}]</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_pfbo9mcpa" class="leafygreen-ui-38lglc" id="_wzsthfua1" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[{\n \"$unionWith\": {\n \"coll\": &lt;collection-name&gt;,\n \"pipeline\": [{\n \"$searchMeta\": {\n \"&lt;collector&gt;\": {\n &lt;collector-specification&gt;\n }\n },\n ...\n }]\n }\n}]"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "$unionWith": {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "coll": &lt;collection-name&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "pipeline": [{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> "$searchMeta": {</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> "&lt;collector&gt;": {</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> &lt;collector-specification&gt;</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}]</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> To see an example of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unionWith" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </span> </a> with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/search/#mongodb-pipeline-pipe.-search" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $search </code> </span> </a> , see the Atlas Search tutorial <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/tutorial/search-with-unionwith/" target="_self"> <span> Run an Atlas Search $search Query Using $unionWith <!-- --> . </span> </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Restrictions <a class="headerlink leafygreen-ui-1kepx47" href="#restrictions" 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="restrictions"> </div> </a> </h3> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Restrictions </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> transactions </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An aggregation pipeline cannot use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unionWith" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </span> </a> inside <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> transactions <!-- --> . </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Sharded Collection </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> If the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unionWith" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </span> </a> stage is part of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#std-label-lookup-join-pipeline"> $lookup pipeline </a> , the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-unionWith-coll" target="_self"> <span> $unionWith coll </span> </a> cannot be sharded. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out"> <code class="leafygreen-ui-1l06pbn"> $out </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-unionWith-pipeline" target="_self"> <span> $unionWith pipeline </span> </a> cannot include the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out"> <code class="leafygreen-ui-1l06pbn"> $out </code> </a> stage. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-unionWith-pipeline" target="_self"> <span> $unionWith pipeline </span> </a> cannot include the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> stage. </div> </div> </td> </tr> </tbody> </table> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create Sales Reports from the Union of Yearly Data Collections <a class="headerlink leafygreen-ui-1kepx47" href="#create-sales-reports-from-the-union-of-yearly-data-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="create-sales-reports-from-the-union-of-yearly-data-collections"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following examples use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unionWith" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </span> </a> stage to combine data and return results from multiple collections. In these examples, each collection contains a year of sales data. </p> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Populate Sample Data <a class="headerlink leafygreen-ui-1kepx47" href="#populate-sample-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="populate-sample-data"> </div> </a> </h4> <ol class="leafygreen-ui-rioki0" type="1"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create a <code class="leafygreen-ui-1l06pbn"> sales_2017 </code> collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales_2017.insertMany( [\n { store: \"General Store\", item: \"Chocolates\", quantity: 150 },\n { store: \"ShopMart\", item: \"Chocolates\", quantity: 50 },\n { store: \"General Store\", item: \"Cookies\", quantity: 100 },\n { store: \"ShopMart\", item: \"Cookies\", quantity: 120 },\n { store: \"General Store\", item: \"Pie\", quantity: 10 },\n { store: \"ShopMart\", item: \"Pie\", quantity: 5 }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales_2017</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">150</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">50</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">100</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">120</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">5</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create a <code class="leafygreen-ui-1l06pbn"> sales_2018 </code> collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales_2018.insertMany( [\n { store: \"General Store\", item: \"Cheese\", quantity: 30 },\n { store: \"ShopMart\", item: \"Cheese\", quantity: 50 },\n { store: \"General Store\", item: \"Chocolates\", quantity: 125 },\n { store: \"ShopMart\", item: \"Chocolates\", quantity: 150 },\n { store: \"General Store\", item: \"Cookies\", quantity: 200 },\n { store: \"ShopMart\", item: \"Cookies\", quantity: 100 },\n { store: \"ShopMart\", item: \"Nuts\", quantity: 100 },\n { store: \"General Store\", item: \"Pie\", quantity: 30 },\n { store: \"ShopMart\", item: \"Pie\", quantity: 25 }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales_2018</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">30</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">50</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">125</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">150</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">200</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">100</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Nuts"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">100</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">30</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">25</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create a <code class="leafygreen-ui-1l06pbn"> sales_2019 </code> collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales_2019.insertMany( [\n { store: \"General Store\", item: \"Cheese\", quantity: 50 },\n { store: \"ShopMart\", item: \"Cheese\", quantity: 20 },\n { store: \"General Store\", item: \"Chocolates\", quantity: 125 },\n { store: \"ShopMart\", item: \"Chocolates\", quantity: 150 },\n { store: \"General Store\", item: \"Cookies\", quantity: 200 },\n { store: \"ShopMart\", item: \"Cookies\", quantity: 100 },\n { store: \"General Store\", item: \"Nuts\", quantity: 80 },\n { store: \"ShopMart\", item: \"Nuts\", quantity: 30 },\n { store: \"General Store\", item: \"Pie\", quantity: 50 },\n { store: \"ShopMart\", item: \"Pie\", quantity: 75 }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales_2019</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">50</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">20</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">125</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">150</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">200</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">100</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Nuts"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">80</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Nuts"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">30</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">50</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">75</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create a <code class="leafygreen-ui-1l06pbn"> sales_2020 </code> collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales_2020.insertMany( [\n { store: \"General Store\", item: \"Cheese\", quantity: 100, },\n { store: \"ShopMart\", item: \"Cheese\", quantity: 100},\n { store: \"General Store\", item: \"Chocolates\", quantity: 200 },\n { store: \"ShopMart\", item: \"Chocolates\", quantity: 300 },\n { store: \"General Store\", item: \"Cookies\", quantity: 500 },\n { store: \"ShopMart\", item: \"Cookies\", quantity: 400 },\n { store: \"General Store\", item: \"Nuts\", quantity: 100 },\n { store: \"ShopMart\", item: \"Nuts\", quantity: 200 },\n { store: \"General Store\", item: \"Pie\", quantity: 100 },\n { store: \"ShopMart\", item: \"Pie\", quantity: 100 }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales_2020</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">100</span>, <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">100</span>}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">200</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">300</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">500</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">400</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Nuts"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">100</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Nuts"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">200</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">100</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">100</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> </li> </ol> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Report 1: All Sales by Year and Stores and Items <a class="headerlink leafygreen-ui-1kepx47" href="#report-1--all-sales-by-year-and-stores-and-items" 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="report-1--all-sales-by-year-and-stores-and-items"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following aggregation creates a yearly sales report that lists all sales by quarter and stores. The pipeline uses <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unionWith" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </span> </a> to combine documents from all four collections: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales_2017.aggregate( [\n { $set: { _id: \"2017\" } },\n { $unionWith: { coll: \"sales_2018\", pipeline: [ { $set: { _id: \"2018\" } } ] } },\n { $unionWith: { coll: \"sales_2019\", pipeline: [ { $set: { _id: \"2019\" } } ] } },\n { $unionWith: { coll: \"sales_2020\", pipeline: [ { $set: { _id: \"2020\" } } ] } },\n { $sort: { _id: 1, store: 1, item: 1 } }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales_2017</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">$set</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"2017"</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unionWith</span>: <!-- -->{ <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"sales_2018"</span>, <span class="lg-highlight-attr">pipeline</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"2018"</span> } } ] } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unionWith</span>: <!-- -->{ <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"sales_2019"</span>, <span class="lg-highlight-attr">pipeline</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"2019"</span> } } ] } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unionWith</span>: <!-- -->{ <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"sales_2020"</span>, <span class="lg-highlight-attr">pipeline</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"2020"</span> } } ] } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">store</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">item</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> <p class="leafygreen-ui-1kp3ins"> Specifically, the aggregation pipeline uses: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> stage to update the <code class="leafygreen-ui-1l06pbn"> _id </code> field to contain the year. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A sequence of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unionWith" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </span> </a> stages to combine all documents from the four collections, each also using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> stage on its documents. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> stage to sort by the <code class="leafygreen-ui-1l06pbn"> _id </code> (the year), the <code class="leafygreen-ui-1l06pbn"> store </code> , and <code class="leafygreen-ui-1l06pbn"> item </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Pipeline output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"2017\", \"store\" : \"General Store\", \"item\" : \"Chocolates\", \"quantity\" : 150 }\n{ \"_id\" : \"2017\", \"store\" : \"General Store\", \"item\" : \"Cookies\", \"quantity\" : 100 }\n{ \"_id\" : \"2017\", \"store\" : \"General Store\", \"item\" : \"Pie\", \"quantity\" : 10 }\n{ \"_id\" : \"2017\", \"store\" : \"ShopMart\", \"item\" : \"Chocolates\", \"quantity\" : 50 }\n{ \"_id\" : \"2017\", \"store\" : \"ShopMart\", \"item\" : \"Cookies\", \"quantity\" : 120 }\n{ \"_id\" : \"2017\", \"store\" : \"ShopMart\", \"item\" : \"Pie\", \"quantity\" : 5 }\n{ \"_id\" : \"2018\", \"store\" : \"General Store\", \"item\" : \"Cheese\", \"quantity\" : 30 }\n{ \"_id\" : \"2018\", \"store\" : \"General Store\", \"item\" : \"Chocolates\", \"quantity\" : 125 }\n{ \"_id\" : \"2018\", \"store\" : \"General Store\", \"item\" : \"Cookies\", \"quantity\" : 200 }\n{ \"_id\" : \"2018\", \"store\" : \"General Store\", \"item\" : \"Pie\", \"quantity\" : 30 }\n{ \"_id\" : \"2018\", \"store\" : \"ShopMart\", \"item\" : \"Cheese\", \"quantity\" : 50 }\n{ \"_id\" : \"2018\", \"store\" : \"ShopMart\", \"item\" : \"Chocolates\", \"quantity\" : 150 }\n{ \"_id\" : \"2018\", \"store\" : \"ShopMart\", \"item\" : \"Cookies\", \"quantity\" : 100 }\n{ \"_id\" : \"2018\", \"store\" : \"ShopMart\", \"item\" : \"Nuts\", \"quantity\" : 100 }\n{ \"_id\" : \"2018\", \"store\" : \"ShopMart\", \"item\" : \"Pie\", \"quantity\" : 25 }\n{ \"_id\" : \"2019\", \"store\" : \"General Store\", \"item\" : \"Cheese\", \"quantity\" : 50 }\n{ \"_id\" : \"2019\", \"store\" : \"General Store\", \"item\" : \"Chocolates\", \"quantity\" : 125 }\n{ \"_id\" : \"2019\", \"store\" : \"General Store\", \"item\" : \"Cookies\", \"quantity\" : 200 }\n{ \"_id\" : \"2019\", \"store\" : \"General Store\", \"item\" : \"Nuts\", \"quantity\" : 80 }\n{ \"_id\" : \"2019\", \"store\" : \"General Store\", \"item\" : \"Pie\", \"quantity\" : 50 }\n{ \"_id\" : \"2019\", \"store\" : \"ShopMart\", \"item\" : \"Cheese\", \"quantity\" : 20 }\n{ \"_id\" : \"2019\", \"store\" : \"ShopMart\", \"item\" : \"Chocolates\", \"quantity\" : 150 }\n{ \"_id\" : \"2019\", \"store\" : \"ShopMart\", \"item\" : \"Cookies\", \"quantity\" : 100 }\n{ \"_id\" : \"2019\", \"store\" : \"ShopMart\", \"item\" : \"Nuts\", \"quantity\" : 30 }\n{ \"_id\" : \"2019\", \"store\" : \"ShopMart\", \"item\" : \"Pie\", \"quantity\" : 75 }\n{ \"_id\" : \"2020\", \"store\" : \"General Store\", \"item\" : \"Cheese\", \"quantity\" : 100 }\n{ \"_id\" : \"2020\", \"store\" : \"General Store\", \"item\" : \"Chocolates\", \"quantity\" : 200 }\n{ \"_id\" : \"2020\", \"store\" : \"General Store\", \"item\" : \"Cookies\", \"quantity\" : 500 }\n{ \"_id\" : \"2020\", \"store\" : \"General Store\", \"item\" : \"Nuts\", \"quantity\" : 100 }\n{ \"_id\" : \"2020\", \"store\" : \"General Store\", \"item\" : \"Pie\", \"quantity\" : 100 }\n{ \"_id\" : \"2020\", \"store\" : \"ShopMart\", \"item\" : \"Cheese\", \"quantity\" : 100 }\n{ \"_id\" : \"2020\", \"store\" : \"ShopMart\", \"item\" : \"Chocolates\", \"quantity\" : 300 }\n{ \"_id\" : \"2020\", \"store\" : \"ShopMart\", \"item\" : \"Cookies\", \"quantity\" : 400 }\n{ \"_id\" : \"2020\", \"store\" : \"ShopMart\", \"item\" : \"Nuts\", \"quantity\" : 200 }\n{ \"_id\" : \"2020\", \"store\" : \"ShopMart\", \"item\" : \"Pie\", \"quantity\" : 100 }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2017"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">150</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2017"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">100</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2017"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">10</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2017"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">50</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2017"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">120</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2017"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">5</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2018"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">30</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2018"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">125</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2018"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">200</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2018"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">30</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2018"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">50</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2018"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">150</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2018"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">100</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2018"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Nuts"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">100</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2018"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">25</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">50</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">125</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">200</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Nuts"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">80</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">50</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">20</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">150</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">100</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Nuts"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">30</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">75</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2020"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">100</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2020"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">200</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2020"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">500</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2020"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Nuts"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">100</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2020"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"General Store"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">100</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2020"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">100</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2020"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">300</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2020"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">400</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2020"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Nuts"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">200</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2020"</span>, <span class="lg-highlight-string">"store"</span> <!-- -->: <span class="lg-highlight-string">"ShopMart"</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">100</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Report 2: Aggregated Sales by Items <a class="headerlink leafygreen-ui-1kepx47" href="#report-2--aggregated-sales-by-items" 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="report-2--aggregated-sales-by-items"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following aggregation creates a sales report that lists the sales quantity per item. The pipeline uses <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unionWith" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </span> </a> to combine documents from all four years: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales_2017.aggregate( [\n { $unionWith: \"sales_2018\" },\n { $unionWith: \"sales_2019\" },\n { $unionWith: \"sales_2020\" },\n { $group: { _id: \"$item\", total: { $sum: \"$quantity\" } } },\n { $sort: { total: -1 } }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales_2017</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">$unionWith</span>: <span class="lg-highlight-string">"sales_2018"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unionWith</span>: <span class="lg-highlight-string">"sales_2019"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unionWith</span>: <span class="lg-highlight-string">"sales_2020"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$item"</span>, <span class="lg-highlight-attr">total</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$quantity"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-attr">total</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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The sequence of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-unionWith" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </span> </a> stages retrieve documents from the specified collections into the pipeline: </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage groups by the <code class="leafygreen-ui-1l06pbn"> item </code> field and uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> $sum </code> </a> to calculate the total sales quantity per <code class="leafygreen-ui-1l06pbn"> item </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> stage orders the documents by descending <code class="leafygreen-ui-1l06pbn"> total </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Pipeline output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"Cookies\", \"total\" : 1720 }\n{ \"_id\" : \"Chocolates\", \"total\" : 1250 }\n{ \"_id\" : \"Nuts\", \"total\" : 510 }\n{ \"_id\" : \"Pie\", \"total\" : 395 }\n{ \"_id\" : \"Cheese\", \"total\" : 350 }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Cookies"</span>, <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">1720</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Chocolates"</span>, <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">1250</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Nuts"</span>, <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">510</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Pie"</span>, <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">395</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">350</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-unionWith-example-specified-docs"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create a Union with Specified Documents <a class="headerlink leafygreen-ui-1kepx47" href="#create-a-union-with-specified-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="create-a-union-with-specified-documents"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> You can use <code class="leafygreen-ui-1l06pbn"> $unionWith </code> to perform a union with documents that you specify in the <code class="leafygreen-ui-1l06pbn"> pipeline </code> field. When you specify a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/documents/#mongodb-pipeline-pipe.-documents"> <code class="leafygreen-ui-1l06pbn"> $documents </code> </a> stage in the <code class="leafygreen-ui-1l06pbn"> pipeline </code> field, you perform a union with documents that aren't stored in a separate collection. </p> <p class="leafygreen-ui-1kp3ins"> Create a collection <code class="leafygreen-ui-1l06pbn"> cakeFlavors </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeFlavors.insertMany( [\n { _id: 1, flavor: \"chocolate\" },\n { _id: 2, flavor: \"strawberry\" },\n { _id: 3, flavor: \"cherry\" }\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">db.<span class="lg-highlight-property">cakeFlavors</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"chocolate"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"strawberry"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"cherry"</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> <p class="leafygreen-ui-1kp3ins"> The following <code class="leafygreen-ui-1l06pbn"> $unionWith </code> operation performs a union with documents specified in the <code class="leafygreen-ui-1l06pbn"> pipeline </code> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/documents/#mongodb-pipeline-pipe.-documents"> <code class="leafygreen-ui-1l06pbn"> $documents </code> </a> field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeFlavors.aggregate( [\n {\n $unionWith: {\n pipeline: [\n {\n $documents: [\n { _id: 4, flavor: \"orange\" },\n { _id: 5, flavor: \"vanilla\", price: 20 }\n ]\n }\n ]\n }\n }\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">db.<span class="lg-highlight-property">cakeFlavors</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$unionWith</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pipeline</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$documents</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"orange"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">20</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> Output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: 1, flavor: 'chocolate' },\n { _id: 2, flavor: 'strawberry' },\n { _id: 3, flavor: 'cherry' },\n { _id: 4, flavor: 'orange' },\n { _id: 5, flavor: 'vanilla', price: 20 }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">'chocolate'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">'strawberry'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">'cherry'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">'orange'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">'vanilla'</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">20</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-unionWith-example-namespaces-in-subpipelines"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Namespaces in Subpipelines <a class="headerlink leafygreen-ui-1kepx47" href="#namespaces-in-subpipelines" 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="namespaces-in-subpipelines"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 8.0, namespaces in subpipelines within <code class="leafygreen-ui-1l06pbn"> $lookup </code> and <code class="leafygreen-ui-1l06pbn"> $unionWith </code> are validated to ensure the correct use of <code class="leafygreen-ui-1l06pbn"> from </code> and <code class="leafygreen-ui-1l06pbn"> coll </code> fields: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For <code class="leafygreen-ui-1l06pbn"> $lookup </code> , omit the <code class="leafygreen-ui-1l06pbn"> from </code> field if you use a subpipeline with a stage which doesn't require a specified collection. For example, a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/documents/#mongodb-pipeline-pipe.-documents"> <code class="leafygreen-ui-1l06pbn"> $documents </code> </a> stage. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Similarly, for <code class="leafygreen-ui-1l06pbn"> $unionWith </code> , omit the <code class="leafygreen-ui-1l06pbn"> coll </code> field. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Unchanged behavior: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For a <code class="leafygreen-ui-1l06pbn"> $lookup </code> that starts with a stage for a collection, for example a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/collStats/#mongodb-pipeline-pipe.-collStats"> <code class="leafygreen-ui-1l06pbn"> $collStats </code> </a> subpipeline, you must include the <code class="leafygreen-ui-1l06pbn"> from </code> field and specify the collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Similarly, for <code class="leafygreen-ui-1l06pbn"> $unionWith </code> , include the <code class="leafygreen-ui-1l06pbn"> coll </code> field and specify the collection. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The following scenario shows an example. </p> <p class="leafygreen-ui-1kp3ins"> Create a collection <code class="leafygreen-ui-1l06pbn"> cakeFlavors </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeFlavors.insertMany( [\n { _id: 1, flavor: \"chocolate\" },\n { _id: 2, flavor: \"strawberry\" },\n { _id: 3, flavor: \"cherry\" }\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">db.<span class="lg-highlight-property">cakeFlavors</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"chocolate"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"strawberry"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"cherry"</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> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 8.0, the following example returns an error because it contains an invalid <code class="leafygreen-ui-1l06pbn"> coll </code> field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeFlavors.aggregate( [ {\n $unionWith: {\n coll: \"cakeFlavors\",\n pipeline: [ { $documents: [] } ] }\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">db.<span class="lg-highlight-property">cakeFlavors</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">$unionWith</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"cakeFlavors"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pipeline</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$documents</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> <p class="leafygreen-ui-1kp3ins"> In MongoDB versions before 8.0, the previous example runs. </p> <p class="leafygreen-ui-1kp3ins"> For an example with a valid <code class="leafygreen-ui-1l06pbn"> coll </code> field, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-unionWith-duplicate-results" target="_self"> <span> Duplicate Results <!-- --> . </span> </a> </p> </section> </section> </section>
https://www.mongodb.com/docs/manual/core/dot-dollar-considerations/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Field Names with Periods and Dollar Signs <a class="headerlink leafygreen-ui-1kepx47" href="#field-names-with-periods-and-dollar-signs" 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="field-names-with-periods-and-dollar-signs"> </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="#get-started" target="_self"> <span> Get Started </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> MongoDB supports field names that are dollar ( <code class="leafygreen-ui-1l06pbn"> $ </code> ) prefixed or that contain periods ( <code class="leafygreen-ui-1l06pbn"> . </code> ). </p> <p class="leafygreen-ui-1kp3ins"> In most cases data that has been stored using field names like these is not directly accessible. You need to use helper methods like <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/getField/#mongodb-expression-exp.-getField"> <code class="leafygreen-ui-1l06pbn"> $getField </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setField/#mongodb-expression-exp.-setField"> <code class="leafygreen-ui-1l06pbn"> $setField </code> </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal"> <code class="leafygreen-ui-1l06pbn"> $literal </code> </a> in queries that access those fields. </p> <p class="leafygreen-ui-1kp3ins"> The field name validation rules are not the same for all types of storage operations. </p> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Get Started <a class="headerlink leafygreen-ui-1kepx47" href="#get-started" 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="get-started"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> For examples of how to handle field names that contain periods and dollar signs, see these pages: </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/dot-dollar-considerations/dollar-prefix/#std-label-dollar-prefix-field-names"> Dollar-Prefixed Field Names </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/dot-dollar-considerations/periods/#std-label-period-field-names"> Field Names with Periods </a> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $currentOp (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-currentop--aggregation-" 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="-currentop--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#constraints" target="_self"> <span> Constraints </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#output-fields" target="_self"> <span> Output Fields </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="pipeline"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-pipeline-pipe.-currentOp" title="Permalink to this definition"> <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="mongodb-pipeline-pipe.-currentOp"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Returns a stream of documents containing information on active and/or dormant operations as well as inactive sessions that are holding locks as part of a transaction. The stage returns a document for each operation or session. To run <code class="leafygreen-ui-1l06pbn"> $currentOp </code> , use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.aggregate/#mongodb-method-db.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.aggregate() </code> </a> helper on the <code class="leafygreen-ui-1l06pbn"> admin </code> database. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $currentOp </code> aggregation stage is preferred over the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp"> <code class="leafygreen-ui-1l06pbn"> currentOp </code> </a> command and its <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> helper method <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.currentOp/#mongodb-method-db.currentOp"> <code class="leafygreen-ui-1l06pbn"> db.currentOp() </code> </a> . Because the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp"> <code class="leafygreen-ui-1l06pbn"> currentOp </code> </a> command and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.currentOp/#mongodb-method-db.currentOp"> <code class="leafygreen-ui-1l06pbn"> db.currentOp() </code> </a> helper method return the results in a single document, the total size of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp"> <code class="leafygreen-ui-1l06pbn"> currentOp </code> </a> result set is subject to the maximum 16MB BSON size limit for documents. The <code class="leafygreen-ui-1l06pbn"> $currentOp </code> stage returns a cursor over a stream of documents, each of which reports a single operation. Each operation document is subject to the 16MB BSON limit, but unlike the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp"> <code class="leafygreen-ui-1l06pbn"> currentOp </code> </a> command, there is no limit on the overall size of the result set. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $currentOp </code> also enables you to perform arbitrary transformations of the results as the documents pass through the pipeline. </p> </dd> </dl> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h3> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $currentOp: { allUsers: &lt;boolean&gt;, idleConnections: &lt;boolean&gt;, idleCursors: &lt;boolean&gt;, idleSessions: &lt;boolean&gt;, localOps: &lt;boolean&gt; } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$currentOp</span>: <!-- -->{ <span class="lg-highlight-attr">allUsers</span>: &lt;<!-- -->boolean<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">idleConnections</span>: &lt;<!-- -->boolean<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">idleCursors</span>: &lt;<!-- -->boolean<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">idleSessions</span>: &lt;<!-- -->boolean<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">localOps</span>: &lt;<!-- -->boolean<!-- -->&gt; <!-- -->} }</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"> <code class="leafygreen-ui-1l06pbn"> $currentOp </code> takes an options document as its operand: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:25%"/> <col style="width:75%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Option </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-allUsers" target="_self"> <span> allUsers </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-currentOp-stage-allUsers"> </span> <p class="leafygreen-ui-1kp3ins"> Boolean. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If set to <code class="leafygreen-ui-1l06pbn"> false </code> , <code class="leafygreen-ui-1l06pbn"> $currentOp </code> only reports on operations/idle connections/idle cursors/idle sessions belonging to the user who ran the command. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If set to <code class="leafygreen-ui-1l06pbn"> true </code> , <code class="leafygreen-ui-1l06pbn"> $currentOp </code> reports operations belonging to all users. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For standalone and replica sets that enforce access control, <code class="leafygreen-ui-1l06pbn"> inprog </code> privilege is required if <code class="leafygreen-ui-1l06pbn"> allUsers: true </code> . </p> <p class="leafygreen-ui-1kp3ins"> For sharded clusters that enforce access control, the <code class="leafygreen-ui-1l06pbn"> inprog </code> privilege is required to run <code class="leafygreen-ui-1l06pbn"> $currentOp </code> . </p> <p class="leafygreen-ui-1kp3ins"> Defaults to <code class="leafygreen-ui-1l06pbn"> false </code> . </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-idleConnections" target="_self"> <span> idleConnections </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-currentOp-stage-idleConnections"> </span> <p class="leafygreen-ui-1kp3ins"> Boolean. If set to <code class="leafygreen-ui-1l06pbn"> false </code> , <code class="leafygreen-ui-1l06pbn"> $currentOp </code> only reports active operations. If set to <code class="leafygreen-ui-1l06pbn"> true </code> , <code class="leafygreen-ui-1l06pbn"> $currentOp </code> returns all operations, including idle connections. </p> <p class="leafygreen-ui-1kp3ins"> Defaults to <code class="leafygreen-ui-1l06pbn"> false </code> . </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-idleCursors" target="_self"> <span> idleCursors </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-currentOp-stage-idleCursors"> </span> <p class="leafygreen-ui-1kp3ins"> Boolean. </p> <p class="leafygreen-ui-1kp3ins"> If set to <code class="leafygreen-ui-1l06pbn"> true </code> , <code class="leafygreen-ui-1l06pbn"> $currentOp </code> reports on cursors that are "idle"; i.e. open but not currently active in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getMore/#mongodb-dbcommand-dbcmd.getMore"> <code class="leafygreen-ui-1l06pbn"> getMore </code> </a> operation. </p> <p class="leafygreen-ui-1kp3ins"> Information on idle cursors have the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.type" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> type </code> </span> </a> set to <code class="leafygreen-ui-1l06pbn"> "idleCursor" </code> . </p> <p class="leafygreen-ui-1kp3ins"> Information on cursors currently active in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getMore/#mongodb-dbcommand-dbcmd.getMore"> <code class="leafygreen-ui-1l06pbn"> getMore </code> </a> operation information have the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.type" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> type </code> </span> </a> set to <code class="leafygreen-ui-1l06pbn"> "op" </code> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.op" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> op </code> </span> </a> set to <code class="leafygreen-ui-1l06pbn"> getmore </code> . </p> <p class="leafygreen-ui-1kp3ins"> Defaults to <code class="leafygreen-ui-1l06pbn"> false </code> . </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-idleSessions" target="_self"> <span> idleSessions </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-currentOp-stage-idleSessions"> </span> <p class="leafygreen-ui-1kp3ins"> Boolean. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If set to <code class="leafygreen-ui-1l06pbn"> true </code> , in addition to active/dormant operations, <code class="leafygreen-ui-1l06pbn"> $currentOp </code> reports on: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Inactive sessions that are holding locks as part of a transaction. Each inactive session appears as a separate document in the <code class="leafygreen-ui-1l06pbn"> $currentOp </code> stream. </p> <p class="leafygreen-ui-1kp3ins"> The document for a session includes information on the session ID in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.lsid" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> lsid </code> </span> </a> field and the transaction in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> transaction </code> </span> </a> field. </p> <p class="leafygreen-ui-1kp3ins"> Information on idle sessions have the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.type" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> type </code> </span> </a> set to <code class="leafygreen-ui-1l06pbn"> "idleSession" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator </code> </span> </a> in <code class="leafygreen-ui-1l06pbn"> inactive </code> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.state" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> state </code> </span> </a> </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If set to <code class="leafygreen-ui-1l06pbn"> false </code> , <code class="leafygreen-ui-1l06pbn"> $currentOp </code> doesn't report on: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Inactive sessions </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator </code> </span> </a> information in <code class="leafygreen-ui-1l06pbn"> inactive </code> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.state" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> state </code> </span> </a> </p> </li> </ul> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Defaults to <code class="leafygreen-ui-1l06pbn"> true </code> . </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-currentOp-stage-localOps"> </span> <p class="leafygreen-ui-1kp3ins"> Boolean. If set to <code class="leafygreen-ui-1l06pbn"> true </code> for an aggregation running on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> , <code class="leafygreen-ui-1l06pbn"> $currentOp </code> reports only operations running locally on that <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> . If <code class="leafygreen-ui-1l06pbn"> false </code> , then <code class="leafygreen-ui-1l06pbn"> $currentOp </code> instead reports operations running on the shards. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> localOps </code> parameter has no effect for <code class="leafygreen-ui-1l06pbn"> $currentOp </code> aggregations running on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Defaults to <code class="leafygreen-ui-1l06pbn"> false </code> . </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-targetAllNodes" target="_self"> <span> targetAllNodes </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-currentOp-stage-targetAllNodes"> </span> <p class="leafygreen-ui-1kp3ins"> Boolean. If set to <code class="leafygreen-ui-1l06pbn"> true </code> , <code class="leafygreen-ui-1l06pbn"> $currentOp </code> outputs a document for each data-bearing node for all shards. If set to <code class="leafygreen-ui-1l06pbn"> false </code> , <code class="leafygreen-ui-1l06pbn"> $curentOp </code> outputs a document for each shard. </p> <p class="leafygreen-ui-1kp3ins"> For example, in a sharded cluster with three shards where each shard is a replica set with three nodes: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> targetAllNodes=false </code> outputs three documents </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> targetAllNodes=true </code> outputs nine documents </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Defaults to <code class="leafygreen-ui-1l06pbn"> false </code> . </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.1 </em> . </p> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Omitting any of the above parameters will cause $currentOp to use that parameter's default value. Specify an empty document, as shown below, to use the default values of all parameters. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $currentOp: { } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$currentOp</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> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Constraints <a class="headerlink leafygreen-ui-1kepx47" href="#constraints" 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="constraints"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Pipeline <a class="headerlink leafygreen-ui-1kepx47" href="#pipeline" 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="pipeline"> </div> </a> </h3> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $currentOp </code> must be the first stage in the pipeline. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Pipelines that start with <code class="leafygreen-ui-1l06pbn"> $currentOp </code> can only be run on the <code class="leafygreen-ui-1l06pbn"> admin </code> database. </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Access Control <a class="headerlink leafygreen-ui-1kepx47" href="#access-control" 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="access-control"> </div> </a> </h3> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For standalone and replica sets that enforce access control, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-inprog"> <code class="leafygreen-ui-1l06pbn"> inprog </code> </a> privilege is required to run <code class="leafygreen-ui-1l06pbn"> $currentOp </code> if <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-allUsers" target="_self"> <span> allUsers: true <!-- --> . </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For sharded clusters that enforce access control, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-inprog"> <code class="leafygreen-ui-1l06pbn"> inprog </code> </a> privilege is required to run <code class="leafygreen-ui-1l06pbn"> $currentOp </code> . </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" 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> </h3> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $currentOp </code> is not allowed in <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> transactions <!-- --> . </a> </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Redaction <a class="headerlink leafygreen-ui-1kepx47" href="#redaction" 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="redaction"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> When using <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/#std-label-qe-manual-feature-qe"> Queryable Encryption </a> , <code class="leafygreen-ui-1l06pbn"> $currentOp </code> output redacts certain information: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The output omits all fields after <code class="leafygreen-ui-1l06pbn"> "command" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The output redacts <code class="leafygreen-ui-1l06pbn"> "command" </code> to include only the first element, <code class="leafygreen-ui-1l06pbn"> $comment </code> , and <code class="leafygreen-ui-1l06pbn"> $db </code> . </p> </li> </ul> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following examples show how to use the <code class="leafygreen-ui-1l06pbn"> $currentOp </code> aggregation stage. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Inactive Sessions <a class="headerlink leafygreen-ui-1kepx47" href="#inactive-sessions" 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="inactive-sessions"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> This example returns information on inactive sessions that are holding locks as part of a transaction. Specifically: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The first stage returns documents for all active operations as well as inactive sessions that are holding locks as part of a transaction. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The second stage filters for documents related to inactive sessions that are holding locks as part of a transaction. </p> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"admin\").aggregate( [\n { $currentOp : { allUsers: true, idleSessions: true } },\n { $match : { active: false, transaction : { $exists: true } } }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</span>).<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$currentOp<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">allUsers</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">idleSessions</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$match<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">active</span>: <span class="lg-highlight-literal">false</span>, <!-- -->transaction <!-- -->: <!-- -->{ <span class="lg-highlight-attr">$exists</span>: <span class="lg-highlight-literal">true</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> <p class="leafygreen-ui-1kp3ins"> You can use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.type" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.type </code> </span> </a> to specify an equivalent filter: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"admin\").aggregate( [\n { $currentOp : { allUsers: true, idleSessions: true } },\n { $match : { type: \"idleSession\" } }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</span>).<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$currentOp<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">allUsers</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">idleSessions</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$match<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"idleSession"</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 class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> For transactions on a sharded cluster, include <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps:true </span> </a> in the previous examples for a composite view of the transactions. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Both operations return documents of the form: </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-14"> <div aria-label="Tabs to describe usage of currentOp-mongos/currentOp-mongos-localops/currentOp-rs" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_vugnio443" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_chdw5j9qv" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Replica Set </div> </button> <button aria-controls="_iip2y4z1m" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_t1ku0eiap" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Sharded Cluster (localOps: true) </div> </button> <button aria-controls="_kkznilzva" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_hqb07llvr" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Sharded Cluster </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="_gatf1y05c" class="" id="_0qg13a9de" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> When run on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> that is part of a replica set: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"type\" : \"idleSession\",\n \"host\" : \"example.mongodb.com:27017\",\n \"desc\" : \"inactive transaction\",\n \"client\" : \"198.51.100.1:50428\",\n \"connectionId\" : NumberLong(32),\n \"appName\" : \"\",\n \"clientMetadata\" : {\n \"driver\" : {\n \"name\" : \"PyMongo\",\n \"version\" : \"3.9.0\"\n },\n \"os\" : {\n \"type\" : \"Darwin\",\n \"name\" : \"Darwin\",\n \"architecture\" : \"x86_64\",\n \"version\" : \"10.14.5\"\n },\n \"platform\" : \"CPython 3.7.1.final.0\"\n },\n \"lsid\" : {\n \"id\" : UUID(\"ff21e1a9-a130-4fe0-942f-9e6b6c67ea3c\"),\n \"uid\" : BinData(0,\"3pxqkATNUYKV/soT7qqKE0zC0BFb0pBz1pk4xXcSHsI=\")\n },\n \"transaction\" : {\n \"parameters\" : {\n \"txnNumber\" : NumberLong(4),\n \"autocommit\" : false,\n \"readConcern\" : {\n \"level\" : \"snapshot\",\n \"afterClusterTime\" : Timestamp(1563892246, 1)\n }\n },\n \"readTimestamp\" : Timestamp(0, 0),\n \"startWallClockTime\" : \"2019-07-23T10:30:49.461-04:00\",\n \"timeOpenMicros\" : NumberLong(1913590),\n \"timeActiveMicros\" : NumberLong(55),\n \"timeInactiveMicros\" : NumberLong(1913535),\n \"expiryTime\" : \"2019-07-23T10:31:49.461-04:00\"\n },\n \"waitingForLock\" : false,\n \"active\" : false,\n \"locks\" : {\n \"ReplicationStateTransition\" : \"w\",\n \"Global\" : \"w\",\n \"Database\" : \"w\",\n \"Collection\" : \"w\"\n },\n \"lockStats\" : {\n \"ReplicationStateTransition\" : {\n \"acquireCount\" : {\n \"w\" : NumberLong(5)\n }\n },\n \"Global\" : {\n \"acquireCount\" : {\n \"r\" : NumberLong(3),\n \"w\" : NumberLong(1)\n }\n },\n \"Database\" : {\n \"acquireCount\" : {\n \"r\" : NumberLong(2),\n \"w\" : NumberLong(1)\n }\n },\n \"Collection\" : {\n \"acquireCount\" : {\n \"w\" : NumberLong(1)\n }\n },\n \"Mutex\" : {\n \"acquireCount\" : {\n \"r\" : NumberLong(3)\n }\n },\n \"oplog\" : {\n \"acquireCount\" : {\n \"r\" : NumberLong(2)\n }\n }\n },\n \"waitingForFlowControl\" : false,\n \"flowControlStats\" : {},\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"idleSession"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"example.mongodb.com:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"desc"</span> <!-- -->: <span class="lg-highlight-string">"inactive transaction"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"client"</span> <!-- -->: <span class="lg-highlight-string">"198.51.100.1:50428"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"connectionId"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">32</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"appName"</span> <!-- -->: <span class="lg-highlight-string">""</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"clientMetadata"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"driver"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"PyMongo"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-string">"3.9.0"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"os"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"Darwin"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Darwin"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"architecture"</span> <!-- -->: <span class="lg-highlight-string">"x86_64"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-string">"10.14.5"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"platform"</span> <!-- -->: <span class="lg-highlight-string">"CPython 3.7.1.final.0"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lsid"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"ff21e1a9-a130-4fe0-942f-9e6b6c67ea3c"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"uid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>,<span class="lg-highlight-string">"3pxqkATNUYKV/soT7qqKE0zC0BFb0pBz1pk4xXcSHsI="</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"transaction"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"parameters"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"txnNumber"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">4</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"autocommit"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"readConcern"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"level"</span> <!-- -->: <span class="lg-highlight-string">"snapshot"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"afterClusterTime"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1563892246</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"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"readTimestamp"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">0</span>, <span class="lg-highlight-number">0</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"startWallClockTime"</span> <!-- -->: <span class="lg-highlight-string">"2019-07-23T10:30:49.461-04:00"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timeOpenMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">1913590</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timeActiveMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">55</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timeInactiveMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">1913535</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"expiryTime"</span> <!-- -->: <span class="lg-highlight-string">"2019-07-23T10:31:49.461-04:00"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"waitingForLock"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"active"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"locks"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ReplicationStateTransition"</span> <!-- -->: <span class="lg-highlight-string">"w"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Global"</span> <!-- -->: <span class="lg-highlight-string">"w"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Database"</span> <!-- -->: <span class="lg-highlight-string">"w"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Collection"</span> <!-- -->: <span class="lg-highlight-string">"w"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lockStats"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ReplicationStateTransition"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acquireCount"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">5</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Global"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acquireCount"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"r"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">3</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</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"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Database"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acquireCount"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"r"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">2</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</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"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Collection"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acquireCount"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</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"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Mutex"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acquireCount"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"r"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">3</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"oplog"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acquireCount"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"r"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">2</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"waitingForFlowControl"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"flowControlStats"</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="_3lhy5v7dv" class="leafygreen-ui-38lglc" id="_9fhn65iba" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Running <code class="leafygreen-ui-1l06pbn"> $currentOp </code> with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps:true </span> </a> provides a composite view (rather than per shard information) of the in-progress transactions run on that <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> . </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"admin\").aggregate( [\n { $currentOp : { allUsers: true, idleSessions: true, localOps: true } },\n { $match : { type: \"idleSession\" } }\n] );\n\n// or\n\ndb.getSiblingDB(\"admin\").aggregate( [\n { $currentOp : { allUsers: true, idleSessions: true, localOps: true } },\n { $match : { active: false, transaction : { $exists: true } } }\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">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</span>).<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$currentOp<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">allUsers</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">idleSessions</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">localOps</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$match<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"idleSession"</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"><span class="lg-highlight-comment">// or</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</span>).<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$currentOp<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">allUsers</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">idleSessions</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">localOps</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$match<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">active</span>: <span class="lg-highlight-literal">false</span>, <!-- -->transaction <!-- -->: <!-- -->{ <span class="lg-highlight-attr">$exists</span>: <span class="lg-highlight-literal">true</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> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"type\" : \"idleSession\",\n \"host\" : \"example.mongodb.com:27017\",\n \"desc\" : \"inactive transaction\",\n \"client\" : \"198.51.100.1:49618\",\n \"connectionId\" : NumberLong(48),\n \"appName\" : \"\",\n \"clientMetadata\" : {\n \"driver\" : {\n \"name\" : \"PyMongo\",\n \"version\" : \"3.9.0\"\n },\n \"os\" : {\n \"type\" : \"Darwin\",\n \"name\" : \"Darwin\",\n \"architecture\" : \"x86_64\",\n \"version\" : \"10.14.6\"\n },\n \"platform\" : \"CPython 3.7.1.final.0\",\n \"mongos\" : {\n \"host\" : \"example.mongodb.com:27017\",\n \"client\" : \"198.51.100.1:53268\",\n \"version\" : \"4.2.1\"\n }\n },\n \"lsid\" : {\n \"id\" : UUID(\"2c9ce111-133e-45b7-a00f-a7871005cae1\"),\n \"uid\" : BinData(0,\"3pxqkATNUYKV/soT7qqKE0zC0BFb0pBz1pk4xXcSHsI=\")\n },\n \"active\" : false,\n \"transaction\" : {\n \"parameters\" : {\n \"txnNumber\" : NumberLong(2),\n \"autocommit\" : false,\n \"readConcern\" : {\n \"level\" : \"snapshot\",\n \"afterClusterTime\" : Timestamp(1571869019, 2)\n }\n },\n \"globalReadTimestamp\" : Timestamp(1571869019, 2),\n \"startWallClockTime\" : \"2019-10-23T18:16:59.341-04:00\",\n \"timeOpenMicros\" : NumberLong(169244639),\n \"timeActiveMicros\" : NumberLong(535),\n \"timeInactiveMicros\" : NumberLong(169244104),\n \"numParticipants\" : 2,\n \"participants\" : [\n {\n \"name\" : \"shardB\",\n \"coordinator\" : true,\n \"readOnly\" : false\n },\n {\n \"name\" : \"shardA\",\n \"coordinator\" : false,\n \"readOnly\" : false\n }\n ],\n \"numReadOnlyParticipants\" : 0,\n \"numNonReadOnlyParticipants\" : 2\n }\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"idleSession"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"example.mongodb.com:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"desc"</span> <!-- -->: <span class="lg-highlight-string">"inactive transaction"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"client"</span> <!-- -->: <span class="lg-highlight-string">"198.51.100.1:49618"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"connectionId"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">48</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"appName"</span> <!-- -->: <span class="lg-highlight-string">""</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"clientMetadata"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"driver"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"PyMongo"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-string">"3.9.0"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"os"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"Darwin"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Darwin"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"architecture"</span> <!-- -->: <span class="lg-highlight-string">"x86_64"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-string">"10.14.6"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"platform"</span> <!-- -->: <span class="lg-highlight-string">"CPython 3.7.1.final.0"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"mongos"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"example.mongodb.com:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"client"</span> <!-- -->: <span class="lg-highlight-string">"198.51.100.1:53268"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-string">"4.2.1"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lsid"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"2c9ce111-133e-45b7-a00f-a7871005cae1"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"uid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>,<span class="lg-highlight-string">"3pxqkATNUYKV/soT7qqKE0zC0BFb0pBz1pk4xXcSHsI="</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"active"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"transaction"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"parameters"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"txnNumber"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">2</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"autocommit"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"readConcern"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"level"</span> <!-- -->: <span class="lg-highlight-string">"snapshot"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"afterClusterTime"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1571869019</span>, <span class="lg-highlight-number">2</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"globalReadTimestamp"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1571869019</span>, <span class="lg-highlight-number">2</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"startWallClockTime"</span> <!-- -->: <span class="lg-highlight-string">"2019-10-23T18:16:59.341-04:00"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timeOpenMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">169244639</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timeActiveMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">535</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timeInactiveMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">169244104</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numParticipants"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"participants"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"shardB"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"coordinator"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"readOnly"</span> <!-- -->: <span class="lg-highlight-literal">false</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"shardA"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"coordinator"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"readOnly"</span> <!-- -->: <span class="lg-highlight-literal">false</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numReadOnlyParticipants"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numNonReadOnlyParticipants"</span> <!-- -->: <span class="lg-highlight-number">2</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> When run without <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps:true </span> </a> on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> , the transaction information is per shard. </p> </div> </div> </div> <div> <div aria-labelledby="_h4gk41qdk" class="leafygreen-ui-38lglc" id="_g0ey7fbpk" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> When run on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> without <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps:true </span> </a> , the transaction information is per shard. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"shard\" : \"shardB\",\n \"type\" : \"idleSession\",\n \"host\" : \"shardB.mongodb.com:27018\",\n \"desc\" : \"inactive transaction\",\n \"client_s\" : \"198.51.100.1:53961\",\n \"connectionId\" : NumberLong(63),\n \"appName\" : \"\",\n \"clientMetadata\" : {\n \"driver\" : {\n \"name\" : \"PyMongo\",\n \"version\" : \"3.9.0\"\n },\n \"os\" : {\n \"type\" : \"Darwin\",\n \"name\" : \"Darwin\",\n \"architecture\" : \"x86_64\",\n \"version\" : \"10.14.6\"\n },\n \"platform\" : \"CPython 3.7.1.final.0\",\n \"mongos\" : {\n \"host\" : \"example.mongodb.com:27017\",\n \"client\" : \"198.51.100.1:53976\",\n \"version\" : \"4.2.0\"\n }\n },\n \"lsid\" : {\n \"id\" : UUID(\"720d403c-8daf-40bb-b61e-329e20b0493b\"),\n \"uid\" : BinData(0,\"3pxqkATNUYKV/soT7qqKE0zC0BFb0pBz1pk4xXcSHsI=\")\n },\n \"transaction\" : {\n \"parameters\" : {\n \"txnNumber\" : NumberLong(1),\n \"autocommit\" : false,\n \"readConcern\" : {\n \"level\" : \"snapshot\"\n }\n },\n \"readTimestamp\" : Timestamp(0, 0),\n \"startWallClockTime\" : \"2019-10-21T18:31:12.192-04:00\",\n \"timeOpenMicros\" : NumberLong(24137008),\n \"timeActiveMicros\" : NumberLong(52),\n \"timeInactiveMicros\" : NumberLong(24136956),\n \"expiryTime\" : \"2019-10-21T18:32:12.192-04:00\"\n },\n \"waitingForLock\" : false,\n \"active\" : false,\n \"locks\" : {\n \"ReplicationStateTransition\" : \"w\",\n \"Global\" : \"w\",\n \"Database\" : \"w\",\n \"Collection\" : \"w\"\n },\n \"lockStats\" : {\n \"ReplicationStateTransition\" : {\n \"acquireCount\" : {\n \"w\" : NumberLong(3)\n }\n },\n \"Global\" : {\n \"acquireCount\" : {\n \"r\" : NumberLong(1),\n \"w\" : NumberLong(1)\n }\n },\n \"Database\" : {\n \"acquireCount\" : {\n \"r\" : NumberLong(1),\n \"w\" : NumberLong(1)\n }\n },\n \"Collection\" : {\n \"acquireCount\" : {\n \"r\" : NumberLong(1),\n \"w\" : NumberLong(1)\n }\n },\n \"Mutex\" : {\n \"acquireCount\" : {\n \"r\" : NumberLong(6)\n }\n }\n }\n}\n{\n \"shard\" : \"shardA\",\n \"type\" : \"idleSession\",\n ...\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"shard"</span> <!-- -->: <span class="lg-highlight-string">"shardB"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"idleSession"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"shardB.mongodb.com:27018"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"desc"</span> <!-- -->: <span class="lg-highlight-string">"inactive transaction"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"client_s"</span> <!-- -->: <span class="lg-highlight-string">"198.51.100.1:53961"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"connectionId"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">63</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"appName"</span> <!-- -->: <span class="lg-highlight-string">""</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"clientMetadata"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"driver"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"PyMongo"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-string">"3.9.0"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"os"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"Darwin"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Darwin"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"architecture"</span> <!-- -->: <span class="lg-highlight-string">"x86_64"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-string">"10.14.6"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"platform"</span> <!-- -->: <span class="lg-highlight-string">"CPython 3.7.1.final.0"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"mongos"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"example.mongodb.com:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"client"</span> <!-- -->: <span class="lg-highlight-string">"198.51.100.1:53976"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-string">"4.2.0"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lsid"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"720d403c-8daf-40bb-b61e-329e20b0493b"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"uid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>,<span class="lg-highlight-string">"3pxqkATNUYKV/soT7qqKE0zC0BFb0pBz1pk4xXcSHsI="</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"transaction"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"parameters"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"txnNumber"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">1</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"autocommit"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"readConcern"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"level"</span> <!-- -->: <span class="lg-highlight-string">"snapshot"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"readTimestamp"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">0</span>, <span class="lg-highlight-number">0</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"startWallClockTime"</span> <!-- -->: <span class="lg-highlight-string">"2019-10-21T18:31:12.192-04:00"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timeOpenMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">24137008</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timeActiveMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">52</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timeInactiveMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">24136956</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"expiryTime"</span> <!-- -->: <span class="lg-highlight-string">"2019-10-21T18:32:12.192-04:00"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"waitingForLock"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"active"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"locks"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ReplicationStateTransition"</span> <!-- -->: <span class="lg-highlight-string">"w"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Global"</span> <!-- -->: <span class="lg-highlight-string">"w"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Database"</span> <!-- -->: <span class="lg-highlight-string">"w"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Collection"</span> <!-- -->: <span class="lg-highlight-string">"w"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lockStats"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ReplicationStateTransition"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acquireCount"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">3</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Global"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acquireCount"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"r"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">1</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</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"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Database"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acquireCount"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"r"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">1</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</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"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Collection"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acquireCount"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"r"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">1</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</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"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Mutex"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acquireCount"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"r"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">6</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"shard"</span> <!-- -->: <span class="lg-highlight-string">"shardA"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"idleSession"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-sampled-queries-currentOp-stage"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Sampled Queries <a class="headerlink leafygreen-ui-1kepx47" href="#sampled-queries" 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="sampled-queries"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> This example returns information on query sampling progess. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The first stage returns documents for all active operations. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The second stage filters for documents related to the query analyzer. </p> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"admin\").aggregate( [\n { $currentOp: { allUsers: true, localOps: true } },\n { $match: { desc: \"query analyzer\" } }\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">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</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">$currentOp</span>: <!-- -->{ <span class="lg-highlight-attr">allUsers</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">localOps</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-attr">desc</span>: <span class="lg-highlight-string">"query analyzer"</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> <p class="leafygreen-ui-1kp3ins"> This pipeline returns output similar to the following: </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-16"> <div aria-label="Tabs to describe usage of currentOp-query-analyzer-mongod-shardsvr/currentOp-query-analyzer-mongos/currentOp-query-analyzer-rs" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_fm61i1i48" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_vo07y0ngb" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Replica Set </div> </button> <button aria-controls="_0u5h2erl1" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_v3b6seuy5" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Sharded Cluster: mongos </div> </button> <button aria-controls="_1tdugcrj0" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_wxkk5eo91" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Sharded Cluster: mongod --shardsvr </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="_cpc5rgk8o" class="" id="_2rht29aar" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> When run on a <code class="leafygreen-ui-1l06pbn"> mongod </code> that is part of a replica set: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"desc\" : \"query analyzer\",\n \"ns\" : \"testDb.testColl\",\n \"collUuid\" : UUID(\"ed9dfb1d-5b7c-4c6b-82e9-b0f537335795\"),\n \"samplesPerSecond\" : 5,\n \"startTime\" : ISODate(\"2023-08-08T16:23:22.846Z\"),\n \"sampledReadsCount\" : NumberLong(2),\n \"sampledReadsBytes\" : NumberLong(346),\n \"sampledWritesCount\" : NumberLong(3),\n \"sampledWritesBytes\" : NumberLong(904)\n}"} </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "desc" : "query analyzer",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "ns" : "testDb.testColl",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "collUuid" : UUID("ed9dfb1d-5b7c-4c6b-82e9-b0f537335795"),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "samplesPerSecond" : 5,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "startTime" : ISODate("2023-08-08T16:23:22.846Z"),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "sampledReadsCount" : NumberLong(2),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "sampledReadsBytes" : NumberLong(346),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "sampledWritesCount" : NumberLong(3),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "sampledWritesBytes" : NumberLong(904)</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="_4qhjsegyt" class="leafygreen-ui-38lglc" id="_5nn38cy5m" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> When run on a <code class="leafygreen-ui-1l06pbn"> mongos </code> that is part of a sharded cluster: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"desc\" : \"query analyzer\",\n \"ns\" : \"testDb.testColl\",\n \"collUuid\" : UUID(\"5130b4df-5966-434f-85f0-f8956b5ca74e\"),\n \"samplesPerSecond\" : 5,\n \"startTime\" : ISODate(\"2023-08-08T16:15:07.427Z\"),\n \"sampledReadsCount\" : NumberLong(2),\n \"sampledWritesCount\" : NumberLong(3)\n}"} </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "desc" : "query analyzer",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "ns" : "testDb.testColl",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "collUuid" : UUID("5130b4df-5966-434f-85f0-f8956b5ca74e"),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "samplesPerSecond" : 5,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "startTime" : ISODate("2023-08-08T16:15:07.427Z"),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "sampledReadsCount" : NumberLong(2),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "sampledWritesCount" : NumberLong(3)</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="_lynppjfd2" class="leafygreen-ui-38lglc" id="_lp5p61cho" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> When run on a <code class="leafygreen-ui-1l06pbn"> mongod --shardsvr </code> that is part of a sharded cluster: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"desc\" : \"query analyzer\",\n \"ns\" : \"testDb.testColl\",\n \"collUuid\" : UUID(\"5130b4df-5966-434f-85f0-f8956b5ca74e\"),\n \"startTime\" : ISODate(\"2023-08-08T16:15:07.427Z\"),\n \"sampledReadsCount\" : NumberLong(2),\n \"sampledReadsBytes\" : NumberLong(346),\n \"sampledWritesCount\" : NumberLong(3),\n \"sampledWritesBytes\" : NumberLong(904)\n}"} </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "desc" : "query analyzer",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "ns" : "testDb.testColl",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "collUuid" : UUID("5130b4df-5966-434f-85f0-f8956b5ca74e"),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "startTime" : ISODate("2023-08-08T16:15:07.427Z"),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "sampledReadsCount" : NumberLong(2),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "sampledReadsBytes" : NumberLong(346),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "sampledWritesCount" : NumberLong(3),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "sampledWritesBytes" : NumberLong(904)</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-currentOp-stage-output-fields"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Output Fields <a class="headerlink leafygreen-ui-1kepx47" href="#output-fields" 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="output-fields"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Each output document may contain a subset of the following fields, as relevant for the operation: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.type </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.type" title="Permalink to this definition"> <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="mongodb-data--currentOp.type"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The type of operation. Values are either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> op </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> idleSession </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> idleCursor </code> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> If the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.type" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.type </code> </span> </a> is <code class="leafygreen-ui-1l06pbn"> op </code> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.op" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.op </code> </span> </a> provides details on the specific operation. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.host </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.host" title="Permalink to this definition"> <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="mongodb-data--currentOp.host"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The name of the host against which the operation is run. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.shard </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.shard" title="Permalink to this definition"> <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="mongodb-data--currentOp.shard"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The name of the shard where the operation is running. </p> <p class="leafygreen-ui-1kp3ins"> Only present for sharded clusters. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.desc </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.desc" title="Permalink to this definition"> <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="mongodb-data--currentOp.desc"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A description of the operation. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.connectionId </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.connectionId" title="Permalink to this definition"> <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="mongodb-data--currentOp.connectionId"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> An identifier for the connection where the specific operation originated. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.client </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.client" title="Permalink to this definition"> <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="mongodb-data--currentOp.client"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The IP address (or hostname) and the ephemeral port of the client connection where the operation originates. </p> <p class="leafygreen-ui-1kp3ins"> For multi-document transactions, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.client" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.client </code> </span> </a> stores information about the most recent client to run an operation inside the transaction. </p> <p class="leafygreen-ui-1kp3ins"> <em> For standalones and replica sets only </em> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.client_s </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.client_s" title="Permalink to this definition"> <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="mongodb-data--currentOp.client_s"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The IP address (or hostname) and the ephemeral port of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> where the operation originates. </p> <p class="leafygreen-ui-1kp3ins"> <em> For sharded clusters only </em> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.clientMetadata </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.clientMetadata" title="Permalink to this definition"> <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="mongodb-data--currentOp.clientMetadata"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Additional information on the client. </p> <p class="leafygreen-ui-1kp3ins"> For multi-document transactions, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.client" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.client </code> </span> </a> stores information about the most recent client to run an operation inside the transaction. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.appName </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.appName" title="Permalink to this definition"> <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="mongodb-data--currentOp.appName"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The identifier of the client application which ran the operation. Use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string-options/#mongodb-urioption-urioption.appName"> <code class="leafygreen-ui-1l06pbn"> appName </code> </a> connection string option to set a custom value for the <code class="leafygreen-ui-1l06pbn"> appName </code> field. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.active </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.active" title="Permalink to this definition"> <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="mongodb-data--currentOp.active"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A boolean value specifying whether the operation has started. Value is <code class="leafygreen-ui-1l06pbn"> true </code> if the operation has started or <code class="leafygreen-ui-1l06pbn"> false </code> if the operation is idle, such as an idle connection, an inactive session, or an internal thread that is currently idle. An operation can be active even if the operation has yielded to another operation. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Information on either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <span class="leafygreen-ui-1qnjd6d" id="std-label-agg-current-op-commit-coord-metrics"> </span> <p class="leafygreen-ui-1kp3ins"> The commit coordination metrics for a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> transaction whose write operations span multiple shards <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Commit coordination is handled by a shard, and <code class="leafygreen-ui-1l06pbn"> $currentOp </code> (run either on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> or a shard member) returns a shard's coordination information only for transactions the shard is currently coordinating. </p> <p class="leafygreen-ui-1kp3ins"> To filter for only the commit coordination metrics: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"admin\").aggregate( [\n { $currentOp: { allUsers: true, idleSessions: true } },\n { $match: { desc: \"transaction coordinator\" } }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</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">$currentOp</span>: <!-- -->{ <span class="lg-highlight-attr">allUsers</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">idleSessions</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-attr">desc</span>: <span class="lg-highlight-string">"transaction coordinator"</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> </li> <li class="leafygreen-ui-d7p7b6"> <span class="leafygreen-ui-1qnjd6d" id="std-label-agg-current-op-commit-coord-operation"> </span> <p class="leafygreen-ui-1kp3ins"> A specific commit coordination operation (i.e. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.type" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> type </code> </span> </a> is <code class="leafygreen-ui-1l06pbn"> op </code> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.desc" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> desc </code> </span> </a> is <code class="leafygreen-ui-1l06pbn"> "TransactionCoordinator" </code> ) spawned by the transaction coordinator. </p> </li> </ul> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If run with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-idleSessions" target="_self"> <span> idleSessions: false </span> </a> , <code class="leafygreen-ui-1l06pbn"> $currentOp </code> does not return the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator </code> </span> </a> information in <code class="leafygreen-ui-1l06pbn"> inactive </code> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.state" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> state </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If access control is enabled and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-allUsers" target="_self"> <span> allUsers: false </span> </a> , <code class="leafygreen-ui-1l06pbn"> $currentOp </code> does not return <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator </code> </span> </a> information. </p> </li> </ul> </div> </div> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.lsid </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.lsid" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator.lsid"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The session identifier for the multi-shard transaction. </p> <p class="leafygreen-ui-1kp3ins"> The combination of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.lsid" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> lsid </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.txnNumber" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> txnNumber </code> </span> </a> identifies the transaction. </p> <p class="leafygreen-ui-1kp3ins"> Available for both the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-metrics" target="_self"> <span> commit coordination metrics </span> </a> and for specific <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-operation" target="_self"> <span> coordination operation <!-- --> . </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.txnNumber </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.txnNumber" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator.txnNumber"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The transaction number for the multi-shard transaction. </p> <p class="leafygreen-ui-1kp3ins"> The combination of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.txnNumber" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> txnNumber </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.lsid" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> lsid </code> </span> </a> identifies the transaction. </p> <p class="leafygreen-ui-1kp3ins"> Available for both the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-metrics" target="_self"> <span> commit coordination metrics </span> </a> and for specific <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-operation" target="_self"> <span> coordination operation <!-- --> . </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.action </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.action" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator.action"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The specific commit coordination operation spawned by the transaction coordinator: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "sendingPrepare" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "sendingCommit" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "sendingAbort" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "writingParticipantList" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "writingDecision" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "deletingCoordinatorDoc" </code> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Only available for specific <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-operation" target="_self"> <span> coordination operation <!-- --> . </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.startTime </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.startTime" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator.startTime"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The start date and time of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.action" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> action </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> Only available for specific <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-operation" target="_self"> <span> coordination operation <!-- --> . </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.numParticipants </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.numParticipants" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator.numParticipants"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Number of shards participating in this commit. </p> <p class="leafygreen-ui-1kp3ins"> Only available for the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-metrics" target="_self"> <span> commit coordination metrics <!-- --> . </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.state </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.state" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator.state"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The current step/state of the commit coordination process. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Step/stage </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> inactive </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Not actively part of a commit. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> writingParticipantList </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Writing a local record of the list of shards that are part of this multi-shard transaction. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> waitingForVotes </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Waiting for the participants to respond with vote to commit or abort. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> writingDecision </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Writing a local record of the coordinator's decision to commit or abort based on votes. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> waitingForDecisionAck </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Waiting for participants to acknowledge the coordinator's decision to commit or abort. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> deletingCoordinatorDoc </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Deleting the local record of commit decision. </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Only available for the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-metrics" target="_self"> <span> commit coordination metrics <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> See also <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.stepDurations" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.stepDurations </code> . </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.commitStartTime </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.commitStartTime" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator.commitStartTime"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The date and time when the commit started. </p> <p class="leafygreen-ui-1kp3ins"> Only available for the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-metrics" target="_self"> <span> commit coordination metrics <!-- --> . </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.hasRecoveredFromFailover </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.hasRecoveredFromFailover" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator.hasRecoveredFromFailover"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A boolean that indicates whether the commit coordination was restarted due to failover on the shard that is coordinating the commit. </p> <p class="leafygreen-ui-1kp3ins"> If <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.hasRecoveredFromFailover" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> hasRecoveredFromFailover </code> </span> </a> is true, then the times specified in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.stepDurations" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.stepDurations </code> </span> </a> may not be accurate for all steps. </p> <p class="leafygreen-ui-1kp3ins"> Only available for the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-metrics" target="_self"> <span> commit coordination metrics <!-- --> . </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.stepDurations </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.stepDurations" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator.stepDurations"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A document that contains the duration, in microseconds, of the completed or in-progress <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.state" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> steps/state </code> </span> </a> of the active process as well as the cumulative total duration; for example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"stepDurations\" : {\n \"writingParticipantListMicros\" : NumberLong(17801),\n \"totalCommitDurationMicros\" : NumberLong(42488463),\n \"waitingForVotesMicros\" : NumberLong(30378502),\n \"writingDecisionMicros\" : NumberLong(15015),\n \"waitingForDecisionAcksMicros\" : NumberLong(12077145),\n \"deletingCoordinatorDocMicros\" : NumberLong(6009)\n},","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"stepDurations"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"writingParticipantListMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">17801</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"totalCommitDurationMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">42488463</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"waitingForVotesMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">30378502</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"writingDecisionMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">15015</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"waitingForDecisionAcksMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">12077145</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"deletingCoordinatorDocMicros"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">6009</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> <p class="leafygreen-ui-1kp3ins"> If <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.hasRecoveredFromFailover" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.hasRecoveredFromFailover </code> </span> </a> is true, then the times specified in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.stepDurations" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> stepDurations </code> </span> </a> may not be accurate for all steps. </p> <p class="leafygreen-ui-1kp3ins"> For a coordinator in an <code class="leafygreen-ui-1l06pbn"> inactive </code> state, the document is empty: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"stepDurations\" : {\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"><span class="lg-highlight-string">"stepDurations"</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> <p class="leafygreen-ui-1kp3ins"> Only available for the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-metrics" target="_self"> <span> commit coordination metrics <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.state" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.state </code> . </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.decision </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.decision" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator.decision"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A document that contains the commit/abort decision, for example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For a commit decision: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"decision\" : {\n \"decision\" : \"commit\",\n \"commitTimestamp\" : Timestamp(1572034669, 3)\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"><span class="lg-highlight-string">"decision"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"decision"</span> <!-- -->: <span class="lg-highlight-string">"commit"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"commitTimestamp"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1572034669</span>, <span class="lg-highlight-number">3</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For an abort decision: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"decision\" : {\n \"decision\" : \"abort\",\n \"abortStatus\" : {\n \"code\" : 282,\n \"codeName\" : \"TransactionCoordinatorReachedAbortDecision\",\n \"errmsg\" : \"Transaction exceeded deadline\"\n }\n}","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"decision"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"decision"</span> <!-- -->: <span class="lg-highlight-string">"abort"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"abortStatus"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"code"</span> <!-- -->: <span class="lg-highlight-number">282</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"codeName"</span> <!-- -->: <span class="lg-highlight-string">"TransactionCoordinatorReachedAbortDecision"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"errmsg"</span> <!-- -->: <span class="lg-highlight-string">"Transaction exceeded deadline"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Only available for the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-metrics" target="_self"> <span> commit coordination metrics <!-- --> . </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.twoPhaseCommitCoordinator.deadline </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.twoPhaseCommitCoordinator.deadline" title="Permalink to this definition"> <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="mongodb-data--currentOp.twoPhaseCommitCoordinator.deadline"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The date and time by which the commit must finish. </p> <p class="leafygreen-ui-1kp3ins"> Only available for the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-current-op-commit-coord-metrics" target="_self"> <span> commit coordination metrics <!-- --> . </span> </a> </p> </dd> </dl> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.currentOpTime </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.currentOpTime" title="Permalink to this definition"> <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="mongodb-data--currentOp.currentOpTime"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The start time of the operation. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.effectiveUsers </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.effectiveUsers" title="Permalink to this definition"> <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="mongodb-data--currentOp.effectiveUsers"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> An array that contains a document for each user associated with the operation. Each user document contains the <code class="leafygreen-ui-1l06pbn"> user </code> name and the authentication <code class="leafygreen-ui-1l06pbn"> db </code> . </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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.runBy" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.runBy </code> </span> </a> </p> </div> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.runBy </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.runBy" title="Permalink to this definition"> <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="mongodb-data--currentOp.runBy"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> An array that contains a document for each user who is impersonating the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.effectiveUsers" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> effectiveUser(s) </code> </span> </a> for the operation. The runBy document contains the <code class="leafygreen-ui-1l06pbn"> user </code> name and the authentication <code class="leafygreen-ui-1l06pbn"> db </code> . In general, the impersonating user is the <code class="leafygreen-ui-1l06pbn"> __system </code> user; e.g. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"runBy\" : [\n {\n \"user\" : \"__system\",\n \"db\" : \"local\"\n }\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"><span class="lg-highlight-string">"runBy"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"user"</span> <!-- -->: <span class="lg-highlight-string">"__system"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"db"</span> <!-- -->: <span class="lg-highlight-string">"local"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.opid </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.opid" title="Permalink to this definition"> <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="mongodb-data--currentOp.opid"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The identifier for the operation. You can pass this value to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.killOp/#mongodb-method-db.killOp"> <code class="leafygreen-ui-1l06pbn"> db.killOp() </code> </a> in <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> to terminate the operation. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Terminate running operations with extreme caution. Only use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.killOp/#mongodb-method-db.killOp"> <code class="leafygreen-ui-1l06pbn"> db.killOp() </code> </a> to terminate operations initiated by clients and <em> do not </em> terminate internal database operations. </p> </div> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.secs_running </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.secs_running" title="Permalink to this definition"> <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="mongodb-data--currentOp.secs_running"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The duration of the operation in seconds. MongoDB calculates this value by subtracting the current time from the start time of the operation. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is running; i.e. if <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.active" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> active </code> </span> </a> is <code class="leafygreen-ui-1l06pbn"> true </code> . </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.microsecs_running </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.microsecs_running" title="Permalink to this definition"> <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="mongodb-data--currentOp.microsecs_running"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The duration of the operation in microseconds. MongoDB calculates this value by subtracting the current time from the start time of the operation. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is running; i.e. if <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.active"> <code class="leafygreen-ui-1l06pbn"> active </code> </a> is <code class="leafygreen-ui-1l06pbn"> true </code> . </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.lsid </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.lsid" title="Permalink to this definition"> <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="mongodb-data--currentOp.lsid"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The session identifier. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is associated with a session. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A document that contains <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> multi-document transaction </a> information. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a transaction: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> On a replica set. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> On a sharded cluster if <code class="leafygreen-ui-1l06pbn"> $currentOp </code> is run <em> without </em> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps:true </span> </a> . The transaction information is per shard. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> On a sharded cluster if <code class="leafygreen-ui-1l06pbn"> $currentOp </code> is run with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps:true </span> </a> . The transaction information is a composite view rather than per shard. </p> </li> </ul> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.parameters </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.parameters" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.parameters"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A document that contains information on multi-document transaction. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a multi-document transaction. </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.parameters.txnNumber </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.parameters.txnNumber" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.parameters.txnNumber"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The transaction number. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a multi-document transaction. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.parameters.autocommit </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.parameters.autocommit" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.parameters.autocommit"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A boolean flag that indicates if autocommit is on for the transaction. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a multi-document transaction. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.parameters.readConcern </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.parameters.readConcern" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.parameters.readConcern"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-read-concern"> read concern </a> for the transaction. </p> <p class="leafygreen-ui-1kp3ins"> Multi-document transactions support read concern <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-"> <code class="leafygreen-ui-1l06pbn"> "snapshot" </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-"> <code class="leafygreen-ui-1l06pbn"> "local" </code> </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a multi-document transaction. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.globalReadTimestamp </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.globalReadTimestamp" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.globalReadTimestamp"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The timestamp of the snapshot read by the operations in the sharded cluster transaction that uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-read-concern-snapshot"> "snapshot" read concern </a> . For transactions on sharded clusters, the read concern <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-"> <code class="leafygreen-ui-1l06pbn"> "snapshot" </code> </a> of the data is synchronized across shards; i.e. other read concerns cannot guarantee that the data is from the same snapshot view across the shards. </p> <p class="leafygreen-ui-1kp3ins"> Only present when run with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps: true </span> </a> for sharded cluster transactions. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.readTimestamp </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.readTimestamp" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.readTimestamp"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The timestamp of the snapshot being read by the operations in this transaction </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a multi-document transaction. However, the field is not returned if: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the transaction is on a sharded cluster and uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-read-concern-snapshot"> "snapshot" read concern </a> , and </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $currentOp </code> is run with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps: true <!-- --> . </span> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Instead, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.globalReadTimestamp" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.globalReadTimestamp </code> </span> </a> is returned. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.startWallClockTime </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.startWallClockTime" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.startWallClockTime"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The date and time (with time zone) of the transaction start. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a multi-document transaction. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.timeOpenMicros </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.timeOpenMicros" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.timeOpenMicros"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The duration, in microseconds, for the transaction. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.timeActiveMicros" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> timeActiveMicros </code> </span> </a> value added to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.timeInactiveMicros" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> timeInactiveMicros </code> </span> </a> should equal the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.timeOpenMicros" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> timeOpenMicros </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a multi-document transaction. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.timeActiveMicros </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.timeActiveMicros" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.timeActiveMicros"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The total amount of time that the transaction has been active; i.e. when the transaction had operations running. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.timeActiveMicros" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> timeActiveMicros </code> </span> </a> value added to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.timeInactiveMicros" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> timeInactiveMicros </code> </span> </a> should equal the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.timeOpenMicros" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> timeOpenMicros </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a multi-document transaction. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.timeInactiveMicros </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.timeInactiveMicros" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.timeInactiveMicros"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The total amount of time that the transaction has been inactive; i.e. when the transaction had no operations running. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.timeInactiveMicros" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> timeInactiveMicros </code> </span> </a> value added to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.timeActiveMicros" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> timeActiveMicros </code> </span> </a> should equal the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.timeOpenMicros" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> timeOpenMicros </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a multi-document transaction. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.numParticipants </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.numParticipants" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.numParticipants"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Number of shards participating in this transaction. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a transaction on a sharded cluster and <code class="leafygreen-ui-1l06pbn"> $currentOp </code> is run with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps: true </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.participants </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.participants" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.participants"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> An array of documents detailing the participating shards in this transaction. Each document contains the name, a flag indicating if the shard acts as the commit coordinator, and a flag indicating if the shard is only involved in read operations for the transaction. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"name\" : \"shardA\",\n \"coordinator\" : false,\n \"readOnly\" : false\n}","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"shardA"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"coordinator"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"readOnly"</span> <!-- -->: <span class="lg-highlight-literal">false</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a transaction on a sharded cluster and <code class="leafygreen-ui-1l06pbn"> $currentOp </code> is run with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps: true </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.numReadOnlyParticipants </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.numReadOnlyParticipants" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.numReadOnlyParticipants"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Number of shards only affected by read operations in this transaction. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a transaction on a sharded cluster and <code class="leafygreen-ui-1l06pbn"> $currentOp </code> is run with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps: true </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.numNonReadOnlyParticipants </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.numNonReadOnlyParticipants" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.numNonReadOnlyParticipants"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Number of shards affected by operations other than reads in this transaction. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a transaction on a sharded cluster and <code class="leafygreen-ui-1l06pbn"> $currentOp </code> is run with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-currentOp-stage-localOps" target="_self"> <span> localOps: true </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.expiryTime </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.transaction.expiryTime" title="Permalink to this definition"> <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="mongodb-data--currentOp.transaction.expiryTime"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The date and time (with time zone) when the transaction will time out and abort. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.expiryTime" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.expiryTime </code> </span> </a> equals the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.transaction.startWallClockTime" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.transaction.startWallClockTime </code> </span> </a> + the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.transactionLifetimeLimitSeconds"> <code class="leafygreen-ui-1l06pbn"> transactionLifetimeLimitSeconds </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> For more information, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-production-consideration/#std-label-transaction-limit"> Runtime Limit </a> for transactions. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the operation is part of a multi-document transaction. </p> </dd> </dl> </dd> </dl> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.op </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.op" title="Permalink to this definition"> <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="mongodb-data--currentOp.op"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A string that identifies the specific operation type. Only present if <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.type" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $currentOp.type </code> </span> </a> is <code class="leafygreen-ui-1l06pbn"> op </code> . </p> <p class="leafygreen-ui-1kp3ins"> The possible values are: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "none" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "update" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "insert" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "query" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "command" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "getmore" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "remove" </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "killcursors" </code> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "command" </code> operations include most <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/#std-label-database-commands"> commands </a> such as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/createIndexes/#mongodb-dbcommand-dbcmd.createIndexes"> <code class="leafygreen-ui-1l06pbn"> createIndexes </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate"> <code class="leafygreen-ui-1l06pbn"> aggregate </code> </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/findAndModify/#mongodb-dbcommand-dbcmd.findAndModify"> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "query" </code> operations include <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/find/#mongodb-dbcommand-dbcmd.find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> operations and OP_QUERY operations. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.ns </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.ns" title="Permalink to this definition"> <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="mongodb-data--currentOp.ns"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace"> namespace </a> the operation targets. A namespace consists of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-database"> database </a> name and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-collection"> collection </a> name concatenated with a dot ( <code class="leafygreen-ui-1l06pbn"> . </code> ); that is, <code class="leafygreen-ui-1l06pbn"> "&lt;database&gt;.&lt;collection&gt;" </code> . </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.command </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.command" title="Permalink to this definition"> <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="mongodb-data--currentOp.command"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A document containing the full command object associated with this operation. </p> <p class="leafygreen-ui-1kp3ins"> For example, the following output contains the command object for a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/find/#mongodb-dbcommand-dbcmd.find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> operation on a collection named <code class="leafygreen-ui-1l06pbn"> items </code> in a database named <code class="leafygreen-ui-1l06pbn"> test </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"command\" : {\n \"find\" : \"items\",\n \"filter\" : {\n \"sku\" : 1403978\n },\n ...\n \"$db\" : \"test\"\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"><span class="lg-highlight-string">"command"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"find"</span> <!-- -->: <span class="lg-highlight-string">"items"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"filter"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-number">1403978</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$db"</span> <!-- -->: <span class="lg-highlight-string">"test"</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> <p class="leafygreen-ui-1kp3ins"> The following example output contains the command object for a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getMore/#mongodb-dbcommand-dbcmd.getMore"> <code class="leafygreen-ui-1l06pbn"> getMore </code> </a> operation generated by a command with cursor ID <code class="leafygreen-ui-1l06pbn"> 19234103609 </code> on a collection named <code class="leafygreen-ui-1l06pbn"> items </code> in a database named <code class="leafygreen-ui-1l06pbn"> test </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"command\" : {\n \"getMore\" : NumberLong(\"19234103609\"),\n \"collection\" : \"items\",\n \"batchSize\" : 10,\n ...\n \"$db\" : \"test\"\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"><span class="lg-highlight-string">"command"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"getMore"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"19234103609"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"collection"</span> <!-- -->: <span class="lg-highlight-string">"items"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"batchSize"</span> <!-- -->: <span class="lg-highlight-number">10</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$db"</span> <!-- -->: <span class="lg-highlight-string">"test"</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> <p class="leafygreen-ui-1kp3ins"> If the command document exceeds 1 kilobyte, the document has the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"command\" : {\n \"$truncated\": &lt;string&gt;,\n \"comment\": &lt;string&gt;\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"><span class="lg-highlight-string">"command"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$truncated"</span>: &lt;<!-- -->string<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"comment"</span>: &lt;<!-- -->string<!-- -->&gt;</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> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $truncated </code> field contains a string summary of the document excluding the document's <code class="leafygreen-ui-1l06pbn"> comment </code> field if present. If the summary still exceeds 1 kilobyte then it is further truncated, denoted by an ellipsis (...) at the end of the string. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> comment </code> field is present if a comment was passed to the operation. A comment may be attached to any <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/#std-label-database-commands"> database command <!-- --> . </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A document that contains the cursor information for <code class="leafygreen-ui-1l06pbn"> idleCursor </code> and <code class="leafygreen-ui-1l06pbn"> getmore </code> operations; i.e. where <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.type"> <code class="leafygreen-ui-1l06pbn"> type </code> </a> is <code class="leafygreen-ui-1l06pbn"> idleCursor </code> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.op"> <code class="leafygreen-ui-1l06pbn"> op </code> </a> is <code class="leafygreen-ui-1l06pbn"> getmore </code> . </p> <p class="leafygreen-ui-1kp3ins"> If reporting on a <code class="leafygreen-ui-1l06pbn"> getmore </code> operation before the <code class="leafygreen-ui-1l06pbn"> getmore </code> has accessed its cursor information, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.cursor"> <code class="leafygreen-ui-1l06pbn"> cursor </code> </a> field is not available. </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.cursorId </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.cursorId" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.cursorId"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The ID of the cursor. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.createdDate </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.createdDate" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.createdDate"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The date and time when the cursor was created. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.lastAccessDate </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.lastAccessDate" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.lastAccessDate"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The date and time when the cursor was last used. </p> <p class="leafygreen-ui-1kp3ins"> If the cursor is actively in use (i.e. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.op"> <code class="leafygreen-ui-1l06pbn"> op </code> </a> is <code class="leafygreen-ui-1l06pbn"> getmore </code> and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.type"> <code class="leafygreen-ui-1l06pbn"> type </code> </a> is not <code class="leafygreen-ui-1l06pbn"> idleCursor </code> ), then <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.cursor.lastAccessDate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> lastAccessDate </code> </span> </a> reports either the time the previous <code class="leafygreen-ui-1l06pbn"> getmore </code> ended or the time the cursor was created if this is the first <code class="leafygreen-ui-1l06pbn"> getmore </code> . </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.nDocsReturned </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.nDocsReturned" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.nDocsReturned"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The cumulative number of documents returned by the cursor. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.nBatchesReturned </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.nBatchesReturned" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.nBatchesReturned"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The cumulative number of batches returned by the cursor. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.noCursorTimeout </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.noCursorTimeout" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.noCursorTimeout"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The flag that indicates that the cursor doesn't timeout when idle; i.e. if the cursor has the <code class="leafygreen-ui-1l06pbn"> noTimeout </code> option set. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If true, the cursor does not time out when idle. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If false, the cursor times out when idle. </p> </li> </ul> <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/reference/method/cursor.addOption/#mongodb-method-cursor.addOption"> <code class="leafygreen-ui-1l06pbn"> cursor.addOption() </code> </a> </p> </div> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.tailable </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.tailable" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.tailable"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The flag that indicates if the cursor is a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/tailable-cursors/#std-label-tailable-cursors-landing-page"> tailable cursor </a> for a capped collection. Tailable cursors remain open after the client exhausts the results in the initial cursor. </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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/find/#mongodb-dbcommand-dbcmd.find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.tailable/#mongodb-method-cursor.tailable"> <code class="leafygreen-ui-1l06pbn"> cursor.tailable() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.addOption/#mongodb-method-cursor.addOption"> <code class="leafygreen-ui-1l06pbn"> cursor.addOption() </code> </a> </p> </li> </ul> </div> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.awaitData </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.awaitData" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.awaitData"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The flag that indicates whether the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/tailable-cursors/#std-label-tailable-cursors-landing-page"> tailable cursor </a> should temporarily block a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getMore/#mongodb-dbcommand-dbcmd.getMore"> <code class="leafygreen-ui-1l06pbn"> getMore </code> </a> command on the cursor while waiting for new data rather than returning no data. </p> <p class="leafygreen-ui-1kp3ins"> For non-tailable cursors, the value is always false. </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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/find/#mongodb-dbcommand-dbcmd.find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.tailable/#mongodb-method-cursor.tailable"> <code class="leafygreen-ui-1l06pbn"> cursor.tailable() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.addOption/#mongodb-method-cursor.addOption"> <code class="leafygreen-ui-1l06pbn"> cursor.addOption() </code> </a> </p> </li> </ul> </div> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.originatingCommand </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.originatingCommand" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.originatingCommand"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> originatingCommand </code> field contains the full command object (e.g. <code class="leafygreen-ui-1l06pbn"> find </code> or <code class="leafygreen-ui-1l06pbn"> aggregate </code> ) which originally created the cursor. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.planSummary </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.planSummary" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.planSummary"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A string that specifies whether the cursor uses a collection scan ( <code class="leafygreen-ui-1l06pbn"> COLLSCAN </code> ) or an index scan ( <code class="leafygreen-ui-1l06pbn"> IXSCAN { ... } </code> ). </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> IXSCAN </code> also includes the specification document of the index used. </p> <p class="leafygreen-ui-1kp3ins"> Not available when running with <code class="leafygreen-ui-1l06pbn"> localOps: true </code> on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> or when reporting on <code class="leafygreen-ui-1l06pbn"> idleCursors </code> . </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.operationUsingCursorId </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.operationUsingCursorId" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.operationUsingCursorId"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> opid </code> of the operation using the cursor. </p> <p class="leafygreen-ui-1kp3ins"> Only present if the cursor is not idle. </p> </dd> </dl> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.cursor.queryFramework </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.cursor.queryFramework" title="Permalink to this definition"> <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="mongodb-data--currentOp.cursor.queryFramework"> </div> </a> </dt> <dd> <div> <p> <em> New <!-- --> in version <!-- --> 6.2 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> A string that specifies the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-query-framework"> query framework </a> used to process an operation. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.planSummary </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.planSummary" title="Permalink to this definition"> <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="mongodb-data--currentOp.planSummary"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A string that specifies whether the cursor uses a collection scan ( <code class="leafygreen-ui-1l06pbn"> COLLSCAN </code> ) or an index scan ( <code class="leafygreen-ui-1l06pbn"> IXSCAN { ... } </code> ). </p> <p class="leafygreen-ui-1kp3ins"> Not available when running with <code class="leafygreen-ui-1l06pbn"> localOps: true </code> on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> . </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.prepareReadConflicts </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.prepareReadConflicts" title="Permalink to this definition"> <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="mongodb-data--currentOp.prepareReadConflicts"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of times the current operation had to wait for a prepared transaction with a write to commit or abort. </p> <p class="leafygreen-ui-1kp3ins"> While waiting, the operation continues to hold any necessary locks and storage engine resources. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.writeConflicts </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.writeConflicts" title="Permalink to this definition"> <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="mongodb-data--currentOp.writeConflicts"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of times the current operation conflicted with another write operation on the same document. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.numYields </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.numYields" title="Permalink to this definition"> <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="mongodb-data--currentOp.numYields"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.numYields" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> numYields </code> </span> </a> is a counter that reports the number of times the operation has yielded to allow other operations to complete. </p> <p class="leafygreen-ui-1kp3ins"> Typically, operations yield when they need access to data that MongoDB has not yet fully read into memory. This allows other operations that have data in memory to complete quickly while MongoDB reads in data for the yielding operation. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.queryShapeHash </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.queryShapeHash" title="Permalink to this definition"> <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="mongodb-data--currentOp.queryShapeHash"> </div> </a> </dt> <dd> <div> <p> <em> New <!-- --> in version <!-- --> 8.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> queryShapeHash </code> is a hexadecimal string with the hash of a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-query-shape"> query shape </a> . For details, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-shapes/#std-label-query-shapes"> Query Shapes <!-- --> . </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.dataThroughputLastSecond </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.dataThroughputLastSecond" title="Permalink to this definition"> <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="mongodb-data--currentOp.dataThroughputLastSecond"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Amount of data (in MiB) processed by the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/validate/#mongodb-dbcommand-dbcmd.validate"> <code class="leafygreen-ui-1l06pbn"> validate </code> </a> operation in the last second. Only available for a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/validate/#mongodb-dbcommand-dbcmd.validate"> <code class="leafygreen-ui-1l06pbn"> validate </code> </a> operation that is currently scanning documents. For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"msg\" : \"Validate: scanning documents Validate: scanning documents: 7258/24000 30%\",\n\"progress\" : {\n \"done\" : 7258,\n \"total\" : 24000\n},\n\"numYields\" : 0,\n\"dataThroughputLastSecond\" : 15.576952934265137,\n\"dataThroughputAverage\" : 15.375944137573242,","programmingLanguage":"JSON"} </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 json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">"msg"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"Validate: scanning documents Validate: scanning documents: 7258/24000 30%"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">"progress"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"done"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">7258</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"total"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">24000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">"numYields"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">"dataThroughputLastSecond"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">15.576952934265137</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">"dataThroughputAverage"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">15.375944137573242</span><span class="lg-highlight-punctuation">,</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> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.dataThroughputAverage </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.dataThroughputAverage" title="Permalink to this definition"> <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="mongodb-data--currentOp.dataThroughputAverage"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The average amount of data (in MiB) processed by the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/validate/#mongodb-dbcommand-dbcmd.validate"> <code class="leafygreen-ui-1l06pbn"> validate </code> </a> operation. Only available for a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/validate/#mongodb-dbcommand-dbcmd.validate"> <code class="leafygreen-ui-1l06pbn"> validate </code> </a> operation that is currently scanning documents. For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"msg\" : \"Validate: scanning documents Validate: scanning documents: 7258/24000 30%\",\n\"progress\" : {\n \"done\" : 7258,\n \"total\" : 24000\n},\n\"numYields\" : 0,\n\"dataThroughputLastSecond\" : 15.576952934265137,\n\"dataThroughputAverage\" : 15.375944137573242,","programmingLanguage":"JSON"} </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 json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">"msg"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"Validate: scanning documents Validate: scanning documents: 7258/24000 30%"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">"progress"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"done"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">7258</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"total"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">24000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">"numYields"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">"dataThroughputLastSecond"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">15.576952934265137</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">"dataThroughputAverage"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">15.375944137573242</span><span class="lg-highlight-punctuation">,</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> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.locks </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.locks" title="Permalink to this definition"> <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="mongodb-data--currentOp.locks"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.locks" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> locks </code> </span> </a> document reports the type and mode of locks the operation currently holds. The possible lock types are as follows: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Lock Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> ParallelBatchWriterMode </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Represents a lock for parallel batch writer mode. </p> <p class="leafygreen-ui-1kp3ins"> In earlier versions, PBWM information was reported as part of the <code class="leafygreen-ui-1l06pbn"> Global </code> lock information. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> ReplicationStateTransition </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Represents lock taken for <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/"> replica set member state </a> transitions. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> Global </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Represents global lock. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> Database </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Represents database lock. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> Collection </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Represents collection lock. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> Mutex </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Represents mutex. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> Metadata </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Represents metadata lock. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> DDLDatabase </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Represents a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-DDL--Data-Definition-Language-"> DDL </a> database lock. </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.1 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> DDLCollection </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Represents a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-DDL--Data-Definition-Language-"> DDL </a> collection lock. </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.1 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> oplog </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Represents lock on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog <!-- --> . </a> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> The possible modes are as follows: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Lock Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> R </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Represents Shared (S) lock. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> W </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Represents Exclusive (X) lock. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> r </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Represents Intent Shared (IS) lock. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> w </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Represents Intent Exclusive (IX) lock. </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.lockStats </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.lockStats" title="Permalink to this definition"> <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="mongodb-data--currentOp.lockStats"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> For each lock type and mode (see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.locks" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> locks </code> </span> </a> for descriptions of lock types and modes), returns the following information: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.lockStats.acquireCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.lockStats.acquireCount" title="Permalink to this definition"> <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="mongodb-data--currentOp.lockStats.acquireCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Number of times the operation acquired the lock in the specified mode. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.lockStats.acquireWaitCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.lockStats.acquireWaitCount" title="Permalink to this definition"> <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="mongodb-data--currentOp.lockStats.acquireWaitCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Number of times the operation had to wait for the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.lockStats.acquireCount" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> acquireCount </code> </span> </a> lock acquisitions because the locks were held in a conflicting mode. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.lockStats.acquireWaitCount" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> acquireWaitCount </code> </span> </a> is less than or equal to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.lockStats.acquireCount" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> acquireCount </code> . </span> </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.lockStats.timeAcquiringMicros </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.lockStats.timeAcquiringMicros" title="Permalink to this definition"> <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="mongodb-data--currentOp.lockStats.timeAcquiringMicros"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Cumulative time in microseconds that the operation had to wait to acquire the locks. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.lockStats.timeAcquiringMicros" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> timeAcquiringMicros </code> </span> </a> divided by <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.lockStats.acquireWaitCount" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> acquireWaitCount </code> </span> </a> gives an approximate average wait time for the particular lock mode. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.lockStats.deadlockCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.lockStats.deadlockCount" title="Permalink to this definition"> <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="mongodb-data--currentOp.lockStats.deadlockCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Number of times the operation encountered deadlocks while waiting for lock acquisitions. </p> </dd> </dl> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.waitingForLock </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.waitingForLock" title="Permalink to this definition"> <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="mongodb-data--currentOp.waitingForLock"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Returns a boolean value. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.waitingForLock" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> waitingForLock </code> </span> </a> is <code class="leafygreen-ui-1l06pbn"> true </code> if the operation is waiting for a lock and <code class="leafygreen-ui-1l06pbn"> false </code> if the operation has the required lock. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.msg </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.msg" title="Permalink to this definition"> <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="mongodb-data--currentOp.msg"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.msg" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> msg </code> </span> </a> provides a message that describes the status and progress of the operation. In the case of indexing or mapReduce operations, the field reports the completion percentage. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.progress </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.progress" title="Permalink to this definition"> <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="mongodb-data--currentOp.progress"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Reports on the progress of mapReduce or indexing operations. The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.progress" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> progress </code> </span> </a> fields corresponds to the completion percentage in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.msg" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> msg </code> </span> </a> field. The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data--currentOp.progress" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> progress </code> </span> </a> specifies the following information: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.progress.done </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.progress.done" title="Permalink to this definition"> <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="mongodb-data--currentOp.progress.done"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Reports the number of work items completed. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.progress.total </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.progress.total" title="Permalink to this definition"> <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="mongodb-data--currentOp.progress.total"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Reports the total number of work items. </p> </dd> </dl> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.killPending </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.killPending" title="Permalink to this definition"> <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="mongodb-data--currentOp.killPending"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Returns <code class="leafygreen-ui-1l06pbn"> true </code> if the operation is currently flagged for termination. When the operation encounters its next safe termination point, the operation terminates. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.waitingForFlowControl </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.waitingForFlowControl" title="Permalink to this definition"> <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="mongodb-data--currentOp.waitingForFlowControl"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A boolean that indicates if the operation had to wait because of <a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/#std-label-replication-flow-control"> flow control <!-- --> . </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.flowControlStats </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.flowControlStats" title="Permalink to this definition"> <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="mongodb-data--currentOp.flowControlStats"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The flow control statistics for this operation. </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.flowControlStats.acquireCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.flowControlStats.acquireCount" title="Permalink to this definition"> <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="mongodb-data--currentOp.flowControlStats.acquireCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of times this operation acquired a ticket. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.flowControlStats.acquireWaitCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.flowControlStats.acquireWaitCount" title="Permalink to this definition"> <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="mongodb-data--currentOp.flowControlStats.acquireWaitCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of times this operation waited to acquire a ticket. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.flowControlStats.timeAcquiringMicros </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.flowControlStats.timeAcquiringMicros" title="Permalink to this definition"> <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="mongodb-data--currentOp.flowControlStats.timeAcquiringMicros"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The total time this operation has waited to acquire a ticket. </p> </dd> </dl> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.totalOperationTimeElapsed </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.totalOperationTimeElapsed" title="Permalink to this definition"> <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="mongodb-data--currentOp.totalOperationTimeElapsed"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The total time elapsed, in seconds, for the current <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . The time is set to 0 when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present if a resharding operation is taking place. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.remainingOperationTimeEstimated </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.remainingOperationTimeEstimated" title="Permalink to this definition"> <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="mongodb-data--currentOp.remainingOperationTimeEstimated"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The estimated time remaining in seconds for the current <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . The time is set to -1 when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present when a resharding operation is taking place. This field may not be present if an estimate cannot not be computed. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.approxDocumentsToCopy </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.approxDocumentsToCopy" title="Permalink to this definition"> <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="mongodb-data--currentOp.approxDocumentsToCopy"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The approximate number of documents to be copied from the donor shards to the recipient shards during the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . This number is an estimate that is set at the beginning of the resharding operation and does not change after it has been set. The number is set to 0 when a new resharding operation starts. It is possible for <code class="leafygreen-ui-1l06pbn"> $currentOp.documentsCopied </code> and <code class="leafygreen-ui-1l06pbn"> $currentOp.bytesCopied </code> to end up exceeding <code class="leafygreen-ui-1l06pbn"> $currentOp.approxDocumentsToCopy </code> and <code class="leafygreen-ui-1l06pbn"> $currentOp.approxBytesToCopy </code> , respectively, if the post-resharding data distribution is not perfectly uniform. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a recipient shard when a resharding operation is taking place. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.documentsCopied </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.documentsCopied" title="Permalink to this definition"> <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="mongodb-data--currentOp.documentsCopied"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of documents copied form donor shards to recipient shards during the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . The number is set to 0 when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a recipient shard when a resharding operation is taking place. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.approxBytesToCopy </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.approxBytesToCopy" title="Permalink to this definition"> <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="mongodb-data--currentOp.approxBytesToCopy"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The approximate number of bytes to be copied from the donor shards to the recipient shards during the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . This number is an estimate that is set at the beginning of the resharding operation and does not change after it has been set. The number is set to 0 when a new resharding operation starts. It is possible for <code class="leafygreen-ui-1l06pbn"> $currentOp.documentsCopied </code> and <code class="leafygreen-ui-1l06pbn"> $currentOp.bytesCopied </code> to end up exceeding <code class="leafygreen-ui-1l06pbn"> $currentOp.approxDocumentsToCopy </code> and <code class="leafygreen-ui-1l06pbn"> $currentOp.approxBytesToCopy </code> , respectively, if the post-resharding data distribution is not perfectly uniform. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a recipient shard when a resharding operation is taking place. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.bytesCopied </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.bytesCopied" title="Permalink to this definition"> <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="mongodb-data--currentOp.bytesCopied"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of bytes copied from donor shards to recipient shards during the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . The number is set to 0 when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a recipient shard when a resharding operation is taking place. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.totalCopyTimeElapsed </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.totalCopyTimeElapsed" title="Permalink to this definition"> <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="mongodb-data--currentOp.totalCopyTimeElapsed"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The total elapsed time, in seconds, for ongoing data copy tasks from donor shards to recipient shards for the current resharding operation. The time is set to 0 when a new <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a recipient shard when a resharding operation is taking place. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.oplogEntriesFetched </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.oplogEntriesFetched" title="Permalink to this definition"> <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="mongodb-data--currentOp.oplogEntriesFetched"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of entries fetched from the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> for the current <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . The number is set to 0 when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a recipient shard when a resharding operation is taking place. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.oplogEntriesApplied </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.oplogEntriesApplied" title="Permalink to this definition"> <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="mongodb-data--currentOp.oplogEntriesApplied"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of entries applied to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> for the current <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . The number is set to 0 when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a recipient shard when a resharding operation is taking place. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.totalApplyTimeElapsed </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.totalApplyTimeElapsed" title="Permalink to this definition"> <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="mongodb-data--currentOp.totalApplyTimeElapsed"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The total elapsed time, in seconds, for the apply step of the current <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . In the apply step, recipient shards apply <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> entries to modify their data based on new incoming writes from donor shards. The time is set to 0 when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a recipient shard when a resharding operation is taking place. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.countWritesDuringCriticalSection </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.countWritesDuringCriticalSection" title="Permalink to this definition"> <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="mongodb-data--currentOp.countWritesDuringCriticalSection"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of writes performed in the critical section for the current <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . The critical section prevents new incoming writes to the collection currently being resharded. The number is set to 0 when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a donor shard when a resharding operation is taking place. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.totalCriticalSectionTimeElapsed </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.totalCriticalSectionTimeElapsed" title="Permalink to this definition"> <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="mongodb-data--currentOp.totalCriticalSectionTimeElapsed"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The total elapsed time, in seconds, for the critical section of the current <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . The critical section prevents new incoming writes to the collection currently being resharded. The time is set to 0 when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a donor shard when a resharding operation is taking place. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.donorState </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.donorState" title="Permalink to this definition"> <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="mongodb-data--currentOp.donorState"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The current state of a donor shard for the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . The state is set to <code class="leafygreen-ui-1l06pbn"> unused </code> when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a donor shard when a resharding operation is taking place. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> State </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> unused </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding operation is about to start or recovering from a primary failover. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> preparing-to-donate </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The donor shard is preparing to donate data to the recipient shards. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> donating-initial-data </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The donor shard is donating data to the recipient shards. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> donating-oplog-entries </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The donor shard is donating <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> entries to the recipient shards. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> preparing-to-block-writes </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The donor shard is about to prevent new incoming write operations to the collection that is being resharded. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> error </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An error occurred during the resharding operation. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> blocking-writes </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The donor shard is preventing new incoming write operations and the donor shard has notified all recipient shards that new incoming writes are prevented. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> done </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The donor shard has dropped the old sharded collection and the resharding operation is complete. </div> </div> </td> </tr> </tbody> </table> </div> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.recipientState </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.recipientState" title="Permalink to this definition"> <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="mongodb-data--currentOp.recipientState"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The current state of a recipient shard for a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . The state is set to <code class="leafygreen-ui-1l06pbn"> unused </code> when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present on a donor shard when a resharding operation is taking place. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> State </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> unused </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding operation is about to start or recovering from a primary failover. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> awaiting-fetch-timestamp </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The recipient shard is waiting for the donor shards to be prepared to donate their data. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> creating-collection </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The recipient shard is creating the new sharded collection. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> cloning </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The recipient shard is receiving data from the donor shards. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> applying </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The recipient shard is applying <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> entries to modify its copy of the data based on the new incoming writes from donor shards. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> error </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An error occurred during the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation <!-- --> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> strict-consistency </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The recipient shard has all data changes stored in a temporary collection. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> done </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding operation is complete. </div> </div> </td> </tr> </tbody> </table> </div> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.coordinatorState </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.coordinatorState" title="Permalink to this definition"> <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="mongodb-data--currentOp.coordinatorState"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The state of the resharding coordinator for the current <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> . The resharding coordinator is an operation that runs on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-config-servers/#std-label-sharding-config-server"> config server </a> primary. The state is set to <code class="leafygreen-ui-1l06pbn"> unused </code> when a new resharding operation starts. </p> <p class="leafygreen-ui-1kp3ins"> Only present on the coordinating config server. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> State </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> unused </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding operation is about to start or recovering from a primary failover. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> initializing </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding coordinator has inserted the coordinator document into <code class="leafygreen-ui-1l06pbn"> config.reshardingOperations </code> and has added the <code class="leafygreen-ui-1l06pbn"> reshardingFields </code> to the <code class="leafygreen-ui-1l06pbn"> config.collections </code> entry for the original collection. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> preparing-to-donate </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> The resharding coordinator </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> has created a <code class="leafygreen-ui-1l06pbn"> config.collections </code> entry for the temporary resharding collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> has inserted entries into <code class="leafygreen-ui-1l06pbn"> config.chunks </code> for ranges based on the new shard key. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> has inserted entries into <code class="leafygreen-ui-1l06pbn"> config.tags </code> for any zones associated with the new shard key. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The coordinator informs participant shards to begin the resharding operation. The coordinator then waits until all donor shards have picked a <code class="leafygreen-ui-1l06pbn"> minFetchTimestamp </code> and are ready to donate. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> cloning </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding coordinator informs donor shards to donate data to recipient shards. The coordinator waits for all recipients to finish cloning the data from the donor. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> applying </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding coordinator informs recipient shards to modify their copies of data based on new incoming writes from donor shards. The coordinator waits for all recipients to finish applying <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> entries. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> blocking-writes </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding coordinator informs donor shards to prevent new incoming write operations to the collection being resharded. The coordinator then waits for all recipients to have all data changes. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> aborting </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An unrecoverable error occurred during the resharding operation or the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/abortReshardCollection/#mongodb-dbcommand-dbcmd.abortReshardCollection"> <code class="leafygreen-ui-1l06pbn"> abortReshardCollection </code> </a> command (or the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.abortReshardCollection/#mongodb-method-sh.abortReshardCollection"> <code class="leafygreen-ui-1l06pbn"> sh.abortReshardCollection() </code> </a> method) was run. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> committing </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding coordinator removes the <code class="leafygreen-ui-1l06pbn"> config.collections </code> entry for the temporary resharding collection. The coordinator then adds the <code class="leafygreen-ui-1l06pbn"> recipientFields </code> to the source collection's entry. </div> </div> </td> </tr> </tbody> </table> </div> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.opStatus </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.opStatus" title="Permalink to this definition"> <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="mongodb-data--currentOp.opStatus"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The current state of a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Only present if a resharding operation is taking place. Once the operation has completed, the operation is removed from <code class="leafygreen-ui-1l06pbn"> currentOp </code> output. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> State </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> actively running </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding operation is actively running. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> success </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding operation has succeeded. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> failure </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding operation has failed. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> canceled </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The resharding operation was canceled. </div> </div> </td> </tr> </tbody> </table> </div> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </dd> </dl> <span class="leafygreen-ui-1qnjd6d" id="std-label-currentOp-agg-query-sampling-fields"> </span> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.collUuid </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.collUuid" title="Permalink to this definition"> <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="mongodb-data--currentOp.collUuid"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The UUID of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/configureQueryAnalyzer/#std-label-configureQueryAnalyzer"> sampled collection <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> This field only appears on documents related to query sampling. For details, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sampled-queries-currentOp-stage" target="_self"> <span> Sampled Queries <!-- --> . </span> </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.startTime </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.startTime" title="Permalink to this definition"> <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="mongodb-data--currentOp.startTime"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The time at which query sampling began. </p> <p class="leafygreen-ui-1kp3ins"> This field only appears on documents related to query sampling. For details, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sampled-queries-currentOp-stage" target="_self"> <span> Sampled Queries <!-- --> . </span> </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.samplesPerSecond </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.samplesPerSecond" title="Permalink to this definition"> <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="mongodb-data--currentOp.samplesPerSecond"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The maximum number of queries to sample per second. </p> <p class="leafygreen-ui-1kp3ins"> Only reported when running <code class="leafygreen-ui-1l06pbn"> $currentOp </code> on <code class="leafygreen-ui-1l06pbn"> mongos </code> . </p> <p class="leafygreen-ui-1kp3ins"> This field only appears on documents related to query sampling. For details, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sampled-queries-currentOp-stage" target="_self"> <span> Sampled Queries <!-- --> . </span> </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.sampledReadsCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.sampledReadsCount" title="Permalink to this definition"> <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="mongodb-data--currentOp.sampledReadsCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of sampled read queries. </p> <p class="leafygreen-ui-1kp3ins"> This field only appears on documents related to query sampling. For details, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sampled-queries-currentOp-stage" target="_self"> <span> Sampled Queries <!-- --> . </span> </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.sampledWritesCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.sampledWritesCount" title="Permalink to this definition"> <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="mongodb-data--currentOp.sampledWritesCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of sampled write queries. </p> <p class="leafygreen-ui-1kp3ins"> This field only appears on documents related to query sampling. For details, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sampled-queries-currentOp-stage" target="_self"> <span> Sampled Queries <!-- --> . </span> </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.sampledReadsBytes </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.sampledReadsBytes" title="Permalink to this definition"> <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="mongodb-data--currentOp.sampledReadsBytes"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The size of the sampled read queries, in bytes. </p> <p class="leafygreen-ui-1kp3ins"> On a replica set, this is reported on every <code class="leafygreen-ui-1l06pbn"> mongod </code> . </p> <p class="leafygreen-ui-1kp3ins"> On a sharded cluster, this only reported on <code class="leafygreen-ui-1l06pbn"> mongod </code> with <code class="leafygreen-ui-1l06pbn"> --shardsvr </code> . </p> <p class="leafygreen-ui-1kp3ins"> This field only appears on documents related to query sampling. For details, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sampled-queries-currentOp-stage" target="_self"> <span> Sampled Queries <!-- --> . </span> </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> $currentOp.sampledWritesBytes </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data--currentOp.sampledWritesBytes" title="Permalink to this definition"> <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="mongodb-data--currentOp.sampledWritesBytes"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The size of the sampled write queries, in bytes. </p> <p class="leafygreen-ui-1kp3ins"> On a replica set, this is reported on every <code class="leafygreen-ui-1l06pbn"> mongod </code> . </p> <p class="leafygreen-ui-1kp3ins"> On a sharded cluster, this only reported on <code class="leafygreen-ui-1l06pbn"> mongod </code> with <code class="leafygreen-ui-1l06pbn"> --shardsvr </code> . </p> <p class="leafygreen-ui-1kp3ins"> This field only appears on documents related to query sampling. For details, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sampled-queries-currentOp-stage" target="_self"> <span> Sampled Queries <!-- --> . </span> </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> </dd> </dl> </section> </section>
https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> MongoDB Extended JSON (v2) <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-extended-json--v2-" 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="mongodb-extended-json--v2-"> </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="#mongodb-extended-json-v2-usage" target="_self"> <span> MongoDB Extended JSON v2 Usage </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#bson-data-types-and-associated-representations" target="_self"> <span> BSON Data Types and Associated Representations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-extended-json-high-level-ref-v2"> </span> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Disambiguation </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The following page discusses MongoDB Extended JSON v2. For discussion on the Legacy MongoDB Extended JSON v1, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json-v1/"> MongoDB Extended JSON (v1) <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> For supported data types in <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> , see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/" target="_self"> <span> mongosh Data Types <!-- --> . </span> </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-JSON"> JSON </a> can only directly represent a subset of the types supported by <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-BSON"> BSON </a> . To preserve type information, MongoDB adds the following extensions to the JSON format. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <dl> <dt> Canonical Mode </dt> <dd class="css-1ufxuu7"> A string format that emphasizes type preservation at the expense of readability and interoperability. That is, conversion from canonical to BSON will generally preserve type information except in certain specific cases. </dd> </dl> </li> <li class="leafygreen-ui-d7p7b6"> <dl> <dt> Relaxed Mode </dt> <dd class="css-1ufxuu7"> A string format that emphasizes readability and interoperability at the expense of type preservation. That is, conversion from relaxed format to BSON can lose type information. </dd> </dl> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Both formats conform to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.json.org" rel="noopener noreferrer"> <span> JSON RFC </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> and can be parsed by the various MongoDB drivers and tools. </p> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> MongoDB Extended JSON v2 Usage <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-extended-json-v2-usage" 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="mongodb-extended-json-v2-usage"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Drivers <a class="headerlink leafygreen-ui-1kepx47" href="#drivers" 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="drivers"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following drivers use the Extended JSON v2.0 </p> <table class="hlist"> <tbody> <tr> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> C </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> C++ </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Go </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Java </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Node </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Perl </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> PHPC </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Python </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Scala </p> </li> </ul> </td> </tr> </tbody> </table> <p class="leafygreen-ui-1kp3ins"> For C# and Ruby that use Legacy MongoDB Extended JSON v1, refer to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json-v1/"> MongoDB Extended JSON (v1) <!-- --> . </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Extended JSON Methods <a class="headerlink leafygreen-ui-1kepx47" href="#extended-json-methods" 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="extended-json-methods"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB provides the following methods for Extended JSON: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Method </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Description </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> serialize </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Serializes a BSON object and returns the data in Extended JSON format. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"EJSON.serialize( db.&lt;collection&gt;.findOne() )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-variable lg-highlight-constant">EJSON</span>.<span class="lg-highlight-title lg-highlight-function">serialize</span>( <!-- -->db.<!-- -->&lt;<!-- -->collection<!-- -->&gt;<!-- -->.<span class="lg-highlight-title lg-highlight-function">findOne</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> deserialize </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Converts a serialized document to field and value pairs. The values have <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-type-representations" target="_self"> <span> BSON types <!-- --> . </span> </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"EJSON.deserialize( &lt;serialized&gt; )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-variable lg-highlight-constant">EJSON</span>.<span class="lg-highlight-title lg-highlight-function">deserialize</span>( <span class="lg-highlight-tag lg-highlight-xml">&lt;</span><span class="lg-highlight-name lg-highlight-tag lg-highlight-xml">serialized</span><span class="lg-highlight-tag lg-highlight-xml"> </span><span class="lg-highlight-attr lg-highlight-tag lg-highlight-xml">object</span><span class="lg-highlight-tag lg-highlight-xml">&gt;</span><span class="lg-highlight-xml"> )</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> stringify </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Converts the element and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-type-representations" target="_self"> <span> type </span> </a> pairs in a deserialized object to strings. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"EJSON.stringify( &lt;deserialized&gt; )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-variable lg-highlight-constant">EJSON</span>.<span class="lg-highlight-title lg-highlight-function">stringify</span>( <span class="lg-highlight-tag lg-highlight-xml">&lt;</span><span class="lg-highlight-name lg-highlight-tag lg-highlight-xml">deserialized</span><span class="lg-highlight-tag lg-highlight-xml"> </span><span class="lg-highlight-attr lg-highlight-tag lg-highlight-xml">object</span><span class="lg-highlight-tag lg-highlight-xml">&gt;</span><span class="lg-highlight-xml"> )</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> parse </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Converts strings into element and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-type-representations" target="_self"> <span> type </span> </a> pairs. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"EJSON.parse( &lt;string&gt; )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-variable lg-highlight-constant">EJSON</span>.<span class="lg-highlight-title lg-highlight-function">parse</span>( &lt;<!-- -->string<!-- -->&gt; <!-- -->)</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> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> For usage examples, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-ex-obj-conversions" target="_self"> <span> Extended JSON Object Conversions </span> </a> below. </p> <p class="leafygreen-ui-1kp3ins"> For additional details, see the documentation for: </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://mongodb.github.io/node-mongodb-native/4.0/" rel="noopener noreferrer"> <span> MongoDB NodeJS Driver </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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb-js/bson-ext" rel="noopener noreferrer"> <span> BSON Parser </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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb-js/bson-ext" rel="noopener noreferrer"> <span> BSON-EXT Parser </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> </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> MongoDB Database Tools <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-database-tools" 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="mongodb-database-tools"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Starting in version 4.2: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Binary </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Changes </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/bsondump/#mongodb-binary-bin.bsondump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> bsondump </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Uses Extended JSON v2.0 (Canonical mode) format. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongodump/#mongodb-binary-bin.mongodump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongodump </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Use Extended JSON v2.0 (Canonical mode) format for the metadata. Requires <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongorestore </code> </span> </a> version 4.2 or later that supports Extended JSON v2.0 (Canonical mode or Relaxed) format. </p> <p class="leafygreen-ui-1kp3ins"> In general, use corresponding versions of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongodump/#mongodb-binary-bin.mongodump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongodump </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongorestore </code> </span> </a> . To restore data files created with a specific version of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongodump/#mongodb-binary-bin.mongodump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongodump </code> </span> </a> , use the corresponding version of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongorestore </code> . </span> </a> </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoexport </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> Creates output data in Extended JSON v2.0 (Relaxed mode) by default. </div> </div> <div class="line-block"> <div class="line"> Creates output data in Extended JSON v2.0 (Canonical mode) if used with <code class="leafygreen-ui-1l06pbn"> --jsonFormat </code> . </div> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoimport </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> Expects import data to be in Extended JSON v2.0 (either Relaxed or Canonical mode) by default. </div> </div> <div class="line-block"> <div class="line"> Can recognize data that is in Extended JSON v1.0 format if the option <code class="leafygreen-ui-1l06pbn"> --legacy </code> is specified. </div> </div> <p class="leafygreen-ui-1kp3ins"> In general, the versions of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoexport </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoimport </code> </span> </a> should match. To import data created from <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoexport </code> </span> </a> , you should use the corresponding version of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoimport </code> . </span> </a> </p> </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-bsontype-list-of-types"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> BSON Data Types and Associated Representations <a class="headerlink leafygreen-ui-1kepx47" href="#bson-data-types-and-associated-representations" 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="bson-data-types-and-associated-representations"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following presents some common BSON data types and the associated representations in <em> Canonical </em> and <em> Relaxed </em> . </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:15%"/> <col style="width:15%"/> <col style="width:15%"/> <col style="width:30%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-Array" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> Array </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-Binary" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> Binary </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-Date" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> Date </code> </span> </a> </p> </li> </ul> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-Decimal128" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> Decimal128 </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-Document" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> Document </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-Double" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> Double </code> </span> </a> </p> </li> </ul> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-Int32" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> Int32 </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-Int64" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> Int64 </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-MaxKey" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> MaxKey </code> </span> </a> </p> </li> </ul> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-MinKey" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> MinKey </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-ObjectId" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> ObjectId </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-Regular-Expression" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> Regular Expression </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-bsontype-Timestamp" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> Timestamp </code> </span> </a> </p> </li> </ul> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> The complete list is <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/specifications/blob/master/source/extended-json/extended-json.md" rel="noopener noreferrer"> <span> here <!-- --> . </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> </p> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> Array </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-Array" title="Permalink to this definition"> <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="mongodb-bsontype-Array"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ &lt;elements&gt; ]"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[ &lt;elements&gt; ]</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;same&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;Same as Canonical&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Where the array elements are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;elements&gt; </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Array elements use Extended JSON. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To specify an empty array, omit the content <code class="leafygreen-ui-1l06pbn"> [ ] </code> . </p> </li> </ul> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-extended-json-binary"> </span> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> Binary </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-Binary" title="Permalink to this definition"> <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="mongodb-bsontype-Binary"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$binary\":\n {\n \"base64\": \"&lt;payload&gt;\",\n \"subType\": \"&lt;t&gt;\"\n }\n}"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$binary":</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "base64": "&lt;payload&gt;",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "subType": "&lt;t&gt;"</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;same&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;Same as Canonical&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "&lt;payload&gt;" </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Base64 encoded (with padding as "=") payload string. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "&lt;t&gt;" </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A one- or two-character hex string that corresponds to a BSON binary subtype. See the extended bson documentation <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://bsonspec.org/spec.html" rel="noopener noreferrer"> <span> http://bsonspec.org/spec.html </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> for subtypes available. </p> </li> </ul> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-extended-json-date"> </span> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> Date </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-Date" title="Permalink to this definition"> <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="mongodb-bsontype-Date"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <p class="leafygreen-ui-1kp3ins"> <em> For dates between years 1970 and 9999, inclusive </em> : </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\"$date\": {\"$numberLong\": \"&lt;millis&gt;\"}}"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{"$date": {"$numberLong": "&lt;millis&gt;"}}</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\"$date\": \"&lt;iso-8601&gt;\"}"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{"$date": "&lt;ISO-8601 Date/Time Format&gt;"}</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> <em> For dates before year 1970 or after year 9999 </em> : </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\"$date\": {\"$numberLong\": \"&lt;millis&gt;\"}}"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{"$date": {"$numberLong": "&lt;millis&gt;"}}</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;same&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;Same as Canonical&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "&lt;millis&gt;" </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A 64-bit signed integer as string. The value represents milliseconds relative to the epoch. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "&lt;ISO-8601 Date/Time Format&gt;" </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A date in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc3339#section-5.6" rel="noopener noreferrer"> <span> ISO-8601 Internet Date/Time Format </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> as string. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The date/time has a maximum time precision of milliseconds: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Fractional seconds have exactly 3 decimal places if the fractional part is non-zero. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Otherwise, fractional seconds SHOULD be omitted if zero. </p> </li> </ul> </li> </ul> </li> </ul> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> Decimal128 </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-Decimal128" title="Permalink to this definition"> <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="mongodb-bsontype-Decimal128"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$numberDecimal\": \"&lt;number&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{ "$numberDecimal": "&lt;number&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;same&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;Same as Canonical&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "&lt;number&gt;" </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst" rel="noopener noreferrer"> <span> high-precision decimal </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> as a string. </p> </li> </ul> </li> </ul> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> Document </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-Document" title="Permalink to this definition"> <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="mongodb-bsontype-Document"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ &lt;content&gt; }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ &lt;content&gt; }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;same&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;Same as Canonical&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Where the document contents are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;content&gt; </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Name:value pairs that use Extended JSON. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To specify an empty document, omit the content <code class="leafygreen-ui-1l06pbn"> { } </code> . </p> </li> </ul> </li> </ul> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> Double </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-Double" title="Permalink to this definition"> <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="mongodb-bsontype-Double"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <p class="leafygreen-ui-1kp3ins"> <em> For finite numbers </em> : </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\"$numberDouble\": \"&lt;decimal&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{"$numberDouble": "&lt;decimal string&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;non-integer&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;non-integer number&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> <em> For infinite numbers or NAN </em> : </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\"$numberDouble\": &lt;\"Infinity\"|\"-Infinity\"|\"NaN\"&gt; }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{"$numberDouble": &lt;"Infinity"|"-Infinity"|"NaN"&gt; }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;same&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;Same as Canonical&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "&lt;decimal string&gt;" </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A 64-bit signed floating point as a string. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;non-integer number&gt; </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A non-integer number. Integer numbers are parsed as an integer instead of a double. </p> </li> </ul> </li> </ul> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> Int64 </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-Int64" title="Permalink to this definition"> <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="mongodb-bsontype-Int64"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$numberLong\": \"&lt;number&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$numberLong": "&lt;number&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;integer&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;integer&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "&lt;number&gt;" </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A 64-bit signed integer as string. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;integer&gt; </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A 64-bit signed integer. </p> </li> </ul> </li> </ul> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> Int32 </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-Int32" title="Permalink to this definition"> <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="mongodb-bsontype-Int32"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$numberInt\": \"&lt;number&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$numberInt": "&lt;number&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;integer&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;integer&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "&lt;number&gt;" </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A 32-bit signed integer as a string. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;integer&gt; </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A 32-bit signed integer. </p> </li> </ul> </li> </ul> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> MaxKey </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-MaxKey" title="Permalink to this definition"> <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="mongodb-bsontype-MaxKey"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$maxKey\": 1 }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$maxKey": 1 }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;same&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;Same as Canonical&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> The MaxKey BSON data type compares higher than all other types. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-type-comparison-order/#std-label-faq-dev-compare-order-for-BSON-types"> Comparison/Sort Order </a> for more information on comparison order for BSON types. </p> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> MinKey </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-MinKey" title="Permalink to this definition"> <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="mongodb-bsontype-MinKey"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$minKey\": 1 }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$minKey": 1 }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;same&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;Same as Canonical&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> The MinKey BSON data type compares lower than all other types. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-type-comparison-order/#std-label-faq-dev-compare-order-for-BSON-types"> Comparison/Sort Order </a> for more information on comparison order for BSON types. </p> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> ObjectId </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-ObjectId" title="Permalink to this definition"> <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="mongodb-bsontype-ObjectId"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$oid\": \"&lt;objectid&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$oid": "&lt;ObjectId bytes&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;same&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;Same as Canonical&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "&lt;ObjectId bytes&gt;" </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A 24-character, big-endian hexadecimal string that represents the ObjectId bytes. </p> </li> </ul> </li> </ul> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> Regular Expression </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-Regular-Expression" title="Permalink to this definition"> <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="mongodb-bsontype-Regular-Expression"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$regularExpression\":\n {\n \"pattern\": \"&lt;regexpattern&gt;\",\n \"options\": \"&lt;options&gt;\"\n }\n}"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" 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">{ "$regularExpression":</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "pattern": "&lt;regexPattern&gt;",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "options": "&lt;options&gt;"</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;same&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;Same as Canonical&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "&lt;regexPattern&gt;" </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A string that corresponds to the regular expression pattern. The string can contain valid JSON characters and unescaped double quote ( <code class="leafygreen-ui-1l06pbn"> " </code> ) characters, but may not contain unescaped forward slash ( <code class="leafygreen-ui-1l06pbn"> / </code> ) characters. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "&lt;options&gt;" </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A string that specifies BSON regular expression options. You must specify the options in alphabetical order. For information on the supported options, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/regex/#mongodb-query-op.-options"> <code class="leafygreen-ui-1l06pbn"> $options </code> . </a> </p> </li> </ul> </li> </ul> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> Timestamp </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-Timestamp" title="Permalink to this definition"> <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="mongodb-bsontype-Timestamp"> </div> </a> </dt> <dd> </dd> </dl> <hr class="css-1unva0n e4ru7ww0"/> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\"$timestamp\": {\"t\": &lt;t&gt;, \"i\": <i>}}</i>"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{"$timestamp": {"t": &lt;t&gt;, "i": &lt;i&gt;}}</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;same&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;Same as Canonical&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;t&gt; </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A positive integer for the seconds since epoch. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;i&gt; </code> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A positive integer for the increment. </p> </li> </ul> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following examples illustrate Extended JSON usage. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-type-representations"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Type Representations <a class="headerlink leafygreen-ui-1kepx47" href="#type-representations" 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="type-representations"> </div> </a> </h3> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:40%"/> <col style="width:40%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Example Field Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Canonical Format </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Relaxed Format </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "_id:" </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$oid":"5d505646cf6d4fe581014ab2"} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$oid":"5d505646cf6d4fe581014ab2"} </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "arrayField": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> ["hello",{"$numberInt":"10"}] </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> ["hello",10] </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "dateField": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$date":{"$numberLong":"1565546054692"}} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$date":"2019-08-11T17:54:14.692Z"} </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "dateBefore1970": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$date":{"$numberLong":"-1577923200000"}} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$date":{"$numberLong":"-1577923200000"}} </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "decimal128Field": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$numberDecimal":"10.99"} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$numberDecimal":"10.99"} </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "documentField": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"a":"hello"} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"a":"hello"} </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "doubleField": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$numberDouble":"10.5"} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 10.5 </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "infiniteNumber" </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$numberDouble":"Infinity"} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$numberDouble":"Infinity"} </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "int32field": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$numberInt":"10"} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 10 </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "int64Field": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$numberLong":"50"} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 50 </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "minKeyField": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$minKey":1} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$minKey":1} </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "maxKeyField": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$maxKey":1} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$maxKey":1} </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "regexField": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$regularExpression":{"pattern":"^H","options":"i"}} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$regularExpression":{"pattern":"^H","options":"i"}} </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "timestampField": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$timestamp":{"t":1565545664,"i":1}} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$timestamp":{"t":1565545664,"i":1}} </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> "uuid": </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$uuid":"3b241101-e2bb-4255-8caf-4136c566a962"} </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> {"$uuid":"3b241101-e2bb-4255-8caf-4136c566a962"} </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-ex-obj-conversions"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Extended JSON Object Conversions <a class="headerlink leafygreen-ui-1kepx47" href="#extended-json-object-conversions" 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="extended-json-object-conversions"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following short examples create a document object and then convert the object to different forms using Extended JSON object conversion methods. </p> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Setup <a class="headerlink leafygreen-ui-1kepx47" href="#setup" 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="setup"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Create a document in the <code class="leafygreen-ui-1l06pbn"> conversions </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.conversions.insertOne( { insertDate: new Date() } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">conversions</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{ <span class="lg-highlight-attr">insertDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</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> <p class="leafygreen-ui-1kp3ins"> <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> returns a document object: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n acknowledged: true,\n insertedId: ObjectId(\"61fbaf25671c45f3f5f4074a\")\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">acknowledged</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insertedId</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"61fbaf25671c45f3f5f4074a"</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> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> EJSON.serialize <a class="headerlink leafygreen-ui-1kepx47" href="#ejson.serialize" 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="ejson.serialize"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Serialize the data stored in a MongoDB document object: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"serialized = EJSON.serialize( db.conversions.findOne() )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">serialized <!-- -->= <span class="lg-highlight-variable lg-highlight-constant">EJSON</span>.<span class="lg-highlight-title lg-highlight-function">serialize</span>( <!-- -->db.<span class="lg-highlight-property">conversions</span>.<span class="lg-highlight-title lg-highlight-function">findOne</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> <p class="leafygreen-ui-1kp3ins"> <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> parses a JavaScript object and returns values using <code class="leafygreen-ui-1l06pbn"> "$" </code> prefixed <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-type-representations" target="_self"> <span> types <!-- --> : </span> </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: { '$oid': '61fbaf25671c45f3f5f4074a' },\n insertDate: { '$date': '2022-02-03T10:32:05.230Z' }\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-string">'$oid'</span>: <span class="lg-highlight-string">'61fbaf25671c45f3f5f4074a'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insertDate</span>: <!-- -->{ <span class="lg-highlight-string">'$date'</span>: <span class="lg-highlight-string">'2022-02-03T10:32:05.230Z'</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> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> EJSON.deserialize <a class="headerlink leafygreen-ui-1kepx47" href="#ejson.deserialize" 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="ejson.deserialize"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Deserialize a serialized object: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"EJSON.deserialize( serialized )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-variable lg-highlight-constant">EJSON</span>.<span class="lg-highlight-title lg-highlight-function">deserialize</span>( <!-- -->serialized )</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"> <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> parses a JavaScript object and returns values using the default <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> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-type-representations" target="_self"> <span> type </span> </a> form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: new ObjectId( \"61fbaf25671c45f3f5f4074a\" ),\n insertDate: ISODate( \"2022-02-03T10:32:05.230Z\" )\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ObjectId</span>( <span class="lg-highlight-string">"61fbaf25671c45f3f5f4074a"</span> )<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insertDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2022-02-03T10:32:05.230Z"</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> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> EJSON.stringify <a class="headerlink leafygreen-ui-1kepx47" href="#ejson.stringify" 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="ejson.stringify"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Convert an object to a string: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"stringified = EJSON.stringify( db.conversions.findOne() )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">stringified <!-- -->= <span class="lg-highlight-variable lg-highlight-constant">EJSON</span>.<span class="lg-highlight-title lg-highlight-function">stringify</span>( <!-- -->db.<span class="lg-highlight-property">conversions</span>.<span class="lg-highlight-title lg-highlight-function">findOne</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> <p class="leafygreen-ui-1kp3ins"> <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> outputs the elements of the converted object as strings: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\": {\"$oid\":\"61fbaf25671c45f3f5f4074a\"},\n \"insertDate\":{\"$date\":\"2022-02-03T10:32:05.230Z\"}\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span>: <!-- -->{<span class="lg-highlight-string">"$oid"</span>:<span class="lg-highlight-string">"61fbaf25671c45f3f5f4074a"</span>}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insertDate"</span>:<!-- -->{<span class="lg-highlight-string">"$date"</span>:<span class="lg-highlight-string">"2022-02-03T10:32:05.230Z"</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> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> EJSON.parse <a class="headerlink leafygreen-ui-1kepx47" href="#ejson.parse" 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="ejson.parse"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Parse a string to create an object: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"EJSON.parse( stringified )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-variable lg-highlight-constant">EJSON</span>.<span class="lg-highlight-title lg-highlight-function">parse</span>( <!-- -->stringified )</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"> <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> returns the converted strings as documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: new ObjectId(\"61fbaf25671c45f3f5f4074a\"),\n insertDate: ISODate(\"2022-02-03T10:32:05.230Z\")\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"61fbaf25671c45f3f5f4074a"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insertDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2022-02-03T10:32:05.230Z"</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> </section> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $documents (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-documents--aggregation-" 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="-documents--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#limitations" target="_self"> <span> Limitations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="pipeline"> <dt> <code class="leafygreen-ui-1l06pbn"> $documents </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-pipeline-pipe.-documents" title="Permalink to this definition"> <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="mongodb-pipeline-pipe.-documents"> </div> </a> </dt> <dd> <div> <p> <em> New <!-- --> in version <!-- --> 6.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Returns literal documents from input values. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-documents" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $documents </code> </span> </a> stage has the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $documents: &lt;expression&gt; }"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ $documents: &lt;expression&gt; }</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Limitations <a class="headerlink leafygreen-ui-1kepx47" href="#limitations" 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="limitations"> </div> </a> </h2> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You can only use <code class="leafygreen-ui-1l06pbn"> $documents </code> in a database-level aggregation pipeline. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You must use <code class="leafygreen-ui-1l06pbn"> $documents </code> as the first stage of an aggregation pipeline. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> See below for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-ex-agg-documents-stage" target="_self"> <span> usage examples <!-- --> . </span> </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-documents" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $documents </code> </span> </a> accepts any valid expression that resolves to an array of objects. This includes: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> system variables, such as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.NOW"> <code class="leafygreen-ui-1l06pbn"> $$NOW </code> </a> or <code class="leafygreen-ui-1l06pbn"> $$SEARCH_META </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/let/#mongodb-expression-exp.-let"> <code class="leafygreen-ui-1l06pbn"> $let </code> </a> expressions </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> variables in scope from <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup"> <code class="leafygreen-ui-1l06pbn"> $lookup </code> </a> expressions </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Expressions that do not resolve to a current document, like <code class="leafygreen-ui-1l06pbn"> $myField </code> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.ROOT"> <code class="leafygreen-ui-1l06pbn"> $$ROOT </code> </a> , will result in an error. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-ex-agg-documents-stage"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Test a Pipeline Stage <a class="headerlink leafygreen-ui-1kepx47" href="#test-a-pipeline-stage" 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="test-a-pipeline-stage"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Create testing and debugging data for a pipeline stage without creating test collections. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.aggregate(\n [\n { $documents: [ { x: 10 }, { x: 2 }, { x: 5 } ] },\n { $bucketAuto: { groupBy: \"$x\", buckets: 4 } }\n ]\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">db.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$documents</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">x</span>: <span class="lg-highlight-number">10</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">x</span>: <span class="lg-highlight-number">2</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">x</span>: <span class="lg-highlight-number">5</span> } ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$bucketAuto</span>: <!-- -->{ <span class="lg-highlight-attr">groupBy</span>: <span class="lg-highlight-string">"$x"</span>, <span class="lg-highlight-attr">buckets</span>: <span class="lg-highlight-number">4</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> aggregation expression </a> does not specify a collection. It uses the input data in the highlighted <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-documents" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $documents </code> </span> </a> stage as input to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/bucketAuto/#mongodb-pipeline-pipe.-bucketAuto"> <code class="leafygreen-ui-1l06pbn"> $bucketAuto </code> </a> stage. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: { min: 2, max: 5 }, count: 1 },\n { _id: { min: 5, max: 10 }, count: 1 },\n { _id: { min: 10, max: 10 }, count: 1 }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-number">5</span> }<!-- -->, <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-number">10</span> }<!-- -->, <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-number">10</span> }<!-- -->, <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-documents-lookup-example"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Use a <code class="leafygreen-ui-1l06pbn"> $documents </code> Stage in a <code class="leafygreen-ui-1l06pbn"> $lookup </code> Stage <a class="headerlink leafygreen-ui-1kepx47" href="#use-a--documents-stage-in-a--lookup-stage" 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="use-a--documents-stage-in-a--lookup-stage"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Correlate documents in a collection with other data using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-documents" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $documents </code> </span> </a> to modify <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup"> <code class="leafygreen-ui-1l06pbn"> $lookup </code> </a> output. </p> <p class="leafygreen-ui-1kp3ins"> Create the <code class="leafygreen-ui-1l06pbn"> locations </code> collection. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.locations.insertMany(\n [\n { zip: 94301, name: \"Palo Alto\" },\n { zip: 10019, name: \"New York\" }\n ]\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">db.<span class="lg-highlight-property">locations</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">94301</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Palo Alto"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">10019</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"New York"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <p class="leafygreen-ui-1kp3ins"> Use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-documents" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $documents </code> </span> </a> as a data source to transform the documents. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.locations.aggregate(\n [\n { $match: {} },\n { $lookup:\n {\n localField: \"zip\",\n foreignField: \"zip_id\",\n as: \"city_state\",\n pipeline:\n [\n { $documents:\n [\n { zip_id: 94301, name: \"Palo Alto, CA\" },\n { zip_id: 10019, name: \"New York, NY\" }\n ]\n }\n ]\n }\n }\n ]\n )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">locations</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</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"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">localField</span>: <span class="lg-highlight-string">"zip"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">foreignField</span>: <span class="lg-highlight-string">"zip_id"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">as</span>: <span class="lg-highlight-string">"city_state"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pipeline</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$documents</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">zip_id</span>: <span class="lg-highlight-number">94301</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Palo Alto, CA"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">zip_id</span>: <span class="lg-highlight-number">10019</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"New York, NY"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <p class="leafygreen-ui-1kp3ins"> The output correlates the data in the <code class="leafygreen-ui-1l06pbn"> locations </code> collection with the values in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-documents" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $documents </code> </span> </a> pipeline stage. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: ObjectId(\"618949d60f7bfd5f5689490d\"),\n zip: 94301,\n name: 'Palo Alto',\n city_state: [ { zip_id: 94301, name: 'Palo Alto, CA' } ]\n },\n {\n _id: ObjectId(\"618949d60f7bfd5f5689490e\"),\n zip: 10019,\n name: 'New York',\n city_state: [ { zip_id: 10019, name: 'New York, NY' } ]\n }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618949d60f7bfd5f5689490d"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">94301</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'Palo Alto'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">city_state</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">zip_id</span>: <span class="lg-highlight-number">94301</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'Palo Alto, CA'</span> } ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618949d60f7bfd5f5689490e"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">10019</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'New York'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">city_state</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">zip_id</span>: <span class="lg-highlight-number">10019</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'New York, NY'</span> } ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> zip </code> field corresponds to the <code class="leafygreen-ui-1l06pbn"> zip_id </code> field </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> as </code> parameter creates a new output field </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For details on subqueries using this <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup"> <code class="leafygreen-ui-1l06pbn"> $lookup </code> </a> syntax, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#std-label-lookup-syntax-concise-correlated-subquery"> Correlated Subqueries Using Concise Syntax <!-- --> . </a> </p> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $project (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-project--aggregation-" 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="-project--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self"> <span> Considerations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="pipeline"> <dt> <code class="leafygreen-ui-1l06pbn"> $project </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-pipeline-pipe.-project" title="Permalink to this definition"> <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="mongodb-pipeline-pipe.-project"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Passes along the documents with the requested fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> You can use <code class="leafygreen-ui-1l06pbn"> $project </code> for deployments hosted 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> </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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage has the following prototype form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $project: { &lt;specification(s)&gt; } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-xml">&lt;specification(s)&gt; } }</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> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> takes a document that can specify the inclusion of fields, the suppression of the <code class="leafygreen-ui-1l06pbn"> _id </code> field, the addition of new fields, and the resetting of the values of existing fields. Alternatively, you may specify the <em> exclusion </em> of fields. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> specifications have the following forms: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Form </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> &lt;field&gt;: &lt;1 or true&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Specifies the inclusion of a field. Non-zero integers are also treated as <code class="leafygreen-ui-1l06pbn"> true </code> . </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> _id: &lt;0 or false&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Specifies the suppression of the <code class="leafygreen-ui-1l06pbn"> _id </code> field. </p> <p class="leafygreen-ui-1kp3ins"> To exclude a field conditionally, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.REMOVE"> <code class="leafygreen-ui-1l06pbn"> REMOVE </code> </a> variable instead. For details, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-remove-var" target="_self"> <span> Exclude Fields Conditionally <!-- --> . </span> </a> </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> &lt;field&gt;: &lt;expression&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Adds a new field or resets the value of an existing field. </p> <p class="leafygreen-ui-1kp3ins"> If the expression evaluates to <code class="leafygreen-ui-1l06pbn"> $$REMOVE </code> , the field is excluded in the output. For details, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-remove-var" target="_self"> <span> Exclude Fields Conditionally <!-- --> . </span> </a> </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> &lt;field&gt;: &lt;0 or false&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Specifies the exclusion of a field. </p> <p class="leafygreen-ui-1kp3ins"> To exclude a field conditionally, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.REMOVE"> <code class="leafygreen-ui-1l06pbn"> REMOVE </code> </a> variable instead. For details, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-remove-var" target="_self"> <span> Exclude Fields Conditionally <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> If you specify the exclusion of a field other than <code class="leafygreen-ui-1l06pbn"> _id </code> , you <strong> cannot </strong> employ any other <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> specification forms. This restriction does not apply to conditionally exclusion of a field using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.REMOVE"> <code class="leafygreen-ui-1l06pbn"> REMOVE </code> </a> variable. </p> <p class="leafygreen-ui-1kp3ins"> See also the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> stage to exclude fields. </p> </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Include Fields <a class="headerlink leafygreen-ui-1kepx47" href="#include-fields" 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="include-fields"> </div> </a> </h3> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> _id </code> field is, by default, included in the output documents. To include any other fields from the input documents in the output documents, you must explicitly specify the inclusion in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> . </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If you specify an inclusion of a field that does not exist in the document, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> ignores that field inclusion and does not add the field to the document. </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> _id </code> Field <a class="headerlink leafygreen-ui-1kepx47" href="#_id-field" 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="_id-field"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> By default, the <code class="leafygreen-ui-1l06pbn"> _id </code> field is included in the output documents. To exclude the <code class="leafygreen-ui-1l06pbn"> _id </code> field from the output documents, you must explicitly specify the suppression of the <code class="leafygreen-ui-1l06pbn"> _id </code> field in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> . </span> </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Exclude Fields <a class="headerlink leafygreen-ui-1kepx47" href="#exclude-fields" 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="exclude-fields"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If you specify the exclusion of a field or fields, all other fields are returned in the output documents. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $project: { \"&lt;field1&gt;\": 0, \"&lt;field2&gt;\": 0, ... } } // Return all but the specified fields","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-string">"&lt;field1&gt;"</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"&lt;field2&gt;"</span>: <span class="lg-highlight-number">0</span>, <!-- -->...<!-- --> } } <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Return all but </span><span class="lg-highlight-comment">the specified fields</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> <p class="leafygreen-ui-1kp3ins"> If you specify the exclusion of a field other than <code class="leafygreen-ui-1l06pbn"> _id </code> , you cannot employ any other <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> specification forms: i.e. if you exclude fields, you cannot also specify the inclusion of fields, reset the value of existing fields, or add new fields. This restriction does not apply to conditional exclusion of a field using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.REMOVE"> <code class="leafygreen-ui-1l06pbn"> REMOVE </code> </a> variable. </p> <p class="leafygreen-ui-1kp3ins"> See also the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> stage to exclude fields. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-remove-var"> </span> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Exclude Fields Conditionally <a class="headerlink leafygreen-ui-1kepx47" href="#exclude-fields-conditionally" 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="exclude-fields-conditionally"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can use the variable <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.REMOVE"> <code class="leafygreen-ui-1l06pbn"> REMOVE </code> </a> in aggregation expressions to conditionally suppress a field. For an example, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-remove-example" target="_self"> <span> Conditionally Exclude Fields <!-- --> . </span> </a> </p> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Add New Fields or Reset Existing Fields <a class="headerlink leafygreen-ui-1kepx47" href="#add-new-fields-or-reset-existing-fields" 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="add-new-fields-or-reset-existing-fields"> </div> </a> </h3> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> MongoDB also provides <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> to add new fields to the documents. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> To add a new field or to reset the value of an existing field, specify the field name and set its value to some expression. For more information on expressions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> Expression Operators <!-- --> . </a> </p> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Literal Values <a class="headerlink leafygreen-ui-1kepx47" href="#literal-values" 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="literal-values"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> To set a field value directly to a numeric or boolean literal, as opposed to setting the field to an expression that resolves to a literal, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal"> <code class="leafygreen-ui-1l06pbn"> $literal </code> </a> operator. Otherwise, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> treats the numeric or boolean literal as a flag for including or excluding the field. </p> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Field Rename <a class="headerlink leafygreen-ui-1kepx47" href="#field-rename" 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="field-rename"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> By specifying a new field and setting its value to the field path of an existing field, you can effectively rename a field. </p> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> New Array Fields <a class="headerlink leafygreen-ui-1kepx47" href="#new-array-fields" 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="new-array-fields"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage supports using the square brackets <code class="leafygreen-ui-1l06pbn"> [] </code> to directly create new array fields. If you specify array fields that do not exist in a document, the operation substitutes <code class="leafygreen-ui-1l06pbn"> null </code> as the value for that field. For an example, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-example-project-new-array-fields" target="_self"> <span> Project New Array Fields <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> You cannot use an array index with the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage. For more information, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-example-project-array-indexes" target="_self"> <span> Array Indexes are Unsupported <!-- --> . </span> </a> </p> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Embedded Document Fields <a class="headerlink leafygreen-ui-1kepx47" href="#embedded-document-fields" 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="embedded-document-fields"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> When projecting or adding/resetting a field within an embedded document, you can either use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-dot-notation"> dot notation </a> , as in </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"contact.address.country\": &lt;1 or 0 or expression&gt;","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-string">"contact.address.country"</span>: <span class="lg-highlight-xml">&lt;1 or 0 or expression&gt;</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> <p class="leafygreen-ui-1kp3ins"> Or you can nest the fields: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"contact: { address: { country: &lt;1 or 0 or expression&gt; } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-attr">contact</span>: <!-- -->{ <span class="lg-highlight-attr">address</span>: <!-- -->{ <span class="lg-highlight-attr">country</span>: <span class="lg-highlight-xml">&lt;1 or 0 or expression&gt; } }</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> <p class="leafygreen-ui-1kp3ins"> When nesting the fields, you <em> cannot </em> use dot notation inside the embedded document to specify the field, e.g. <code class="leafygreen-ui-1l06pbn"> contact: { "address.country": &lt;1 or 0 or expression&gt; } </code> is <em> invalid </em> . </p> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Path Collision Errors in Embedded Fields <a class="headerlink leafygreen-ui-1kepx47" href="#path-collision-errors-in-embedded-fields" 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="path-collision-errors-in-embedded-fields"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You cannot specify both an embedded document and a field within that embedded document in the same projection. </p> <p class="leafygreen-ui-1kp3ins"> The following <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage fails with a <code class="leafygreen-ui-1l06pbn"> Path collision </code> error because it attempts to project both the embedded <code class="leafygreen-ui-1l06pbn"> contact </code> document and the <code class="leafygreen-ui-1l06pbn"> contact.address.country </code> field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $project: { contact: 1, \"contact.address.country\": 1 } }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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">{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">contact</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"contact.address.country"</span>: <span class="lg-highlight-number">1</span> } }</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> The error occurs regardless of the order in which the parent document and embedded field are specified. The following <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> fails with the same error: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $project: { \"contact.address.country\": 1, contact: 1 } }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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">{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-string">"contact.address.country"</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">contact</span>: <span class="lg-highlight-number">1</span> } }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> $project </code> Stage Placement <a class="headerlink leafygreen-ui-1kepx47" href="#-project-stage-placement" 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="-project-stage-placement"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> When you use a <code class="leafygreen-ui-1l06pbn"> $project </code> stage it should typically be the last stage in your pipeline, used to specify which fields to return to the client. </p> <p class="leafygreen-ui-1kp3ins"> Using a <code class="leafygreen-ui-1l06pbn"> $project </code> stage at the beginning or middle of a pipeline to reduce the number of fields passed to subsequent pipeline stages is unlikely to improve performance, as the database performs this optimization automatically. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Empty Specification <a class="headerlink leafygreen-ui-1kepx47" href="#empty-specification" 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="empty-specification"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB returns an error if the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage is passed an empty document. </p> <p class="leafygreen-ui-1kp3ins"> For example, running the following pipeline produces an error: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.myCollection.aggregate( [ {\n $project: { }\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">db.<span class="lg-highlight-property">myCollection</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">$project</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Array Index <a class="headerlink leafygreen-ui-1kepx47" href="#array-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="array-index"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> You cannot use an array index with the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage. For more information, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-example-project-array-indexes" target="_self"> <span> Array Indexes are Unsupported <!-- --> . </span> </a> </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Include Specific Fields in Output Documents <a class="headerlink leafygreen-ui-1kepx47" href="#include-specific-fields-in-output-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="include-specific-fields-in-output-documents"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Consider a <code class="leafygreen-ui-1l06pbn"> books </code> collection with the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n title: \"abc123\",\n isbn: \"0001122223334\",\n author: { last: \"zzz\", first: \"aaa\" },\n copies: 5\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"abc123"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">isbn</span>: <span class="lg-highlight-string">"0001122223334"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->{ <span class="lg-highlight-attr">last</span>: <span class="lg-highlight-string">"zzz"</span>, <span class="lg-highlight-attr">first</span>: <span class="lg-highlight-string">"aaa"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">copies</span>: <span class="lg-highlight-number">5</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> <p class="leafygreen-ui-1kp3ins"> The following <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage includes only the <code class="leafygreen-ui-1l06pbn"> _id </code> , <code class="leafygreen-ui-1l06pbn"> title </code> , and the <code class="leafygreen-ui-1l06pbn"> author </code> fields in its output documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.aggregate( [ { $project : { title : 1 , author : 1 } } ] )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <!-- -->$project<!-- --> <!-- -->: <!-- -->{ <!-- -->title <!-- -->: <span class="lg-highlight-number">1</span> <!-- -->, <!-- -->author <!-- -->: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> The operation results in the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"title\" : \"abc123\", \"author\" : { \"last\" : \"zzz\", \"first\" : \"aaa\" } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"abc123"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"zzz"</span>, <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"aaa"</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Suppress <code class="leafygreen-ui-1l06pbn"> _id </code> Field in the Output Documents <a class="headerlink leafygreen-ui-1kepx47" href="#suppress-_id-field-in-the-output-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="suppress-_id-field-in-the-output-documents"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> _id </code> field is always included by default. To exclude the <code class="leafygreen-ui-1l06pbn"> _id </code> field from the output documents of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage, specify the exclusion of the <code class="leafygreen-ui-1l06pbn"> _id </code> field by setting it to <code class="leafygreen-ui-1l06pbn"> 0 </code> in the projection document. </p> <p class="leafygreen-ui-1kp3ins"> Consider a <code class="leafygreen-ui-1l06pbn"> books </code> collection with the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n title: \"abc123\",\n isbn: \"0001122223334\",\n author: { last: \"zzz\", first: \"aaa\" },\n copies: 5\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"abc123"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">isbn</span>: <span class="lg-highlight-string">"0001122223334"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->{ <span class="lg-highlight-attr">last</span>: <span class="lg-highlight-string">"zzz"</span>, <span class="lg-highlight-attr">first</span>: <span class="lg-highlight-string">"aaa"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">copies</span>: <span class="lg-highlight-number">5</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> <p class="leafygreen-ui-1kp3ins"> The following <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage excludes the <code class="leafygreen-ui-1l06pbn"> _id </code> field but includes the <code class="leafygreen-ui-1l06pbn"> title </code> , and the <code class="leafygreen-ui-1l06pbn"> author </code> fields in its output documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.aggregate( [ { $project : { _id: 0, title : 1 , author : 1 } } ] )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <!-- -->$project<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>, <!-- -->title <!-- -->: <span class="lg-highlight-number">1</span> <!-- -->, <!-- -->author <!-- -->: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> The operation results in the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"title\" : \"abc123\", \"author\" : { \"last\" : \"zzz\", \"first\" : \"aaa\" } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"abc123"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"zzz"</span>, <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"aaa"</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Exclude Fields from Output Documents <a class="headerlink leafygreen-ui-1kepx47" href="#exclude-fields-from-output-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="exclude-fields-from-output-documents"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Consider a <code class="leafygreen-ui-1l06pbn"> books </code> collection with the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n title: \"abc123\",\n isbn: \"0001122223334\",\n author: { last: \"zzz\", first: \"aaa\" },\n copies: 5,\n lastModified: \"2016-07-28\"\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"abc123"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">isbn</span>: <span class="lg-highlight-string">"0001122223334"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->{ <span class="lg-highlight-attr">last</span>: <span class="lg-highlight-string">"zzz"</span>, <span class="lg-highlight-attr">first</span>: <span class="lg-highlight-string">"aaa"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">copies</span>: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastModified</span>: <span class="lg-highlight-string">"2016-07-28"</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> <p class="leafygreen-ui-1kp3ins"> The following <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage excludes the <code class="leafygreen-ui-1l06pbn"> lastModified </code> field from the output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.aggregate( [ { $project : { \"lastModified\": 0 } } ] )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <!-- -->$project<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"lastModified"</span>: <span class="lg-highlight-number">0</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> <p class="leafygreen-ui-1kp3ins"> See also the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> stage to exclude fields. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Exclude Fields from Embedded Documents <a class="headerlink leafygreen-ui-1kepx47" href="#exclude-fields-from-embedded-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="exclude-fields-from-embedded-documents"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Consider a <code class="leafygreen-ui-1l06pbn"> books </code> collection with the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n title: \"abc123\",\n isbn: \"0001122223334\",\n author: { last: \"zzz\", first: \"aaa\" },\n copies: 5,\n lastModified: \"2016-07-28\"\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"abc123"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">isbn</span>: <span class="lg-highlight-string">"0001122223334"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->{ <span class="lg-highlight-attr">last</span>: <span class="lg-highlight-string">"zzz"</span>, <span class="lg-highlight-attr">first</span>: <span class="lg-highlight-string">"aaa"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">copies</span>: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastModified</span>: <span class="lg-highlight-string">"2016-07-28"</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> <p class="leafygreen-ui-1kp3ins"> The following <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage excludes the <code class="leafygreen-ui-1l06pbn"> author.first </code> and <code class="leafygreen-ui-1l06pbn"> lastModified </code> fields from the output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.aggregate( [ { $project : { \"author.first\" : 0, \"lastModified\" : 0 } } ] )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <!-- -->$project<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"author.first"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"lastModified"</span> <!-- -->: <span class="lg-highlight-number">0</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> <p class="leafygreen-ui-1kp3ins"> Alternatively, you can nest the exclusion specification in a document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.bookmarks.aggregate( [ { $project: { \"author\": { \"first\": 0}, \"lastModified\" : 0 } } ] )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">bookmarks</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-string">"author"</span>: <!-- -->{ <span class="lg-highlight-string">"first"</span>: <span class="lg-highlight-number">0</span>}<!-- -->, <span class="lg-highlight-string">"lastModified"</span> <!-- -->: <span class="lg-highlight-number">0</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> <p class="leafygreen-ui-1kp3ins"> Both specifications result in the same output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n \"title\" : \"abc123\",\n \"isbn\" : \"0001122223334\",\n \"author\" : {\n \"last\" : \"zzz\"\n },\n \"copies\" : 5,\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"abc123"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"isbn"</span> <!-- -->: <span class="lg-highlight-string">"0001122223334"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"zzz"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"copies"</span> <!-- -->: <span class="lg-highlight-number">5</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> <p class="leafygreen-ui-1kp3ins"> See also the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> stage to exclude fields. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-remove-example"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Conditionally Exclude Fields <a class="headerlink leafygreen-ui-1kepx47" href="#conditionally-exclude-fields" 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="conditionally-exclude-fields"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> You can use the variable <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.REMOVE"> <code class="leafygreen-ui-1l06pbn"> REMOVE </code> </a> in aggregation expressions to conditionally suppress a field. </p> <p class="leafygreen-ui-1kp3ins"> Consider a <code class="leafygreen-ui-1l06pbn"> books </code> collection with the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n title: \"abc123\",\n isbn: \"0001122223334\",\n author: { last: \"zzz\", first: \"aaa\" },\n copies: 5,\n lastModified: \"2016-07-28\"\n}\n{\n \"_id\" : 2,\n title: \"Baked Goods\",\n isbn: \"9999999999999\",\n author: { last: \"xyz\", first: \"abc\", middle: \"\" },\n copies: 2,\n lastModified: \"2017-07-21\"\n}\n{\n \"_id\" : 3,\n title: \"Ice Cream Cakes\",\n isbn: \"8888888888888\",\n author: { last: \"xyz\", first: \"abc\", middle: \"mmm\" },\n copies: 5,\n lastModified: \"2017-07-22\"\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"abc123"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">isbn</span>: <span class="lg-highlight-string">"0001122223334"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->{ <span class="lg-highlight-attr">last</span>: <span class="lg-highlight-string">"zzz"</span>, <span class="lg-highlight-attr">first</span>: <span class="lg-highlight-string">"aaa"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">copies</span>: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastModified</span>: <span class="lg-highlight-string">"2016-07-28"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"Baked Goods"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">isbn</span>: <span class="lg-highlight-string">"9999999999999"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->{ <span class="lg-highlight-attr">last</span>: <span class="lg-highlight-string">"xyz"</span>, <span class="lg-highlight-attr">first</span>: <span class="lg-highlight-string">"abc"</span>, <span class="lg-highlight-attr">middle</span>: <span class="lg-highlight-string">""</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">copies</span>: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastModified</span>: <span class="lg-highlight-string">"2017-07-21"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"Ice Cream Cakes"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">isbn</span>: <span class="lg-highlight-string">"8888888888888"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->{ <span class="lg-highlight-attr">last</span>: <span class="lg-highlight-string">"xyz"</span>, <span class="lg-highlight-attr">first</span>: <span class="lg-highlight-string">"abc"</span>, <span class="lg-highlight-attr">middle</span>: <span class="lg-highlight-string">"mmm"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">copies</span>: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastModified</span>: <span class="lg-highlight-string">"2017-07-22"</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> <p class="leafygreen-ui-1kp3ins"> The following <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.REMOVE"> <code class="leafygreen-ui-1l06pbn"> REMOVE </code> </a> variable to excludes the <code class="leafygreen-ui-1l06pbn"> author.middle </code> field only if it equals <code class="leafygreen-ui-1l06pbn"> "" </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.aggregate( [\n {\n $project: {\n title: 1,\n \"author.first\": 1,\n \"author.last\" : 1,\n \"author.middle\": {\n $cond: {\n if: { $eq: [ \"\", \"$author.middle\" ] },\n then: \"$$REMOVE\",\n else: \"$author.middle\"\n }\n }\n }\n }\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">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"author.first"</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"author.last"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"author.middle"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$cond</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">if</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <span class="lg-highlight-string">""</span>, <span class="lg-highlight-string">"$author.middle"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-string">"$$REMOVE"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">else</span>: <span class="lg-highlight-string">"$author.middle"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The aggregation operation results in the following output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"title\" : \"abc123\", \"author\" : { \"last\" : \"zzz\", \"first\" : \"aaa\" } }\n{ \"_id\" : 2, \"title\" : \"Baked Goods\", \"author\" : { \"last\" : \"xyz\", \"first\" : \"abc\" } }\n{ \"_id\" : 3, \"title\" : \"Ice Cream Cakes\", \"author\" : { \"last\" : \"xyz\", \"first\" : \"abc\", \"middle\" : \"mmm\" } }","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"abc123"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"zzz"</span>, <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"aaa"</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"Baked Goods"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"xyz"</span>, <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"abc"</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"Ice Cream Cakes"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"xyz"</span>, <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"abc"</span>, <span class="lg-highlight-string">"middle"</span> <!-- -->: <span class="lg-highlight-string">"mmm"</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 class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Comparison with $addFields </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> You can use either the <code class="leafygreen-ui-1l06pbn"> $addFields </code> or <code class="leafygreen-ui-1l06pbn"> $project </code> stage to remove document fields. The best approach depends on your pipeline and how much of the original document you want to retain. </p> <p class="leafygreen-ui-1kp3ins"> To see an example using <code class="leafygreen-ui-1l06pbn"> $$REMOVE </code> in an <code class="leafygreen-ui-1l06pbn"> $addFields </code> stage, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#std-label-addFields-remove-example"> Remove Fields <!-- --> . </a> </p> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Include Specific Fields from Embedded Documents <a class="headerlink leafygreen-ui-1kepx47" href="#include-specific-fields-from-embedded-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="include-specific-fields-from-embedded-documents"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Consider a <code class="leafygreen-ui-1l06pbn"> bookmarks </code> collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 1, user: \"1234\", stop: { title: \"book1\", author: \"xyz\", page: 32 } }\n{ _id: 2, user: \"7890\", stop: [ { title: \"book2\", author: \"abc\", page: 5 }, { title: \"book3\", author: \"ijk\", page: 100 } ] }","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"1234"</span>, <span class="lg-highlight-attr">stop</span>: <!-- -->{ <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"book1"</span>, <span class="lg-highlight-attr">author</span>: <span class="lg-highlight-string">"xyz"</span>, <span class="lg-highlight-attr">page</span>: <span class="lg-highlight-number">32</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"7890"</span>, <span class="lg-highlight-attr">stop</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"book2"</span>, <span class="lg-highlight-attr">author</span>: <span class="lg-highlight-string">"abc"</span>, <span class="lg-highlight-attr">page</span>: <span class="lg-highlight-number">5</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"book3"</span>, <span class="lg-highlight-attr">author</span>: <span class="lg-highlight-string">"ijk"</span>, <span class="lg-highlight-attr">page</span>: <span class="lg-highlight-number">100</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> <p class="leafygreen-ui-1kp3ins"> To include only the <code class="leafygreen-ui-1l06pbn"> title </code> field in the embedded document in the <code class="leafygreen-ui-1l06pbn"> stop </code> field, you can use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-dot-notation"> dot notation <!-- --> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.bookmarks.aggregate( [ { $project: { \"stop.title\": 1 } } ] )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">bookmarks</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-string">"stop.title"</span>: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> Or, you can nest the inclusion specification in a document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.bookmarks.aggregate( [ { $project: { stop: { title: 1 } } } ] )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">bookmarks</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">stop</span>: <!-- -->{ <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> Both specifications result in the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"stop\" : { \"title\" : \"book1\" } }\n{ \"_id\" : 2, \"stop\" : [ { \"title\" : \"book2\" }, { \"title\" : \"book3\" } ] }","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"stop"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"book1"</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"stop"</span> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"book2"</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"book3"</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Include Computed Fields <a class="headerlink leafygreen-ui-1kepx47" href="#include-computed-fields" 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="include-computed-fields"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Consider a <code class="leafygreen-ui-1l06pbn"> books </code> collection with the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n title: \"abc123\",\n isbn: \"0001122223334\",\n author: { last: \"zzz\", first: \"aaa\" },\n copies: 5\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"abc123"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">isbn</span>: <span class="lg-highlight-string">"0001122223334"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->{ <span class="lg-highlight-attr">last</span>: <span class="lg-highlight-string">"zzz"</span>, <span class="lg-highlight-attr">first</span>: <span class="lg-highlight-string">"aaa"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">copies</span>: <span class="lg-highlight-number">5</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> <p class="leafygreen-ui-1kp3ins"> The following <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage adds the new fields <code class="leafygreen-ui-1l06pbn"> isbn </code> , <code class="leafygreen-ui-1l06pbn"> lastName </code> , and <code class="leafygreen-ui-1l06pbn"> copiesSold </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.aggregate(\n [\n {\n $project: {\n title: 1,\n isbn: {\n prefix: { $substr: [ \"$isbn\", 0, 3 ] },\n group: { $substr: [ \"$isbn\", 3, 2 ] },\n publisher: { $substr: [ \"$isbn\", 5, 4 ] },\n title: { $substr: [ \"$isbn\", 9, 3 ] },\n checkDigit: { $substr: [ \"$isbn\", 12, 1] }\n },\n lastName: \"$author.last\",\n copiesSold: \"$copies\"\n }\n }\n ]\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">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">isbn</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">prefix</span>: <!-- -->{ <span class="lg-highlight-attr">$substr</span>: <!-- -->[ <span class="lg-highlight-string">"$isbn"</span>, <span class="lg-highlight-number">0</span>, <span class="lg-highlight-number">3</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">group</span>: <!-- -->{ <span class="lg-highlight-attr">$substr</span>: <!-- -->[ <span class="lg-highlight-string">"$isbn"</span>, <span class="lg-highlight-number">3</span>, <span class="lg-highlight-number">2</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">publisher</span>: <!-- -->{ <span class="lg-highlight-attr">$substr</span>: <!-- -->[ <span class="lg-highlight-string">"$isbn"</span>, <span class="lg-highlight-number">5</span>, <span class="lg-highlight-number">4</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <!-- -->{ <span class="lg-highlight-attr">$substr</span>: <!-- -->[ <span class="lg-highlight-string">"$isbn"</span>, <span class="lg-highlight-number">9</span>, <span class="lg-highlight-number">3</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">checkDigit</span>: <!-- -->{ <span class="lg-highlight-attr">$substr</span>: <!-- -->[ <span class="lg-highlight-string">"$isbn"</span>, <span class="lg-highlight-number">12</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"> <span class="lg-highlight-attr">lastName</span>: <span class="lg-highlight-string">"$author.last"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">copiesSold</span>: <span class="lg-highlight-string">"$copies"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <p class="leafygreen-ui-1kp3ins"> The operation results in the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n \"title\" : \"abc123\",\n \"isbn\" : {\n \"prefix\" : \"000\",\n \"group\" : \"11\",\n \"publisher\" : \"2222\",\n \"title\" : \"333\",\n \"checkDigit\" : \"4\"\n },\n \"lastName\" : \"zzz\",\n \"copiesSold\" : 5\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"abc123"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"isbn"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"prefix"</span> <!-- -->: <span class="lg-highlight-string">"000"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"group"</span> <!-- -->: <span class="lg-highlight-string">"11"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"publisher"</span> <!-- -->: <span class="lg-highlight-string">"2222"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"333"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"checkDigit"</span> <!-- -->: <span class="lg-highlight-string">"4"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastName"</span> <!-- -->: <span class="lg-highlight-string">"zzz"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"copiesSold"</span> <!-- -->: <span class="lg-highlight-number">5</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-example-project-new-array-fields"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Project New Array Fields <a class="headerlink leafygreen-ui-1kepx47" href="#project-new-array-fields" 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="project-new-array-fields"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> For example, if a collection includes the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : ObjectId(\"55ad167f320c6be244eb3b95\"), \"x\" : 1, \"y\" : 1 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"55ad167f320c6be244eb3b95"</span>)<!-- -->, <span class="lg-highlight-string">"x"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"y"</span> <!-- -->: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> The following operation projects the fields <code class="leafygreen-ui-1l06pbn"> x </code> and <code class="leafygreen-ui-1l06pbn"> y </code> as elements in a new field <code class="leafygreen-ui-1l06pbn"> myArray </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.aggregate( [ { $project: { myArray: [ \"$x\", \"$y\" ] } } ] )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">myArray</span>: <!-- -->[ <span class="lg-highlight-string">"$x"</span>, <span class="lg-highlight-string">"$y"</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : ObjectId(\"55ad167f320c6be244eb3b95\"), \"myArray\" : [ 1, 1 ] }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"55ad167f320c6be244eb3b95"</span>)<!-- -->, <span class="lg-highlight-string">"myArray"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> If array specification includes fields that are non-existent in a document, the operation substitutes <code class="leafygreen-ui-1l06pbn"> null </code> as the value for that field. </p> <p class="leafygreen-ui-1kp3ins"> For example, given the same document as above, the following operation projects the fields <code class="leafygreen-ui-1l06pbn"> x </code> , <code class="leafygreen-ui-1l06pbn"> y </code> , and a non-existing field <code class="leafygreen-ui-1l06pbn"> $someField </code> as elements in a new field <code class="leafygreen-ui-1l06pbn"> myArray </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.aggregate( [ { $project: { myArray: [ \"$x\", \"$y\", \"$someField\" ] } } ] )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">myArray</span>: <!-- -->[ <span class="lg-highlight-string">"$x"</span>, <span class="lg-highlight-string">"$y"</span>, <span class="lg-highlight-string">"$someField"</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : ObjectId(\"55ad167f320c6be244eb3b95\"), \"myArray\" : [ 1, 1, null ] }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"55ad167f320c6be244eb3b95"</span>)<!-- -->, <span class="lg-highlight-string">"myArray"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">1</span>, <span class="lg-highlight-literal">null</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-example-project-array-indexes"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Array Indexes are Unsupported <a class="headerlink leafygreen-ui-1kepx47" href="#array-indexes-are-unsupported" 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="array-indexes-are-unsupported"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> You cannot use an array index with the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-project" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $project </code> </span> </a> stage. This section shows an example. </p> <p class="leafygreen-ui-1kp3ins"> Create the following <code class="leafygreen-ui-1l06pbn"> pizzas </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.pizzas.insert( [\n { _id: 0, name: [ 'Pepperoni' ] },\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">db.<span class="lg-highlight-property">pizzas</span>.<span class="lg-highlight-title lg-highlight-function">insert</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">name</span>: <!-- -->[ <span class="lg-highlight-string">'Pepperoni'</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> <p class="leafygreen-ui-1kp3ins"> The following example returns the pizza: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.pizzas.aggregate( [\n { $project: { x: '$name', _id: 0 } },\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">db.<span class="lg-highlight-property">pizzas</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">$project</span>: <!-- -->{ <span class="lg-highlight-attr">x</span>: <span class="lg-highlight-string">'$name'</span>, <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</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> <p class="leafygreen-ui-1kp3ins"> The pizza is returned in the example output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ { x: [ 'Pepperoni' ] } ]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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">[ <!-- -->{ <span class="lg-highlight-attr">x</span>: <!-- -->[ <span class="lg-highlight-string">'Pepperoni'</span> ] } ]</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> The following example uses an array index ( <code class="leafygreen-ui-1l06pbn"> $name.0 </code> ) to attempt to return the pizza: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.pizzas.aggregate( [\n { $project: { x: '$name.0', _id: 0 } },\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">db.<span class="lg-highlight-property">pizzas</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">$project</span>: <!-- -->{ <span class="lg-highlight-attr">x</span>: <span class="lg-highlight-string">'$name.0'</span>, <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</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> <p class="leafygreen-ui-1kp3ins"> The pizza is not returned in the example output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ { x: [] } ]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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">[ <!-- -->{ <span class="lg-highlight-attr">x</span>: <!-- -->[<!-- -->] } ]</td></tr></tbody></table></code></pre> </div> </div> </div> <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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/aggregation-zip-code-data-set/"> Aggregation with the Zip Code Data Set </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/aggregation-with-user-preference-data/"> Aggregation with User Preference Data </a> </p> </li> </ul> </div> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/tutorial/aggregation-zip-code-data-set/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Aggregation with the Zip Code Data Set <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-with-the-zip-code-data-set" 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="aggregation-with-the-zip-code-data-set"> </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="#data-model" target="_self"> <span> Data Model </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#aggregate---method" target="_self"> <span> <code class="css-1kekw28 e1wawog0"> aggregate() </code> Method </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#return-states-with-populations-above-10-million" target="_self"> <span> Return States with Populations above 10 Million </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#return-average-city-population-by-state" target="_self"> <span> Return Average City Population by State </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#return-largest-and-smallest-cities-by-state" target="_self"> <span> Return Largest and Smallest Cities by State </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> The examples in this document use the <code class="leafygreen-ui-1l06pbn"> zipcodes </code> collection. This collection is available at: <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://media.mongodb.org/zips.json" rel="noopener noreferrer"> <span> media.mongodb.org/zips.json </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> . Use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoimport </code> </span> </a> to load this data set into your <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instance. </p> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Data Model <a class="headerlink leafygreen-ui-1kepx47" href="#data-model" 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="data-model"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Each document in the <code class="leafygreen-ui-1l06pbn"> zipcodes </code> collection has the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\": \"10280\",\n \"city\": \"NEW YORK\",\n \"state\": \"NY\",\n \"pop\": 5574,\n \"loc\": [\n -74.016323,\n 40.710537\n ]\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-string">"10280"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"city"</span>: <span class="lg-highlight-string">"NEW YORK"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span>: <span class="lg-highlight-string">"NY"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pop"</span>: <span class="lg-highlight-number">5574</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"loc"</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->-<span class="lg-highlight-number">74.016323</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-number">40.710537</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> _id </code> field holds the zip code as a string. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> city </code> field holds the city name. A city can have more than one zip code associated with it as different sections of the city can each have a different zip code. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> state </code> field holds the two letter state abbreviation. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> pop </code> field holds the population. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> loc </code> field holds the location as a longitude latitude pair. </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> <code class="leafygreen-ui-1l06pbn"> aggregate() </code> Method <a class="headerlink leafygreen-ui-1kepx47" href="#aggregate---method" 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---method"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> All of the following examples use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> aggregate() </code> </a> helper in <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> </p> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> aggregate() </code> </a> method uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline </a> to process documents into aggregated results. An <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline </a> consists of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference"> stages </a> with each stage processing the documents as they pass along the pipeline. Documents pass through the stages in sequence. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> aggregate() </code> </a> method in <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> provides a wrapper around the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate"> <code class="leafygreen-ui-1l06pbn"> aggregate </code> </a> database command. See the documentation for your <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> driver </span> </a> for a more idiomatic interface for data aggregation operations. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-aggregation-return-states-by-population"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Return States with Populations above 10 Million <a class="headerlink leafygreen-ui-1kepx47" href="#return-states-with-populations-above-10-million" 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="return-states-with-populations-above-10-million"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation returns all states with total population greater than 10 million: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.zipcodes.aggregate( [\n { $group: { _id: \"$state\", totalPop: { $sum: \"$pop\" } } },\n { $match: { totalPop: { $gte: 10*1000*1000 } } }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">zipcodes</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">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$state"</span>, <span class="lg-highlight-attr">totalPop</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$pop"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-attr">totalPop</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-number">10</span>*<span class="lg-highlight-number">1000</span>*<span class="lg-highlight-number">1000</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> <p class="leafygreen-ui-1kp3ins"> In this example, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline </a> consists of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage followed by the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> stage: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage groups the documents of the <code class="leafygreen-ui-1l06pbn"> zipcode </code> collection by the <code class="leafygreen-ui-1l06pbn"> state </code> field, calculates the <code class="leafygreen-ui-1l06pbn"> totalPop </code> field for each state, and outputs a document for each unique state. </p> <p class="leafygreen-ui-1kp3ins"> The new per-state documents have two fields: the <code class="leafygreen-ui-1l06pbn"> _id </code> field and the <code class="leafygreen-ui-1l06pbn"> totalPop </code> field. The <code class="leafygreen-ui-1l06pbn"> _id </code> field contains the value of the <code class="leafygreen-ui-1l06pbn"> state </code> ; i.e. the group by field. The <code class="leafygreen-ui-1l06pbn"> totalPop </code> field is a calculated field that contains the total population of each state. To calculate the value, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> $sum </code> </a> operator to add the population field ( <code class="leafygreen-ui-1l06pbn"> pop </code> ) for each state. </p> <p class="leafygreen-ui-1kp3ins"> After the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage, the documents in the pipeline resemble the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : \"AK\",\n \"totalPop\" : 550043\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"AK"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"totalPop"</span> <!-- -->: <span class="lg-highlight-number">550043</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> stage filters these grouped documents to output only those documents whose <code class="leafygreen-ui-1l06pbn"> totalPop </code> value is greater than or equal to 10 million. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> stage does not alter the matching documents but outputs the matching documents unmodified. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The equivalent <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-SQL"> SQL </a> for this aggregation operation is: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"SELECT state, SUM(pop) AS totalPop\nFROM zipcodes\nGROUP BY state\nHAVING totalPop &gt;= (10*1000*1000)","programmingLanguage":"SQL"} </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 sql leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">SELECT</span> state, <span class="lg-highlight-built_in">SUM</span>(<!-- -->pop) <span class="lg-highlight-keyword">AS</span> totalPop</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">FROM</span> zipcodes</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">GROUP</span> <span class="lg-highlight-keyword">BY</span> state</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">HAVING</span> totalPop <span class="lg-highlight-operator">&gt;=</span> (<span class="lg-highlight-number">10</span><span class="lg-highlight-operator">*</span><span class="lg-highlight-number">1000</span><span class="lg-highlight-operator">*</span><span class="lg-highlight-number">1000</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 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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> $sum </code> </a> </p> </li> </ul> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Return Average City Population by State <a class="headerlink leafygreen-ui-1kepx47" href="#return-average-city-population-by-state" 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="return-average-city-population-by-state"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation returns the average populations for cities in each state: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.zipcodes.aggregate( [\n { $group: { _id: { state: \"$state\", city: \"$city\" }, pop: { $sum: \"$pop\" } } },\n { $group: { _id: \"$_id.state\", avgCityPop: { $avg: \"$pop\" } } }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">zipcodes</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">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"$state"</span>, <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-string">"$city"</span> }<!-- -->, <span class="lg-highlight-attr">pop</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$pop"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$_id.state"</span>, <span class="lg-highlight-attr">avgCityPop</span>: <!-- -->{ <span class="lg-highlight-attr">$avg</span>: <span class="lg-highlight-string">"$pop"</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> <p class="leafygreen-ui-1kp3ins"> In this example, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline </a> consists of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage followed by another <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The first <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage groups the documents by the combination of <code class="leafygreen-ui-1l06pbn"> city </code> and <code class="leafygreen-ui-1l06pbn"> state </code> , uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> $sum </code> </a> expression to calculate the population for each combination, and outputs a document for each <code class="leafygreen-ui-1l06pbn"> city </code> and <code class="leafygreen-ui-1l06pbn"> state </code> combination. <a class="footnote-reference header-buffer" href="#footnote-multiple-zips-per-city" id="ref-multiple-zips-per-city-id1"> [ <!-- --> 1 <!-- --> ] </a> </p> <p class="leafygreen-ui-1kp3ins"> After this stage in the pipeline, the documents resemble the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : {\n \"state\" : \"CO\",\n \"city\" : \"EDGEWATER\"\n },\n \"pop\" : 13154\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CO"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"city"</span> <!-- -->: <span class="lg-highlight-string">"EDGEWATER"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pop"</span> <!-- -->: <span class="lg-highlight-number">13154</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A second <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage groups the documents in the pipeline by the <code class="leafygreen-ui-1l06pbn"> _id.state </code> field (i.e. the <code class="leafygreen-ui-1l06pbn"> state </code> field inside the <code class="leafygreen-ui-1l06pbn"> _id </code> document), uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/avg/#mongodb-group-grp.-avg"> <code class="leafygreen-ui-1l06pbn"> $avg </code> </a> expression to calculate the average city population ( <code class="leafygreen-ui-1l06pbn"> avgCityPop </code> ) for each state, and outputs a document for each state. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The documents that result from this aggregation operation resembles the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : \"MN\",\n \"avgCityPop\" : 5335\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"MN"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"avgCityPop"</span> <!-- -->: <span class="lg-highlight-number">5335</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 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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> $sum </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/avg/#mongodb-group-grp.-avg"> <code class="leafygreen-ui-1l06pbn"> $avg </code> </a> </p> </li> </ul> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Return Largest and Smallest Cities by State <a class="headerlink leafygreen-ui-1kepx47" href="#return-largest-and-smallest-cities-by-state" 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="return-largest-and-smallest-cities-by-state"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation returns the smallest and largest cities by population for each state: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.zipcodes.aggregate( [\n { $group:\n {\n _id: { state: \"$state\", city: \"$city\" },\n pop: { $sum: \"$pop\" }\n }\n },\n { $sort: { pop: 1 } },\n { $group:\n {\n _id : \"$_id.state\",\n biggestCity: { $last: \"$_id.city\" },\n biggestPop: { $last: \"$pop\" },\n smallestCity: { $first: \"$_id.city\" },\n smallestPop: { $first: \"$pop\" }\n }\n },\n\n // the following $project is optional, and\n // modifies the output format.\n\n { $project:\n { _id: 0,\n state: \"$_id\",\n biggestCity: { name: \"$biggestCity\", pop: \"$biggestPop\" },\n smallestCity: { name: \"$smallestCity\", pop: \"$smallestPop\" }\n }\n }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">zipcodes</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">$group</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"$state"</span>, <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-string">"$city"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pop</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$pop"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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">pop</span>: <span class="lg-highlight-number">1</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->_id <!-- -->: <span class="lg-highlight-string">"$_id.state"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">biggestCity</span>: <!-- -->{ <span class="lg-highlight-attr">$last</span>: <span class="lg-highlight-string">"$_id.city"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">biggestPop</span>: <!-- -->{ <span class="lg-highlight-attr">$last</span>: <span class="lg-highlight-string">"$pop"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">smallestCity</span>: <!-- -->{ <span class="lg-highlight-attr">$first</span>: <span class="lg-highlight-string">"$_id.city"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">smallestPop</span>: <!-- -->{ <span class="lg-highlight-attr">$first</span>: <span class="lg-highlight-string">"$pop"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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"> <span class="lg-highlight-comment">// the following $project is optional, and</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> modifies the output </span><span class="lg-highlight-comment">format.</span></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-attr">$project</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"$_id"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">biggestCity</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"$biggestCity"</span>, <span class="lg-highlight-attr">pop</span>: <span class="lg-highlight-string">"$biggestPop"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">smallestCity</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"$smallestCity"</span>, <span class="lg-highlight-attr">pop</span>: <span class="lg-highlight-string">"$smallestPop"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> In this example, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline </a> consists of a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage, a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> stage, another <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage, and a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> stage: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The first <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage groups the documents by the combination of the <code class="leafygreen-ui-1l06pbn"> city </code> and <code class="leafygreen-ui-1l06pbn"> state </code> , calculates the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> sum </code> </a> of the <code class="leafygreen-ui-1l06pbn"> pop </code> values for each combination, and outputs a document for each <code class="leafygreen-ui-1l06pbn"> city </code> and <code class="leafygreen-ui-1l06pbn"> state </code> combination. </p> <p class="leafygreen-ui-1kp3ins"> At this stage in the pipeline, the documents resemble the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : {\n \"state\" : \"CO\",\n \"city\" : \"EDGEWATER\"\n },\n \"pop\" : 13154\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CO"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"city"</span> <!-- -->: <span class="lg-highlight-string">"EDGEWATER"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pop"</span> <!-- -->: <span class="lg-highlight-number">13154</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> stage orders the documents in the pipeline by the <code class="leafygreen-ui-1l06pbn"> pop </code> field value, from smallest to largest; i.e. by increasing order. This operation does not alter the documents. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The next <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage groups the now-sorted documents by the <code class="leafygreen-ui-1l06pbn"> _id.state </code> field (i.e. the <code class="leafygreen-ui-1l06pbn"> state </code> field inside the <code class="leafygreen-ui-1l06pbn"> _id </code> document) and outputs a document for each state. </p> <p class="leafygreen-ui-1kp3ins"> The stage also calculates the following four fields for each state. Using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/last/#mongodb-group-grp.-last"> <code class="leafygreen-ui-1l06pbn"> $last </code> </a> expression, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> operator creates the <code class="leafygreen-ui-1l06pbn"> biggestCity </code> and <code class="leafygreen-ui-1l06pbn"> biggestPop </code> fields that store the city with the largest population and that population. Using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/first/#mongodb-group-grp.-first"> <code class="leafygreen-ui-1l06pbn"> $first </code> </a> expression, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> operator creates the <code class="leafygreen-ui-1l06pbn"> smallestCity </code> and <code class="leafygreen-ui-1l06pbn"> smallestPop </code> fields that store the city with the smallest population and that population. </p> <p class="leafygreen-ui-1kp3ins"> The documents, at this stage in the pipeline, resemble the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : \"WA\",\n \"biggestCity\" : \"SEATTLE\",\n \"biggestPop\" : 520096,\n \"smallestCity\" : \"BENGE\",\n \"smallestPop\" : 2\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"biggestCity"</span> <!-- -->: <span class="lg-highlight-string">"SEATTLE"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"biggestPop"</span> <!-- -->: <span class="lg-highlight-number">520096</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"smallestCity"</span> <!-- -->: <span class="lg-highlight-string">"BENGE"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"smallestPop"</span> <!-- -->: <span class="lg-highlight-number">2</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The final <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> stage renames the <code class="leafygreen-ui-1l06pbn"> _id </code> field to <code class="leafygreen-ui-1l06pbn"> state </code> and moves the <code class="leafygreen-ui-1l06pbn"> biggestCity </code> , <code class="leafygreen-ui-1l06pbn"> biggestPop </code> , <code class="leafygreen-ui-1l06pbn"> smallestCity </code> , and <code class="leafygreen-ui-1l06pbn"> smallestPop </code> into <code class="leafygreen-ui-1l06pbn"> biggestCity </code> and <code class="leafygreen-ui-1l06pbn"> smallestCity </code> embedded documents. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The output documents of this aggregation operation resemble the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"state\" : \"RI\",\n \"biggestCity\" : {\n \"name\" : \"CRANSTON\",\n \"pop\" : 176404\n },\n \"smallestCity\" : {\n \"name\" : \"CLAYVILLE\",\n \"pop\" : 45\n }\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"RI"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"biggestCity"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"CRANSTON"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pop"</span> <!-- -->: <span class="lg-highlight-number">176404</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"smallestCity"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"CLAYVILLE"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pop"</span> <!-- -->: <span class="lg-highlight-number">45</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-multiple-zips-per-city" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <a href="#ref-multiple-zips-per-city-id1"> 1 </a> ] </td> <td class="leafygreen-ui-17r2xs0"> <!-- --> A city can have more than one zip code associated with it as different sections of the city can each have a different zip code. </td> </tr> </tbody> </table> </section> </section>
https://www.mongodb.com/docs/manual/core/map-reduce/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Map-Reduce <a class="headerlink leafygreen-ui-1kepx47" href="#map-reduce" 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="map-reduce"> </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="#map-reduce-javascript-functions" target="_self"> <span> Map-Reduce JavaScript Functions </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#map-reduce-results" target="_self"> <span> Map-Reduce Results </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#sharded-collections" target="_self"> <span> Sharded Collections </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#views" target="_self"> <span> Views </span> </a> </li> </ul> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Aggregation Pipeline as Alternative </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-map-reduce" target="_self"> <span> map-reduce </span> </a> is deprecated: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Instead of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-map-reduce" target="_self"> <span> map-reduce </span> </a> , you should use an <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline </a> . Aggregation pipelines provide better performance and usability than map-reduce. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You can rewrite map-reduce operations using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference"> aggregation pipeline stages </a> , such as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> , and others. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For map-reduce operations that require custom functionality, you can use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator"> <code class="leafygreen-ui-1l06pbn"> $accumulator </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function"> <code class="leafygreen-ui-1l06pbn"> $function </code> </a> aggregation operators. You can use those operators to define custom aggregation expressions in JavaScript. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For examples of aggregation pipeline alternatives to map-reduce, see: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/map-reduce-to-aggregation-pipeline/"> Map-Reduce to Aggregation Pipeline </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/map-reduce-examples/"> Map-Reduce Examples </a> </p> </li> </ul> </div> </div> <a class="css-53dzkk" href="https://www.mongodb.com/docs/atlas/atlas-ui/agg-pipeline"> <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/agg-pipeline/" target="_self"> <span> run aggregation pipelines 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> <p class="leafygreen-ui-1kp3ins"> Map-reduce is a data processing paradigm for condensing large volumes of data into useful <em> aggregated </em> results. To perform map-reduce operations, MongoDB provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce"> <code class="leafygreen-ui-1l06pbn"> mapReduce </code> </a> database command. </p> <p class="leafygreen-ui-1kp3ins"> Consider the following map-reduce operation: </p> <div class="figure css-5vkxs0" style="width: 760px;"> <img alt="Diagram of the annotated map-reduce operation." class="leafygreen-ui-1qnf57e" height="700" src="/docs/manual/images/map-reduce.bakedsvg.svg" style="--border-color: #C1C7C6;" width="815"/> </div> <p class="leafygreen-ui-1kp3ins"> In this map-reduce operation, MongoDB applies the <em> map </em> phase to each input document (i.e. the documents in the collection that match the query condition). The map function emits key-value pairs. For those keys that have multiple values, MongoDB applies the <em> reduce </em> phase, which collects and condenses the aggregated data. MongoDB then stores the results in a collection. Optionally, the output of the reduce function may pass through a <em> finalize </em> function to further condense or process the results of the aggregation. </p> <p class="leafygreen-ui-1kp3ins"> All map-reduce functions in MongoDB are JavaScript and run within the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process. Map-reduce operations take the documents of a single <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-collection"> collection </a> as the <em> input </em> and can perform any arbitrary sorting and limiting before beginning the map stage. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce"> <code class="leafygreen-ui-1l06pbn"> mapReduce </code> </a> can return the results of a map-reduce operation as a document, or may write the results to collections. </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"> Map-reduce is unsupported for MongoDB Atlas free clusters and MongoDB Atlas serverless instances. </p> </div> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Map-Reduce JavaScript Functions <a class="headerlink leafygreen-ui-1kepx47" href="#map-reduce-javascript-functions" 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="map-reduce-javascript-functions"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> In MongoDB, map-reduce operations use custom JavaScript functions to <em> map </em> , or associate, values to a key. If a key has multiple values mapped to it, the operation <em> reduces </em> the values for the key to a single object. </p> <p class="leafygreen-ui-1kp3ins"> The use of custom JavaScript functions provide flexibility to map-reduce operations. For instance, when processing a document, the map function can create more than one key and value mapping or no mapping. Map-reduce operations can also use a custom JavaScript function to make final modifications to the results at the end of the map and reduce operation, such as perform additional calculations. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Map-Reduce Results <a class="headerlink leafygreen-ui-1kepx47" href="#map-reduce-results" 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="map-reduce-results"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> In MongoDB, the map-reduce operation can write results to a collection or return the results inline. If you write map-reduce output to a collection, you can perform subsequent map-reduce operations on the same input collection that merge replace, merge, or reduce new results with previous results. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce"> <code class="leafygreen-ui-1l06pbn"> mapReduce </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/perform-incremental-map-reduce/"> Perform Incremental Map-Reduce </a> for details and examples. </p> <p class="leafygreen-ui-1kp3ins"> When returning the results of a map-reduce operation <em> inline </em> , the result documents must be within the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#mongodb-limit-BSON-Document-Size"> BSON Document Size </a> limit, which is currently 16 megabytes. For additional information on limits and restrictions on map-reduce operations, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/"> mapReduce </a> reference page. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Sharded Collections <a class="headerlink leafygreen-ui-1kepx47" href="#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-collections"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB supports map-reduce operations on <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/#std-label-sharding-background"> sharded collections. </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Views <a class="headerlink leafygreen-ui-1kepx47" href="#views" 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="views"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page"> Views </a> do not support map-reduce operations. </p> </section> </section>
https://www.mongodb.com/docs/manual/tutorial/perform-incremental-map-reduce/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Perform Incremental Map-Reduce <a class="headerlink leafygreen-ui-1kepx47" href="#perform-incremental-map-reduce" 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="perform-incremental-map-reduce"> </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="#data-setup" target="_self"> <span> Data Setup </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#initial-map-reduce-of-current-collection" target="_self"> <span> Initial Map-Reduce of Current Collection </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#subsequent-incremental-map-reduce" target="_self"> <span> Subsequent Incremental Map-Reduce </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#aggregation-alternative" target="_self"> <span> Aggregation Alternative </span> </a> </li> </ul> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Aggregation Pipeline as Alternative </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce"> map-reduce </a> is deprecated: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Instead of <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce"> map-reduce </a> , you should use an <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline </a> . Aggregation pipelines provide better performance and usability than map-reduce. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You can rewrite map-reduce operations using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference"> aggregation pipeline stages </a> , such as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> , and others. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For map-reduce operations that require custom functionality, you can use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator"> <code class="leafygreen-ui-1l06pbn"> $accumulator </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function"> <code class="leafygreen-ui-1l06pbn"> $function </code> </a> aggregation operators. You can use those operators to define custom aggregation expressions in JavaScript. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For examples of aggregation pipeline alternatives to map-reduce, see: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/map-reduce-to-aggregation-pipeline/"> Map-Reduce to Aggregation Pipeline </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/map-reduce-examples/"> Map-Reduce Examples </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> This section has an example aggregation pipeline alternative to map-reduce that does not use a custom function. For an example that uses a custom function, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/map-reduce-to-aggregation-pipeline/"> Map-Reduce to Aggregation Pipeline <!-- --> . </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> To perform map-reduce operations, MongoDB provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce"> <code class="leafygreen-ui-1l06pbn"> mapReduce </code> </a> command and, in <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> , the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.mapReduce/#mongodb-method-db.collection.mapReduce"> <code class="leafygreen-ui-1l06pbn"> db.collection.mapReduce() </code> </a> wrapper method. </p> <p class="leafygreen-ui-1kp3ins"> If the map-reduce data set is constantly growing, you may want to perform an incremental map-reduce rather than performing the map-reduce operation over the entire data set each time. </p> <p class="leafygreen-ui-1kp3ins"> To perform incremental map-reduce: </p> <ol class="leafygreen-ui-rioki0" type="1"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Run a map-reduce job over the current collection and output the result to a separate collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> When you have more data to process, run subsequent map-reduce jobs with: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the <code class="leafygreen-ui-1l06pbn"> query </code> parameter that specifies conditions that match <em> only </em> the new documents. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the <code class="leafygreen-ui-1l06pbn"> out </code> parameter that specifies the <code class="leafygreen-ui-1l06pbn"> reduce </code> action to merge the new results into the existing output collection. </p> </li> </ul> </li> </ol> <p class="leafygreen-ui-1kp3ins"> Consider the following example where you schedule a map-reduce operation on a <code class="leafygreen-ui-1l06pbn"> usersessions </code> collection to run at the end of each day. </p> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Data Setup <a class="headerlink leafygreen-ui-1kepx47" href="#data-setup" 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="data-setup"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> usersessions </code> collection contains documents that log users' sessions each day, for example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.usersessions.insertMany([\n { userid: \"a\", start: ISODate('2020-03-03 14:17:00'), length: 95 },\n { userid: \"b\", start: ISODate('2020-03-03 14:23:00'), length: 110 },\n { userid: \"c\", start: ISODate('2020-03-03 15:02:00'), length: 120 },\n { userid: \"d\", start: ISODate('2020-03-03 16:45:00'), length: 45 },\n { userid: \"a\", start: ISODate('2020-03-04 11:05:00'), length: 105 },\n { userid: \"b\", start: ISODate('2020-03-04 13:14:00'), length: 120 },\n { userid: \"c\", start: ISODate('2020-03-04 17:00:00'), length: 130 },\n { userid: \"d\", start: ISODate('2020-03-04 15:37:00'), length: 65 }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">usersessions</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-03 14:17:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">95</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-03 14:23:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">110</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-03 15:02:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">120</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-03 16:45:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">45</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-04 11:05:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">105</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-04 13:14:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">120</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-04 17:00:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">130</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-04 15:37:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">65</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Initial Map-Reduce of Current Collection <a class="headerlink leafygreen-ui-1kepx47" href="#initial-map-reduce-of-current-collection" 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="initial-map-reduce-of-current-collection"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Run the first map-reduce operation as follows: </p> <ol class="leafygreen-ui-rioki0" type="1"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Define the map function that maps the <code class="leafygreen-ui-1l06pbn"> userid </code> to an object that contains the fields <code class="leafygreen-ui-1l06pbn"> total_time </code> , <code class="leafygreen-ui-1l06pbn"> count </code> , and <code class="leafygreen-ui-1l06pbn"> avg_time </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var mapFunction = function() {\n var key = this.userid;\n var value = { total_time: this.length, count: 1, avg_time: 0 };\n\n emit( key, value );\n};","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> mapFunction <!-- -->= <span class="lg-highlight-keyword lg-highlight-function">function</span>(<!-- -->)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> key <!-- -->= <span class="lg-highlight-variable lg-highlight-language">this</span>.<span class="lg-highlight-property">userid</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> value <!-- -->= <!-- -->{ <span class="lg-highlight-attr">total_time</span>: <span class="lg-highlight-variable lg-highlight-language">this</span>.<span class="lg-highlight-property">length</span>, <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">avg_time</span>: <span class="lg-highlight-number">0</span> }<!-- -->;</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-function">emit</span>( <!-- -->key<!-- -->, <!-- -->value )<!-- -->;</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Define the corresponding reduce function with two arguments <code class="leafygreen-ui-1l06pbn"> key </code> and <code class="leafygreen-ui-1l06pbn"> values </code> to calculate the total time and the count. The <code class="leafygreen-ui-1l06pbn"> key </code> corresponds to the <code class="leafygreen-ui-1l06pbn"> userid </code> , and the <code class="leafygreen-ui-1l06pbn"> values </code> is an array whose elements corresponds to the individual objects mapped to the <code class="leafygreen-ui-1l06pbn"> userid </code> in the <code class="leafygreen-ui-1l06pbn"> mapFunction </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var reduceFunction = function(key, values) {\n\n var reducedObject = { total_time: 0, count:0, avg_time:0 };\n\n values.forEach(function(value) {\n reducedObject.total_time += value.total_time;\n reducedObject.count += value.count;\n });\n\n return reducedObject;\n};","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> reduceFunction <!-- -->= <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">key, values</span>)<!-- --> <!-- -->{</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-keyword">var</span> reducedObject <!-- -->= <!-- -->{ <span class="lg-highlight-attr">total_time</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">count</span>:<span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">avg_time</span>:<span class="lg-highlight-number">0</span> }<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->values.<span class="lg-highlight-title lg-highlight-function">forEach</span>(<span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">value</span>)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->reducedObject.<span class="lg-highlight-property">total_time</span> <!-- -->+<!-- -->= <!-- -->value.<span class="lg-highlight-property">total_time</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->reducedObject.<span class="lg-highlight-property">count</span> <!-- -->+<!-- -->= <!-- -->value.<span class="lg-highlight-property">count</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"> <span class="lg-highlight-keyword">return</span> <!-- -->reducedObject<!-- -->;</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Define the finalize function with two arguments <code class="leafygreen-ui-1l06pbn"> key </code> and <code class="leafygreen-ui-1l06pbn"> reducedValue </code> . The function modifies the <code class="leafygreen-ui-1l06pbn"> reducedValue </code> document to add another field <code class="leafygreen-ui-1l06pbn"> average </code> and returns the modified document. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var finalizeFunction = function(key, reducedValue) {\n\n if (reducedValue.count &gt; 0)\n reducedValue.avg_time = reducedValue.total_time / reducedValue.count;\n\n return reducedValue;\n};","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> finalizeFunction <!-- -->= <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">key, reducedValue</span>)<!-- --> <!-- -->{</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-keyword">if</span> <!-- -->(<!-- -->reducedValue.<span class="lg-highlight-property">count</span> <!-- -->&gt; <span class="lg-highlight-number">0</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> reducedValue.<span class="lg-highlight-property">avg_time</span> <!-- -->= <!-- -->reducedValue.<span class="lg-highlight-property">total_time</span> <!-- -->/ <!-- -->reducedValue.<span class="lg-highlight-property">count</span>;</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-keyword">return</span> <!-- -->reducedValue<!-- -->;</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Perform map-reduce on the <code class="leafygreen-ui-1l06pbn"> usersessions </code> collection using the <code class="leafygreen-ui-1l06pbn"> mapFunction </code> , the <code class="leafygreen-ui-1l06pbn"> reduceFunction </code> , and the <code class="leafygreen-ui-1l06pbn"> finalizeFunction </code> functions. Output the results to a collection <code class="leafygreen-ui-1l06pbn"> session_stats </code> . If the <code class="leafygreen-ui-1l06pbn"> session_stats </code> collection already exists, the operation will replace the contents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.usersessions.mapReduce(\n mapFunction,\n reduceFunction,\n {\n out: \"session_stats\",\n finalize: finalizeFunction\n }\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">db.<span class="lg-highlight-property">usersessions</span>.<span class="lg-highlight-title lg-highlight-function">mapReduce</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->mapFunction<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->reduceFunction<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">out</span>: <span class="lg-highlight-string">"session_stats"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">finalize</span>: <!-- -->finalizeFunction</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Query the <code class="leafygreen-ui-1l06pbn"> session_stats </code> collection to verify the results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.session_stats.find().sort( { _id: 1 } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">session_stats</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"a\", \"value\" : { \"total_time\" : 200, \"count\" : 2, \"avg_time\" : 100 } }\n{ \"_id\" : \"b\", \"value\" : { \"total_time\" : 230, \"count\" : 2, \"avg_time\" : 115 } }\n{ \"_id\" : \"c\", \"value\" : { \"total_time\" : 250, \"count\" : 2, \"avg_time\" : 125 } }\n{ \"_id\" : \"d\", \"value\" : { \"total_time\" : 110, \"count\" : 2, \"avg_time\" : 55 } }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">200</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">100</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">230</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">115</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">250</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">125</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">110</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">55</span> } }</td></tr></tbody></table></code></pre> </div> </div> </div> </li> </ol> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Subsequent Incremental Map-Reduce <a class="headerlink leafygreen-ui-1kepx47" href="#subsequent-incremental-map-reduce" 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="subsequent-incremental-map-reduce"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Later, as the <code class="leafygreen-ui-1l06pbn"> usersessions </code> collection grows, you can run additional map-reduce operations. For example, add new documents to the <code class="leafygreen-ui-1l06pbn"> usersessions </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.usersessions.insertMany([\n { userid: \"a\", ts: ISODate('2020-03-05 14:17:00'), length: 130 },\n { userid: \"b\", ts: ISODate('2020-03-05 14:23:00'), length: 40 },\n { userid: \"c\", ts: ISODate('2020-03-05 15:02:00'), length: 110 },\n { userid: \"d\", ts: ISODate('2020-03-05 16:45:00'), length: 100 }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">usersessions</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-attr">ts</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-05 14:17:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">130</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-attr">ts</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-05 14:23:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">40</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-attr">ts</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-05 15:02:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">110</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-attr">ts</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-05 16:45:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">100</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> <p class="leafygreen-ui-1kp3ins"> At the end of the day, perform incremental map-reduce on the <code class="leafygreen-ui-1l06pbn"> usersessions </code> collection, but use the <code class="leafygreen-ui-1l06pbn"> query </code> field to select only the new documents. Output the results to the collection <code class="leafygreen-ui-1l06pbn"> session_stats </code> , but <code class="leafygreen-ui-1l06pbn"> reduce </code> the contents with the results of the incremental map-reduce: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.usersessions.mapReduce(\n mapFunction,\n reduceFunction,\n {\n query: { ts: { $gte: ISODate('2020-03-05 00:00:00') } },\n out: { reduce: \"session_stats\" },\n finalize: finalizeFunction\n }\n);","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">usersessions</span>.<span class="lg-highlight-title lg-highlight-function">mapReduce</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->mapFunction<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->reduceFunction<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">ts</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-05 00:00:00'</span>) } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">out</span>: <!-- -->{ <span class="lg-highlight-attr">reduce</span>: <span class="lg-highlight-string">"session_stats"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">finalize</span>: <!-- -->finalizeFunction</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> Query the <code class="leafygreen-ui-1l06pbn"> session_stats </code> collection to verify the results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.session_stats.find().sort( { _id: 1 } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">session_stats</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"a\", \"value\" : { \"total_time\" : 330, \"count\" : 3, \"avg_time\" : 110 } }\n{ \"_id\" : \"b\", \"value\" : { \"total_time\" : 270, \"count\" : 3, \"avg_time\" : 90 } }\n{ \"_id\" : \"c\", \"value\" : { \"total_time\" : 360, \"count\" : 3, \"avg_time\" : 120 } }\n{ \"_id\" : \"d\", \"value\" : { \"total_time\" : 210, \"count\" : 3, \"avg_time\" : 70 } }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">330</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">110</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">270</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">90</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">360</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">120</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">210</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">70</span> } }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Aggregation Alternative <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-alternative" 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="aggregation-alternative"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> As an alternative to map-reduce, you can use an <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline </a> that combines <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> stages to achieve the same result in a more flexible operation. </p> <p class="leafygreen-ui-1kp3ins"> Recreate the <code class="leafygreen-ui-1l06pbn"> usersessions </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.usersessions.drop();\n\ndb.usersessions.insertMany([\n { userid: \"a\", start: ISODate('2020-03-03 14:17:00'), length: 95 },\n { userid: \"b\", start: ISODate('2020-03-03 14:23:00'), length: 110 },\n { userid: \"c\", start: ISODate('2020-03-03 15:02:00'), length: 120 },\n { userid: \"d\", start: ISODate('2020-03-03 16:45:00'), length: 45 },\n { userid: \"a\", start: ISODate('2020-03-04 11:05:00'), length: 105 },\n { userid: \"b\", start: ISODate('2020-03-04 13:14:00'), length: 120 },\n { userid: \"c\", start: ISODate('2020-03-04 17:00:00'), length: 130 },\n { userid: \"d\", start: ISODate('2020-03-04 15:37:00'), length: 65 }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">usersessions</span>.<span class="lg-highlight-title lg-highlight-function">drop</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">usersessions</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-03 14:17:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">95</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-03 14:23:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">110</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-03 15:02:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">120</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-03 16:45:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">45</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-04 11:05:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">105</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-04 13:14:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">120</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-04 17:00:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">130</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-attr">start</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-04 15:37:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">65</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> <p class="leafygreen-ui-1kp3ins"> Using the available aggregation pipeline operators, you can rewrite the map-reduce example without defining custom functions: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.usersessions.aggregate([\n { $group: { _id: \"$userid\", total_time: { $sum: \"$length\" }, count: { $sum: 1 }, avg_time: { $avg: \"$length\" } } },\n { $project: { value: { total_time: \"$total_time\", count: \"$count\", avg_time: \"$avg_time\" } } },\n { $merge: {\n into: \"session_stats_agg\",\n whenMatched: [ { $set: {\n \"value.total_time\": { $add: [ \"$value.total_time\", \"$$new.value.total_time\" ] },\n \"value.count\": { $add: [ \"$value.count\", \"$$new.value.count\" ] },\n \"value.avg\": { $divide: [ { $add: [ \"$value.total_time\", \"$$new.value.total_time\" ] }, { $add: [ \"$value.count\", \"$$new.value.count\" ] } ] }\n } } ],\n whenNotMatched: \"insert\"\n }}\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">usersessions</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">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$userid"</span>, <span class="lg-highlight-attr">total_time</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$length"</span> }<!-- -->, <span class="lg-highlight-attr">count</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-attr">avg_time</span>: <!-- -->{ <span class="lg-highlight-attr">$avg</span>: <span class="lg-highlight-string">"$length"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <!-- -->{ <span class="lg-highlight-attr">total_time</span>: <span class="lg-highlight-string">"$total_time"</span>, <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-string">"$count"</span>, <span class="lg-highlight-attr">avg_time</span>: <span class="lg-highlight-string">"$avg_time"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$merge</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">into</span>: <span class="lg-highlight-string">"session_stats_agg"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">whenMatched</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value.total_time"</span>: <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.total_time"</span>, <span class="lg-highlight-string">"$$new.value.total_time"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value.count"</span>: <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.count"</span>, <span class="lg-highlight-string">"$$new.value.count"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value.avg"</span>: <!-- -->{ <span class="lg-highlight-attr">$divide</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.total_time"</span>, <span class="lg-highlight-string">"$$new.value.total_time"</span> ] }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.count"</span>, <span class="lg-highlight-string">"$$new.value.count"</span> ] } ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> } } ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">whenNotMatched</span>: <span class="lg-highlight-string">"insert"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }}</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> <ol class="leafygreen-ui-rioki0" type="1"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> groups by the <code class="leafygreen-ui-1l06pbn"> userid </code> and calculates: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> total_time </code> using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> $sum </code> </a> operator </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> count </code> using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> $sum </code> </a> operator </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> avg_time </code> using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/avg/#mongodb-group-grp.-avg"> <code class="leafygreen-ui-1l06pbn"> $avg </code> </a> operator </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The operation returns the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"c\", \"total_time\" : 250, \"count\" : 2, \"avg_time\" : 125 }\n{ \"_id\" : \"d\", \"total_time\" : 110, \"count\" : 2, \"avg_time\" : 55 }\n{ \"_id\" : \"a\", \"total_time\" : 200, \"count\" : 2, \"avg_time\" : 100 }\n{ \"_id\" : \"b\", \"total_time\" : 230, \"count\" : 2, \"avg_time\" : 115 }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">250</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">125</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">110</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">55</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">200</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">100</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">230</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">115</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> stage reshapes the output document to mirror the map-reduce's output to have two fields <code class="leafygreen-ui-1l06pbn"> _id </code> and <code class="leafygreen-ui-1l06pbn"> value </code> . The stage is optional if you do not need to mirror the <code class="leafygreen-ui-1l06pbn"> _id </code> and <code class="leafygreen-ui-1l06pbn"> value </code> structure. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"a\", \"value\" : { \"total_time\" : 200, \"count\" : 2, \"avg_time\" : 100 } }\n{ \"_id\" : \"d\", \"value\" : { \"total_time\" : 110, \"count\" : 2, \"avg_time\" : 55 } }\n{ \"_id\" : \"b\", \"value\" : { \"total_time\" : 230, \"count\" : 2, \"avg_time\" : 115 } }\n{ \"_id\" : \"c\", \"value\" : { \"total_time\" : 250, \"count\" : 2, \"avg_time\" : 125 } }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">200</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">100</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">110</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">55</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">230</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">115</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">250</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">125</span> } }</td></tr></tbody></table></code></pre> </div> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> stage outputs the results to a <code class="leafygreen-ui-1l06pbn"> session_stats_agg </code> collection. If an existing document has the same <code class="leafygreen-ui-1l06pbn"> _id </code> as the new result, the operation applies the specified pipeline to calculate the total_time, count, and avg_time from the result and the existing document. If there is no existing document with the same <code class="leafygreen-ui-1l06pbn"> _id </code> in the <code class="leafygreen-ui-1l06pbn"> session_stats_agg </code> , the operation inserts the document. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Query the <code class="leafygreen-ui-1l06pbn"> session_stats_agg </code> collection to verify the results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.session_stats_agg.find().sort( { _id: 1 } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">session_stats_agg</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"a\", \"value\" : { \"total_time\" : 200, \"count\" : 2, \"avg_time\" : 100 } }\n{ \"_id\" : \"b\", \"value\" : { \"total_time\" : 230, \"count\" : 2, \"avg_time\" : 115 } }\n{ \"_id\" : \"c\", \"value\" : { \"total_time\" : 250, \"count\" : 2, \"avg_time\" : 125 } }\n{ \"_id\" : \"d\", \"value\" : { \"total_time\" : 110, \"count\" : 2, \"avg_time\" : 55 } }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">200</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">100</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">230</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">115</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">250</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">125</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">110</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">55</span> } }</td></tr></tbody></table></code></pre> </div> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Add new documents to the <code class="leafygreen-ui-1l06pbn"> usersessions </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.usersessions.insertMany([\n { userid: \"a\", ts: ISODate('2020-03-05 14:17:00'), length: 130 },\n { userid: \"b\", ts: ISODate('2020-03-05 14:23:00'), length: 40 },\n { userid: \"c\", ts: ISODate('2020-03-05 15:02:00'), length: 110 },\n { userid: \"d\", ts: ISODate('2020-03-05 16:45:00'), length: 100 }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">usersessions</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-attr">ts</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-05 14:17:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">130</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-attr">ts</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-05 14:23:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">40</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-attr">ts</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-05 15:02:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">110</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-attr">ts</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-05 16:45:00'</span>)<!-- -->, <span class="lg-highlight-attr">length</span>: <span class="lg-highlight-number">100</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Add a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> stage at the start of the pipeline to specify the date filter: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.usersessions.aggregate([\n { $match: { ts: { $gte: ISODate('2020-03-05 00:00:00') } } },\n { $group: { _id: \"$userid\", total_time: { $sum: \"$length\" }, count: { $sum: 1 }, avg_time: { $avg: \"$length\" } } },\n { $project: { value: { total_time: \"$total_time\", count: \"$count\", avg_time: \"$avg_time\" } } },\n { $merge: {\n into: \"session_stats_agg\",\n whenMatched: [ { $set: {\n \"value.total_time\": { $add: [ \"$value.total_time\", \"$$new.value.total_time\" ] },\n \"value.count\": { $add: [ \"$value.count\", \"$$new.value.count\" ] },\n \"value.avg_time\": { $divide: [ { $add: [ \"$value.total_time\", \"$$new.value.total_time\" ] }, { $add: [ \"$value.count\", \"$$new.value.count\" ] } ] }\n } } ],\n whenNotMatched: \"insert\"\n }}\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">usersessions</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">ts</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-05 00:00:00'</span>) } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$userid"</span>, <span class="lg-highlight-attr">total_time</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$length"</span> }<!-- -->, <span class="lg-highlight-attr">count</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-attr">avg_time</span>: <!-- -->{ <span class="lg-highlight-attr">$avg</span>: <span class="lg-highlight-string">"$length"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <!-- -->{ <span class="lg-highlight-attr">total_time</span>: <span class="lg-highlight-string">"$total_time"</span>, <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-string">"$count"</span>, <span class="lg-highlight-attr">avg_time</span>: <span class="lg-highlight-string">"$avg_time"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$merge</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">into</span>: <span class="lg-highlight-string">"session_stats_agg"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">whenMatched</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value.total_time"</span>: <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.total_time"</span>, <span class="lg-highlight-string">"$$new.value.total_time"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value.count"</span>: <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.count"</span>, <span class="lg-highlight-string">"$$new.value.count"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value.avg_time"</span>: <!-- -->{ <span class="lg-highlight-attr">$divide</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.total_time"</span>, <span class="lg-highlight-string">"$$new.value.total_time"</span> ] }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.count"</span>, <span class="lg-highlight-string">"$$new.value.count"</span> ] } ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> } } ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">whenNotMatched</span>: <span class="lg-highlight-string">"insert"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }}</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Query the <code class="leafygreen-ui-1l06pbn"> session_stats_agg </code> collection to verify the results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.session_stats_agg.find().sort( { _id: 1 } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">session_stats_agg</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"a\", \"value\" : { \"total_time\" : 330, \"count\" : 3, \"avg_time\" : 110 } }\n{ \"_id\" : \"b\", \"value\" : { \"total_time\" : 270, \"count\" : 3, \"avg_time\" : 90 } }\n{ \"_id\" : \"c\", \"value\" : { \"total_time\" : 360, \"count\" : 3, \"avg_time\" : 120 } }\n{ \"_id\" : \"d\", \"value\" : { \"total_time\" : 210, \"count\" : 3, \"avg_time\" : 70 } }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">330</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">110</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">270</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">90</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"c"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">360</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">120</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"d"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"total_time"</span> <!-- -->: <span class="lg-highlight-number">210</span>, <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"avg_time"</span> <!-- -->: <span class="lg-highlight-number">70</span> } }</td></tr></tbody></table></code></pre> </div> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Optional. To avoid having to modify the aggregation pipeline's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> date condition each time you run, you can define wrap the aggregation in a helper function: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"updateSessionStats = function(startDate) {\n db.usersessions.aggregate([\n { $match: { ts: { $gte: startDate } } },\n { $group: { _id: \"$userid\", total_time: { $sum: \"$length\" }, count: { $sum: 1 }, avg_time: { $avg: \"$length\" } } },\n { $project: { value: { total_time: \"$total_time\", count: \"$count\", avg_time: \"$avg_time\" } } },\n { $merge: {\n into: \"session_stats_agg\",\n whenMatched: [ { $set: {\n \"value.total_time\": { $add: [ \"$value.total_time\", \"$$new.value.total_time\" ] },\n \"value.count\": { $add: [ \"$value.count\", \"$$new.value.count\" ] },\n \"value.avg_time\": { $divide: [ { $add: [ \"$value.total_time\", \"$$new.value.total_time\" ] }, { $add: [ \"$value.count\", \"$$new.value.count\" ] } ] }\n } } ],\n whenNotMatched: \"insert\"\n }}\n ]);\n};","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">updateSessionStats <!-- -->= <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">startDate</span>)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->db.<span class="lg-highlight-property">usersessions</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">ts</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <!-- -->startDate } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$userid"</span>, <span class="lg-highlight-attr">total_time</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$length"</span> }<!-- -->, <span class="lg-highlight-attr">count</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-attr">avg_time</span>: <!-- -->{ <span class="lg-highlight-attr">$avg</span>: <span class="lg-highlight-string">"$length"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <!-- -->{ <span class="lg-highlight-attr">total_time</span>: <span class="lg-highlight-string">"$total_time"</span>, <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-string">"$count"</span>, <span class="lg-highlight-attr">avg_time</span>: <span class="lg-highlight-string">"$avg_time"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$merge</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">into</span>: <span class="lg-highlight-string">"session_stats_agg"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">whenMatched</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value.total_time"</span>: <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.total_time"</span>, <span class="lg-highlight-string">"$$new.value.total_time"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value.count"</span>: <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.count"</span>, <span class="lg-highlight-string">"$$new.value.count"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"value.avg_time"</span>: <!-- -->{ <span class="lg-highlight-attr">$divide</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.total_time"</span>, <span class="lg-highlight-string">"$$new.value.total_time"</span> ] }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$value.count"</span>, <span class="lg-highlight-string">"$$new.value.count"</span> ] } ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> } } ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">whenNotMatched</span>: <span class="lg-highlight-string">"insert"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ])<!-- -->;</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> <p class="leafygreen-ui-1kp3ins"> Then, to run, you would just pass in the start date to the <code class="leafygreen-ui-1l06pbn"> updateSessionStats() </code> function: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"updateSessionStats(ISODate('2020-03-05 00:00:00'))","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-title lg-highlight-function">updateSessionStats</span>(<span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">'2020-03-05 00:00:00'</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> </li> </ol> <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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#std-label-merge-examples"> $merge Examples </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/materialized-views/"> On-Demand Materialized Views </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/map-reduce-to-aggregation-pipeline/"> Map-Reduce to Aggregation Pipeline </a> </p> </li> </ul> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/nav-sharding/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Sharding Commands <a class="headerlink leafygreen-ui-1kepx47" href="#sharding-commands" 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-commands"> </div> </a> </h1> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> For details on a specific command, including syntax and examples, click on the link to the command's reference page. </p> </div> </div> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/abortMoveCollection/#mongodb-dbcommand-dbcmd.abortMoveCollection"> <code class="leafygreen-ui-1l06pbn"> abortMoveCollection </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Stops an in-progress <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveCollection/#mongodb-dbcommand-dbcmd.moveCollection"> <code class="leafygreen-ui-1l06pbn"> moveCollection </code> </a> operation. </p> <div> <p> <em> New <!-- --> in version <!-- --> 8.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/abortReshardCollection/#mongodb-dbcommand-dbcmd.abortReshardCollection"> <code class="leafygreen-ui-1l06pbn"> abortReshardCollection </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Aborts a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation <!-- --> . </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/abortUnshardCollection/#mongodb-dbcommand-dbcmd.abortUnshardCollection"> <code class="leafygreen-ui-1l06pbn"> abortUnshardCollection </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Stops an in-progress <code class="leafygreen-ui-1l06pbn"> unshardCollection </code> operation. </p> <div> <p> <em> New <!-- --> in version <!-- --> 8.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/addShard/#mongodb-dbcommand-dbcmd.addShard"> <code class="leafygreen-ui-1l06pbn"> addShard </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Adds a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard"> shard </a> to a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster <!-- --> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/addShardToZone/#mongodb-dbcommand-dbcmd.addShardToZone"> <code class="leafygreen-ui-1l06pbn"> addShardToZone </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Associates a shard with a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zone"> zone </a> . Supports configuring <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding"> zones </a> in sharded clusters. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/analyzeShardKey/#mongodb-dbcommand-dbcmd.analyzeShardKey"> <code class="leafygreen-ui-1l06pbn"> analyzeShardKey </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Calculates metrics for evaluating a shard key. </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/balancerCollectionStatus/#mongodb-dbcommand-dbcmd.balancerCollectionStatus"> <code class="leafygreen-ui-1l06pbn"> balancerCollectionStatus </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns information on whether the chunks of a sharded collection are balanced. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/balancerStart/#mongodb-dbcommand-dbcmd.balancerStart"> <code class="leafygreen-ui-1l06pbn"> balancerStart </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Starts a balancer thread. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/balancerStatus/#mongodb-dbcommand-dbcmd.balancerStatus"> <code class="leafygreen-ui-1l06pbn"> balancerStatus </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns information on the balancer status. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/balancerStop/#mongodb-dbcommand-dbcmd.balancerStop"> <code class="leafygreen-ui-1l06pbn"> balancerStop </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Stops the balancer thread. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/checkMetadataConsistency/#mongodb-dbcommand-dbcmd.checkMetadataConsistency"> <code class="leafygreen-ui-1l06pbn"> checkMetadataConsistency </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Performs a series of consistency checks on sharding metadata. </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/clearJumboFlag/#mongodb-dbcommand-dbcmd.clearJumboFlag"> <code class="leafygreen-ui-1l06pbn"> clearJumboFlag </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Clears the <code class="leafygreen-ui-1l06pbn"> jumbo </code> flag for a chunk. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/cleanupReshardCollection/#mongodb-dbcommand-dbcmd.cleanupReshardCollection"> <code class="leafygreen-ui-1l06pbn"> cleanupReshardCollection </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Cleans up a failed <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation <!-- --> . </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/commitReshardCollection/#mongodb-dbcommand-dbcmd.commitReshardCollection"> <code class="leafygreen-ui-1l06pbn"> commitReshardCollection </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Forces a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> to block writes and complete. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/configureCollectionBalancing/#mongodb-dbcommand-dbcmd.configureCollectionBalancing"> <code class="leafygreen-ui-1l06pbn"> configureCollectionBalancing </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Configures balancer settings on a sharded collection. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.3 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/configureQueryAnalyzer/#mongodb-dbcommand-dbcmd.configureQueryAnalyzer"> <code class="leafygreen-ui-1l06pbn"> configureQueryAnalyzer </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Configures query sampling for a collection. </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/enableSharding/#mongodb-dbcommand-dbcmd.enableSharding"> <code class="leafygreen-ui-1l06pbn"> enableSharding </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Creates a database. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/flushRouterConfig/#mongodb-dbcommand-dbcmd.flushRouterConfig"> <code class="leafygreen-ui-1l06pbn"> flushRouterConfig </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Forces a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instance to update its cached routing metadata. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getShardMap/#mongodb-dbcommand-dbcmd.getShardMap"> <code class="leafygreen-ui-1l06pbn"> getShardMap </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns the hostnames and connection strings for shards in the cluster and the config servers for your cluster. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/isdbgrid/#mongodb-dbcommand-dbcmd.isdbgrid"> <code class="leafygreen-ui-1l06pbn"> isdbgrid </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Verifies that a process is a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/listShards/#mongodb-dbcommand-dbcmd.listShards"> <code class="leafygreen-ui-1l06pbn"> listShards </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns a list of configured shards. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveChunk/#mongodb-dbcommand-dbcmd.moveChunk"> <code class="leafygreen-ui-1l06pbn"> moveChunk </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Internal command that migrates chunks between shards. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/movePrimary/#mongodb-dbcommand-dbcmd.movePrimary"> <code class="leafygreen-ui-1l06pbn"> movePrimary </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Reassigns the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary-shard"> primary shard </a> when removing a shard from a sharded cluster. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveRange/#mongodb-dbcommand-dbcmd.moveRange"> <code class="leafygreen-ui-1l06pbn"> moveRange </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Migrates ranges between shards. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mergeAllChunksOnShard/#mongodb-dbcommand-dbcmd.mergeAllChunksOnShard"> <code class="leafygreen-ui-1l06pbn"> mergeAllChunksOnShard </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Squashes <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mergeAllChunksOnShard/#std-label-mergeability"> mergeable </a> chunks for a given collection on a shard. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mergeChunks/#mongodb-dbcommand-dbcmd.mergeChunks"> <code class="leafygreen-ui-1l06pbn"> mergeChunks </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Provides the ability to combine chunks on a single shard. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/refineCollectionShardKey/#mongodb-dbcommand-dbcmd.refineCollectionShardKey"> <code class="leafygreen-ui-1l06pbn"> refineCollectionShardKey </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Refines a collection's shard key by adding a suffix to the existing key. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/removeShard/#mongodb-dbcommand-dbcmd.removeShard"> <code class="leafygreen-ui-1l06pbn"> removeShard </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Starts the process of removing a shard from a sharded cluster. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/removeShardFromZone/#mongodb-dbcommand-dbcmd.removeShardFromZone"> <code class="leafygreen-ui-1l06pbn"> removeShardFromZone </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Removes the association between a shard and a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zone"> zone </a> . Supports configuring <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding"> zones </a> in sharded clusters. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/reshardCollection/#mongodb-dbcommand-dbcmd.reshardCollection"> <code class="leafygreen-ui-1l06pbn"> reshardCollection </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Initiates a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding"> resharding operation </a> to change the shard key for a collection, changing the distribution of your data. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setAllowMigrations/#mongodb-dbcommand-dbcmd.setAllowMigrations"> <code class="leafygreen-ui-1l06pbn"> setAllowMigrations </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Prevents the start of new <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration-automatic"> automatic migrations </a> on a collection, prevents in-flight <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration-manual"> manual migrations </a> from committing, and excludes the collection from new balancer rounds. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/shardCollection/#mongodb-dbcommand-dbcmd.shardCollection"> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enables the sharding functionality for a collection, allowing the collection to be sharded. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/shardingState/#mongodb-dbcommand-dbcmd.shardingState"> <code class="leafygreen-ui-1l06pbn"> shardingState </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Reports whether the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> is a member of a sharded cluster. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/split/#mongodb-dbcommand-dbcmd.split"> <code class="leafygreen-ui-1l06pbn"> split </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Creates a new <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk"> chunk <!-- --> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/transitionFromDedicatedConfigServer/#mongodb-dbcommand-dbcmd.transitionFromDedicatedConfigServer"> <code class="leafygreen-ui-1l06pbn"> transitionFromDedicatedConfigServer </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Configures a dedicated config server to run as a config shard. </p> <div> <p> <em> New <!-- --> in version <!-- --> 8.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/transitionToDedicatedConfigServer/#mongodb-dbcommand-dbcmd.transitionToDedicatedConfigServer"> <code class="leafygreen-ui-1l06pbn"> transitionToDedicatedConfigServer </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Configures a config shard to run as a dedicated config server. </p> <div> <p> <em> New <!-- --> in version <!-- --> 8.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/unsetSharding/#mongodb-dbcommand-dbcmd.unsetSharding"> <code class="leafygreen-ui-1l06pbn"> unsetSharding </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <em> Removed in MongoDB 5.0. </em> Internal command that affects connections between instances in a MongoDB deployment. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/unshardCollection/#mongodb-dbcommand-dbcmd.unshardCollection"> <code class="leafygreen-ui-1l06pbn"> unshardCollection </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Unshards an existing sharded collection and moves the collection data onto a single shard. When you unshard a collection, the collection cannot be partitioned across multiple <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard"> shards </a> and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> is removed. </p> <div> <p> <em> New <!-- --> in version <!-- --> 8.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange"> <code class="leafygreen-ui-1l06pbn"> updateZoneKeyRange </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Adds or removes the association between a range of sharded data and a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zone"> zone </a> . Supports configuring <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding"> zones </a> in sharded clusters. </div> </div> </td> </tr> </tbody> </table> </div> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $out (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-out--aggregation-" 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="-out--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behaviors" target="_self"> <span> Behaviors </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="pipeline"> <dt> <code class="leafygreen-ui-1l06pbn"> $out </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-pipeline-pipe.-out" title="Permalink to this definition"> <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="mongodb-pipeline-pipe.-out"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Takes the documents returned by the aggregation pipeline and writes them to a specified collection. You can specify the output database. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $out </code> stage must be <em> the last stage </em> in the pipeline. The <code class="leafygreen-ui-1l06pbn"> $out </code> operator lets the aggregation framework return result sets of any size. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> If the collection specified by the <code class="leafygreen-ui-1l06pbn"> $out </code> operation already exists, then the <code class="leafygreen-ui-1l06pbn"> $out </code> stage atomically replaces the existing collection with the new results collection upon completion of the aggregation. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replace-existing-collection" target="_self"> <span> Replace Existing Collection </span> </a> for details. </p> </div> </div> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $out </code> stage has the following syntax: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $out </code> can take a string to specify only the output collection (i.e. output to a collection in the same database): </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $out: \"&lt;output-collection&gt;\" } // Output collection is in the same database","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$out</span>: <span class="lg-highlight-string">"&lt;output-collection&gt;"</span> } <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Output collection is </span><span class="lg-highlight-comment">in the same database</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $out </code> can take a document to specify the output database as well as the output collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $out: { db: \"&lt;output-db&gt;\", coll: \"&lt;output-collection&gt;\" } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$out</span>: <!-- -->{ <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"&lt;output-db&gt;"</span>, <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"&lt;output-collection&gt;"</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 7.0.3 and 7.1, <code class="leafygreen-ui-1l06pbn"> $out </code> can take a document to output to a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-landing"> time series collection <!-- --> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $out:\n { db: \"&lt;output-db&gt;\", coll: \"&lt;output-collection&gt;\",\n timeseries: {\n timeField: \"&lt;field-name&gt;\",\n metaField: \"&lt;field-name&gt;\",\n granularity: \"seconds\" || \"minutes\" || \"hours\" ,\n }\n }\n}","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$out</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"&lt;output-db&gt;"</span>, <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"&lt;output-collection&gt;"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timeseries</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timeField</span>: <span class="lg-highlight-string">"&lt;field-name&gt;"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metaField</span>: <span class="lg-highlight-string">"&lt;field-name&gt;"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">granularity</span>: <span class="lg-highlight-string">"seconds"</span> <!-- -->|<!-- -->| <span class="lg-highlight-string">"minutes"</span> <!-- -->|<!-- -->| <span class="lg-highlight-string">"hours"</span> <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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 class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Changing Time Series Granularity </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> After creating a time series collection, you can modify its granularity using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collMod/#mongodb-dbcommand-dbcmd.collMod"> <code class="leafygreen-ui-1l06pbn"> collMod </code> </a> method. However, you can only increase the timespan covered by each bucket. You cannot decrease it. </p> </div> </div> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:15%"/> <col style="width:85%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> db </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-out-db"> </span> <p class="leafygreen-ui-1kp3ins"> The output database name. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For a <a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/#std-label-replica-set"> replica set </a> or a standalone, if the output database does not exist, <code class="leafygreen-ui-1l06pbn"> $out </code> also creates the database. </p> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> coll </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-out-collection"> </span> <p class="leafygreen-ui-1kp3ins"> The output collection name. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> timeseries </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-out-timeseries"> </span> <p class="leafygreen-ui-1kp3ins"> A document that specifies the configuration to use when writing to a time series collection. The <code class="leafygreen-ui-1l06pbn"> timeField </code> is required. All other fields are optional. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> timeField </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-out-timefield"> </span> <p class="leafygreen-ui-1kp3ins"> Required when writing to a time series collection. .. include:: /includes/time-series/fact-time-field-description.rst </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> metaField </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-out-metafield"> </span> <p class="leafygreen-ui-1kp3ins"> Optional. The name of the field which contains metadata in each time series document. The metadata in the specified field should be data that is used to label a unique series of documents. The metadata should rarely, if ever, change The name of the specified field may not be <code class="leafygreen-ui-1l06pbn"> _id </code> or the same as the <code class="leafygreen-ui-1l06pbn"> timeseries.timeField </code> . The field can be of any data type. </p> <p class="leafygreen-ui-1kp3ins"> Although the <code class="leafygreen-ui-1l06pbn"> metaField </code> field is optional, using metadata can improve query optimization. For example, MongoDB automatically <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-secondary-index/#std-label-timeseries-add-secondary-index"> creates a compound index </a> on the <code class="leafygreen-ui-1l06pbn"> metaField </code> and <code class="leafygreen-ui-1l06pbn"> timeField </code> fields for new collections. If you do not provide a value for this field, the data is bucketed solely based on time. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> granularity </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-out-granularity"> </span> <p class="leafygreen-ui-1kp3ins"> Optional. Do not use if setting <code class="leafygreen-ui-1l06pbn"> bucketRoundingSeconds </code> and <code class="leafygreen-ui-1l06pbn"> bucketMaxSpanSeconds </code> . </p> <p class="leafygreen-ui-1kp3ins"> Possible values are <code class="leafygreen-ui-1l06pbn"> seconds </code> (default), <code class="leafygreen-ui-1l06pbn"> minutes </code> , and <code class="leafygreen-ui-1l06pbn"> hours </code> . </p> <p class="leafygreen-ui-1kp3ins"> Set <code class="leafygreen-ui-1l06pbn"> granularity </code> to the value that most closely matches the time between consecutive incoming timestamps. This improves performance by optimizing how MongoDB stores data in the collection. </p> <p class="leafygreen-ui-1kp3ins"> For more information on granularity and bucket intervals, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-granularity/#std-label-timeseries-granularity"> Set Granularity for Time Series Data <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> bucketMaxSpanSeconds </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-out-bucketmaxspanseconds"> </span> <p class="leafygreen-ui-1kp3ins"> Optional. Use with <code class="leafygreen-ui-1l06pbn"> bucketRoundingSeconds </code> as an alternative to <code class="leafygreen-ui-1l06pbn"> granularity </code> . Sets the maximum time between timestamps in the same bucket. </p> <p class="leafygreen-ui-1kp3ins"> Possible values are 1-31536000. </p> <div> <p> <em> New <!-- --> in version <!-- --> 6.3 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> bucketRoundingSeconds </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-out-bucketroundingseconds"> </span> <p class="leafygreen-ui-1kp3ins"> Optional. Use with <code class="leafygreen-ui-1l06pbn"> bucketMaxSpanSeconds </code> as an alternative to <code class="leafygreen-ui-1l06pbn"> granularity </code> . Must be equal to <code class="leafygreen-ui-1l06pbn"> bucketMaxSpanSeconds </code> . </p> <p class="leafygreen-ui-1kp3ins"> When a document requires a new bucket, MongoDB rounds down the document's timestamp value by this interval to set the minimum time for the bucket. </p> <div> <p> <em> New <!-- --> in version <!-- --> 6.3 </em> . </p> </div> </div> </div> </td> </tr> </tbody> </table> </div> </li> </ul> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You cannot specify a sharded collection as the output collection. The input collection for a pipeline can be sharded. To output to a sharded collection, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $out </code> operator cannot write results to a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/capped-collections/#std-label-manual-capped-collection"> capped collection <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If you modify a collection with an <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self"> <span> Atlas Search </span> </a> index, you must first delete and then re-create the search index. Consider using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> instead. </p> </li> </ul> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-out-merge-comparison"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Comparison with <code class="leafygreen-ui-1l06pbn"> $merge </code> <a class="headerlink leafygreen-ui-1kepx47" href="#comparison-with--merge" 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="comparison-with--merge"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB provides two stages, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> and <code class="leafygreen-ui-1l06pbn"> $out </code> , for writing the results of the aggregation pipeline to a collection. The following summarizes the capabilities of the two stages: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <code class="leafygreen-ui-1l06pbn"> $out </code> </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Can output to a collection in the same or different database. </p> </li> </ul> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Can output to a collection in the same or different database. </p> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Creates a new collection if the output collection does not already exist. </p> </li> </ul> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Creates a new collection if the output collection does not already exist. </p> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Replaces the output collection completely if it already exists. </p> </li> </ul> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Can incorporate results (insert new documents, merge documents, replace documents, keep existing documents, fail the operation, process documents with a custom update pipeline) into an existing collection. </p> <p class="leafygreen-ui-1kp3ins"> Can replace the content of the collection but only if the aggregation results contain a match for all existing documents in the collection. </p> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Cannot output to a sharded collection. Input collection, however, can be sharded. </p> </li> </ul> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Can output to a sharded collection. Input collection can also be sharded. </p> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 7.0.3 and 7.1, can output to a time series collection. </p> </li> </ul> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Cannot output to a time series collection. </p> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Corresponds to the SQL statements: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"INSERT INTO T2 SELECT * FROM T1","programmingLanguage":"SQL"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" tabindex="0"><code class="lg-highlight-hljs-light sql leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">INSERT</span> <span class="lg-highlight-keyword">INTO</span> T2 <span class="lg-highlight-keyword">SELECT</span> <span class="lg-highlight-operator">*</span> <span class="lg-highlight-keyword">FROM</span> T1</td></tr></tbody></table></code></pre> </div> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"SELECT * INTO T2 FROM T1","programmingLanguage":"SQL"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" tabindex="0"><code class="lg-highlight-hljs-light sql leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">SELECT</span> <span class="lg-highlight-operator">*</span> <span class="lg-highlight-keyword">INTO</span> T2 <span class="lg-highlight-keyword">FROM</span> T1</td></tr></tbody></table></code></pre> </div> </div> </div> </li> </ul> </li> </ul> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Corresponds to the SQL statement: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MERGE T2 AS TARGET\nUSING (SELECT * FROM T1) AS SOURCE\nON MATCH (T2.ID = SOURCE.ID)\nWHEN MATCHED THEN\n UPDATE SET TARGET.FIELDX = SOURCE.FIELDY\nWHEN NOT MATCHED THEN\n INSERT (FIELDX)\n VALUES (SOURCE.FIELDY)","programmingLanguage":"SQL"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light sql leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">MERGE</span> T2 <span class="lg-highlight-keyword">AS</span> TARGET</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">USING</span> (<span class="lg-highlight-keyword">SELECT</span> <span class="lg-highlight-operator">*</span> <span class="lg-highlight-keyword">FROM</span> T1) <span class="lg-highlight-keyword">AS</span> SOURCE</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">ON</span> <span class="lg-highlight-keyword">MATCH</span> (T2.ID <span class="lg-highlight-operator">=</span> SOURCE.ID)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">WHEN</span> MATCHED <span class="lg-highlight-keyword">THEN</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">UPDATE</span> <span class="lg-highlight-keyword">SET</span> TARGET.FIELDX <span class="lg-highlight-operator">=</span> SOURCE.FIELDY</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">WHEN</span> <span class="lg-highlight-keyword">NOT</span> MATCHED <span class="lg-highlight-keyword">THEN</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">INSERT</span> (FIELDX)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">VALUES</span> (SOURCE.FIELDY)</td></tr></tbody></table></code></pre> </div> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create/Refresh Materialized Views </p> </li> </ul> </li> </ul> </div> </div> </td> </tr> </tbody> </table> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behaviors <a class="headerlink leafygreen-ui-1kepx47" href="#behaviors" 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="behaviors"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> $out Read Operations Run on Secondary Replica Set Members <a class="headerlink leafygreen-ui-1kepx47" href="#-out-read-operations-run-on-secondary-replica-set-members" 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="-out-read-operations-run-on-secondary-replica-set-members"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, <code class="leafygreen-ui-1l06pbn"> $out </code> can run on replica set secondary nodes if all the nodes in cluster have <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv"> featureCompatibilityVersion </a> set to <code class="leafygreen-ui-1l06pbn"> 5.0 </code> or higher and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/"> Read Preference </a> is set to secondary. </p> <p class="leafygreen-ui-1kp3ins"> Read operations of the <code class="leafygreen-ui-1l06pbn"> $out </code> statement occur on the secondary nodes, while the write operations occur only on the primary nodes. </p> <p class="leafygreen-ui-1kp3ins"> Not all driver versions support targeting of <code class="leafygreen-ui-1l06pbn"> $out </code> operations to replica set secondary nodes. Check your <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> driver </span> </a> documentation to see when your driver added support for <code class="leafygreen-ui-1l06pbn"> $out </code> running on a secondary. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create New Collection <a class="headerlink leafygreen-ui-1kepx47" href="#create-new-collection" 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-new-collection"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $out </code> operation creates a new collection if one does not already exist. </p> <p class="leafygreen-ui-1kp3ins"> The collection is not visible until the aggregation completes. If the aggregation fails, MongoDB does not create the collection. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-replace-existing-collection"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Replace Existing Collection <a class="headerlink leafygreen-ui-1kepx47" href="#replace-existing-collection" 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="replace-existing-collection"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If the collection specified by the <code class="leafygreen-ui-1l06pbn"> $out </code> operation already exists, then upon completion of the aggregation, the <code class="leafygreen-ui-1l06pbn"> $out </code> stage atomically replaces the existing collection with the new results collection. Specifically, the <code class="leafygreen-ui-1l06pbn"> $out </code> operation: </p> <ol class="leafygreen-ui-rioki0" type="1"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Creates a temp collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Copies the indexes from the existing collection to the temp collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Inserts the documents into the temp collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Calls the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/renameCollection/#mongodb-dbcommand-dbcmd.renameCollection"> <code class="leafygreen-ui-1l06pbn"> renameCollection </code> </a> command with <code class="leafygreen-ui-1l06pbn"> dropTarget: true </code> to rename the temp collection to the destination collection. </p> </li> </ol> <p class="leafygreen-ui-1kp3ins"> If specified collection exists and the <code class="leafygreen-ui-1l06pbn"> $out </code> operation specifies <code class="leafygreen-ui-1l06pbn"> timeseries </code> options, then the following restrictions apply: </p> <ol class="leafygreen-ui-rioki0" type="1"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The existing collection must be a time series collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The existing collection must not be a view. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> timeseries </code> options included in the <code class="leafygreen-ui-1l06pbn"> $out </code> stage must exactly match those on the existing collection. </p> </li> </ol> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $out </code> operation does not change any indexes that existed on the previous collection. If the aggregation fails, the <code class="leafygreen-ui-1l06pbn"> $out </code> operation makes no changes to the pre-existing collection. </p> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Schema Validation Errors <a class="headerlink leafygreen-ui-1kepx47" href="#schema-validation-errors" 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="schema-validation-errors"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> If your <code class="leafygreen-ui-1l06pbn"> coll </code> collection uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/schema-validation/#std-label-schema-validation-overview"> schema validation </a> and has <code class="leafygreen-ui-1l06pbn"> validationAction </code> set to <code class="leafygreen-ui-1l06pbn"> error </code> , inserting an invalid document with <code class="leafygreen-ui-1l06pbn"> $out </code> throws an error. The <code class="leafygreen-ui-1l06pbn"> $out </code> operation makes no changes to the pre-existing collection and documents returned by the aggregation pipeline are not added to the <code class="leafygreen-ui-1l06pbn"> coll </code> collection. </p> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Index Constraints <a class="headerlink leafygreen-ui-1kepx47" href="#index-constraints" 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="index-constraints"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The pipeline will fail to complete if the documents produced by the pipeline would violate any unique indexes, including the index on the <code class="leafygreen-ui-1l06pbn"> _id </code> field of the original output collection. </p> <p class="leafygreen-ui-1kp3ins"> If the <code class="leafygreen-ui-1l06pbn"> $out </code> operation modifies a collection with an <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self"> <span> Atlas Search </span> </a> index, you must delete and re-create the search index. Consider using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> instead. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> majority </code> Read Concern <a class="headerlink leafygreen-ui-1kepx47" href="#majority-read-concern" 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="majority-read-concern"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> You can specify <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/#std-label-read-concern"> read concern </a> level <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> for an aggregation that includes an <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-out" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $out </code> </span> </a> stage. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Interaction with <code class="leafygreen-ui-1l06pbn"> mongodump </code> <a class="headerlink leafygreen-ui-1kepx47" href="#interaction-with-mongodump" 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="interaction-with-mongodump"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> A <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongodump/#mongodb-binary-bin.mongodump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongodump </code> </span> </a> started with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongodump/#std-option-mongodump.--oplog" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --oplog </code> </span> </a> fails if a client issues an aggregation pipeline that includes <code class="leafygreen-ui-1l06pbn"> $out </code> during the dump process. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongodump/#std-option-mongodump.--oplog" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongodump --oplog </code> </span> </a> for more information. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Restrictions <a class="headerlink leafygreen-ui-1kepx47" href="#restrictions" 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="restrictions"> </div> </a> </h3> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Restrictions </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> transactions </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An aggregation pipeline cannot use <code class="leafygreen-ui-1l06pbn"> $out </code> inside <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> transactions <!-- --> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page"> view definition </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The <code class="leafygreen-ui-1l06pbn"> $out </code> stage is not allowed as part of a view definition. If the view definition includes nested pipeline (e.g. the view definition includes <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup"> <code class="leafygreen-ui-1l06pbn"> $lookup </code> </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/facet/#mongodb-pipeline-pipe.-facet"> <code class="leafygreen-ui-1l06pbn"> $facet </code> </a> stage), this <code class="leafygreen-ui-1l06pbn"> $out </code> stage restriction applies to the nested pipelines as well. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup"> <code class="leafygreen-ui-1l06pbn"> $lookup </code> </a> stage </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> You can't include the <code class="leafygreen-ui-1l06pbn"> $out </code> stage in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup"> <code class="leafygreen-ui-1l06pbn"> $lookup </code> </a> stage's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#std-label-lookup-syntax-let-pipeline"> nested pipeline <!-- --> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/facet/#mongodb-pipeline-pipe.-facet"> <code class="leafygreen-ui-1l06pbn"> $facet </code> </a> stage </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/facet/#mongodb-pipeline-pipe.-facet"> <code class="leafygreen-ui-1l06pbn"> $facet </code> </a> stage's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#std-label-lookup-syntax-let-pipeline"> nested pipeline </a> cannot include the <code class="leafygreen-ui-1l06pbn"> $out </code> stage. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unionWith/#mongodb-pipeline-pipe.-unionWith"> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </a> stage </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unionWith/#mongodb-pipeline-pipe.-unionWith"> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </a> stage's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unionWith/#std-label-unionWith-pipeline"> nested pipeline </a> cannot include the <code class="leafygreen-ui-1l06pbn"> $out </code> stage. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-"> <code class="leafygreen-ui-1l06pbn"> "linearizable" </code> </a> read concern </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-out" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $out </code> </span> </a> stage cannot be used in conjunction with read concern <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-"> <code class="leafygreen-ui-1l06pbn"> "linearizable" </code> </a> . If you specify <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-"> <code class="leafygreen-ui-1l06pbn"> "linearizable" </code> </a> read concern for <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> , you cannot include the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-out" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $out </code> </span> </a> stage in the pipeline. </p> </div> </div> </td> </tr> </tbody> </table> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> In the <code class="leafygreen-ui-1l06pbn"> test </code> database, create a collection <code class="leafygreen-ui-1l06pbn"> books </code> with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"test\").books.insertMany([\n { \"_id\" : 8751, \"title\" : \"The Banquet\", \"author\" : \"Dante\", \"copies\" : 2 },\n { \"_id\" : 8752, \"title\" : \"Divine Comedy\", \"author\" : \"Dante\", \"copies\" : 1 },\n { \"_id\" : 8645, \"title\" : \"Eclogues\", \"author\" : \"Dante\", \"copies\" : 2 },\n { \"_id\" : 7000, \"title\" : \"The Odyssey\", \"author\" : \"Homer\", \"copies\" : 10 },\n { \"_id\" : 7020, \"title\" : \"Iliad\", \"author\" : \"Homer\", \"copies\" : 10 }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"test"</span>).<span class="lg-highlight-property">books</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">"_id"</span> <!-- -->: <span class="lg-highlight-number">8751</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"The Banquet"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <span class="lg-highlight-string">"Dante"</span>, <span class="lg-highlight-string">"copies"</span> <!-- -->: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">8752</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"Divine Comedy"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <span class="lg-highlight-string">"Dante"</span>, <span class="lg-highlight-string">"copies"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">8645</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"Eclogues"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <span class="lg-highlight-string">"Dante"</span>, <span class="lg-highlight-string">"copies"</span> <!-- -->: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">7000</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"The Odyssey"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <span class="lg-highlight-string">"Homer"</span>, <span class="lg-highlight-string">"copies"</span> <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">7020</span>, <span class="lg-highlight-string">"title"</span> <!-- -->: <span class="lg-highlight-string">"Iliad"</span>, <span class="lg-highlight-string">"author"</span> <!-- -->: <span class="lg-highlight-string">"Homer"</span>, <span class="lg-highlight-string">"copies"</span> <!-- -->: <span class="lg-highlight-number">10</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> <p class="leafygreen-ui-1kp3ins"> If the <code class="leafygreen-ui-1l06pbn"> test </code> database does not already exist, the insert operation creates the database as well as the <code class="leafygreen-ui-1l06pbn"> books </code> collection. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Output to Same Database <a class="headerlink leafygreen-ui-1kepx47" href="#output-to-same-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="output-to-same-database"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation pivots the data in the <code class="leafygreen-ui-1l06pbn"> books </code> collection in the <code class="leafygreen-ui-1l06pbn"> test </code> database to have titles grouped by authors and then writes the results to the <code class="leafygreen-ui-1l06pbn"> authors </code> collection, also in the <code class="leafygreen-ui-1l06pbn"> test </code> database. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"test\").books.aggregate( [\n { $group : { _id : \"$author\", books: { $push: \"$title\" } } },\n { $out : \"authors\" }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"test"</span>).<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$group<!-- --> <!-- -->: <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-string">"$author"</span>, <span class="lg-highlight-attr">books</span>: <!-- -->{ <span class="lg-highlight-attr">$push</span>: <span class="lg-highlight-string">"$title"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$out<!-- --> <!-- -->: <span class="lg-highlight-string">"authors"</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> <dl> <dt> First Stage ( <code class="leafygreen-ui-1l06pbn"> $group </code> ): </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage groups by the <code class="leafygreen-ui-1l06pbn"> authors </code> and uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/push/#mongodb-group-grp.-push"> <code class="leafygreen-ui-1l06pbn"> $push </code> </a> to add the titles to a <code class="leafygreen-ui-1l06pbn"> books </code> array field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"Dante\", \"books\" : [ \"The Banquet\", \"Divine Comedy\", \"Eclogues\" ] }\n{ \"_id\" : \"Homer\", \"books\" : [ \"The Odyssey\", \"Iliad\" ] }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Dante"</span>, <span class="lg-highlight-string">"books"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"The Banquet"</span>, <span class="lg-highlight-string">"Divine Comedy"</span>, <span class="lg-highlight-string">"Eclogues"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Homer"</span>, <span class="lg-highlight-string">"books"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"The Odyssey"</span>, <span class="lg-highlight-string">"Iliad"</span> ] }</td></tr></tbody></table></code></pre> </div> </div> </div> </dd> <dt> Second Stage ( <code class="leafygreen-ui-1l06pbn"> $out </code> ): </dt> <dd class="css-1ufxuu7"> The <code class="leafygreen-ui-1l06pbn"> $out </code> stage outputs the documents to the <code class="leafygreen-ui-1l06pbn"> authors </code> collection in the <code class="leafygreen-ui-1l06pbn"> test </code> database. </dd> </dl> <p class="leafygreen-ui-1kp3ins"> To view the documents in the output collection, run the following operation: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"test\").authors.find()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"test"</span>).<span class="lg-highlight-property">authors</span>.<span class="lg-highlight-title lg-highlight-function">find</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> <p class="leafygreen-ui-1kp3ins"> The collection contains the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"Homer\", \"books\" : [ \"The Odyssey\", \"Iliad\" ] }\n{ \"_id\" : \"Dante\", \"books\" : [ \"The Banquet\", \"Divine Comedy\", \"Eclogues\" ] }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Homer"</span>, <span class="lg-highlight-string">"books"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"The Odyssey"</span>, <span class="lg-highlight-string">"Iliad"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Dante"</span>, <span class="lg-highlight-string">"books"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"The Banquet"</span>, <span class="lg-highlight-string">"Divine Comedy"</span>, <span class="lg-highlight-string">"Eclogues"</span> ] }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Output to a Different Database <a class="headerlink leafygreen-ui-1kepx47" href="#output-to-a-different-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="output-to-a-different-database"> </div> </a> </h3> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> For a <a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/#std-label-replica-set"> replica set </a> or a standalone, if the output database does not exist, <code class="leafygreen-ui-1l06pbn"> $out </code> also creates the database. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $out </code> can output to a collection in a database different from where the aggregation is run. </p> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation pivots the data in the <code class="leafygreen-ui-1l06pbn"> books </code> collection to have titles grouped by authors and then writes the results to the <code class="leafygreen-ui-1l06pbn"> authors </code> collection in the <code class="leafygreen-ui-1l06pbn"> reporting </code> database: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"test\").books.aggregate( [\n { $group : { _id : \"$author\", books: { $push: \"$title\" } } },\n { $out : { db: \"reporting\", coll: \"authors\" } }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"test"</span>).<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$group<!-- --> <!-- -->: <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-string">"$author"</span>, <span class="lg-highlight-attr">books</span>: <!-- -->{ <span class="lg-highlight-attr">$push</span>: <span class="lg-highlight-string">"$title"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$out<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"reporting"</span>, <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"authors"</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> <dl> <dt> First Stage ( <code class="leafygreen-ui-1l06pbn"> $group </code> ): </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage groups by the <code class="leafygreen-ui-1l06pbn"> authors </code> and uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/push/#mongodb-group-grp.-push"> <code class="leafygreen-ui-1l06pbn"> $push </code> </a> to add the titles to a <code class="leafygreen-ui-1l06pbn"> books </code> array field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"Dante\", \"books\" : [ \"The Banquet\", \"Divine Comedy\", \"Eclogues\" ] }\n{ \"_id\" : \"Homer\", \"books\" : [ \"The Odyssey\", \"Iliad\" ] }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Dante"</span>, <span class="lg-highlight-string">"books"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"The Banquet"</span>, <span class="lg-highlight-string">"Divine Comedy"</span>, <span class="lg-highlight-string">"Eclogues"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Homer"</span>, <span class="lg-highlight-string">"books"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"The Odyssey"</span>, <span class="lg-highlight-string">"Iliad"</span> ] }</td></tr></tbody></table></code></pre> </div> </div> </div> </dd> <dt> Second Stage ( <code class="leafygreen-ui-1l06pbn"> $out </code> ): </dt> <dd class="css-1ufxuu7"> The <code class="leafygreen-ui-1l06pbn"> $out </code> stage outputs the documents to the <code class="leafygreen-ui-1l06pbn"> authors </code> collection in the <code class="leafygreen-ui-1l06pbn"> reporting </code> database. </dd> </dl> <p class="leafygreen-ui-1kp3ins"> To view the documents in the output collection, run the following operation: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"reporting\").authors.find()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"reporting"</span>).<span class="lg-highlight-property">authors</span>.<span class="lg-highlight-title lg-highlight-function">find</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> <p class="leafygreen-ui-1kp3ins"> The collection contains the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"Homer\", \"books\" : [ \"The Odyssey\", \"Iliad\" ] }\n{ \"_id\" : \"Dante\", \"books\" : [ \"The Banquet\", \"Divine Comedy\", \"Eclogues\" ] }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Homer"</span>, <span class="lg-highlight-string">"books"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"The Odyssey"</span>, <span class="lg-highlight-string">"Iliad"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Dante"</span>, <span class="lg-highlight-string">"books"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"The Banquet"</span>, <span class="lg-highlight-string">"Divine Comedy"</span>, <span class="lg-highlight-string">"Eclogues"</span> ] }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/geoSearch/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> geoSearch <a class="headerlink leafygreen-ui-1kepx47" href="#geosearch" 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="geosearch"> </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="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <dl class="dbcommand"> <dt> <code class="leafygreen-ui-1l06pbn"> geoSearch </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.geoSearch" title="Permalink to this definition"> <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="mongodb-dbcommand-dbcmd.geoSearch"> </div> </a> </dt> <dd> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Removed in MongoDB 5.0 </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> MongoDB 5.0 removes the deprecated <code class="leafygreen-ui-1l06pbn"> geoHaystack </code> index and <code class="leafygreen-ui-1l06pbn"> geoSearch </code> command. Use a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index"> 2d index </a> with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear"> <code class="leafygreen-ui-1l06pbn"> $geoNear </code> </a> or one of the supported <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query-geospatial/#std-label-geospatial-query-selectors"> geospatial query operators </a> instead. </p> <p class="leafygreen-ui-1kp3ins"> Upgrading your MongoDB instance to 5.0 and setting <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv"> featureCompatibilityVersion </a> to <code class="leafygreen-ui-1l06pbn"> 5.0 </code> will delete any pre-existing <code class="leafygreen-ui-1l06pbn"> geoHaystack </code> indexes. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.geoSearch" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> geoSearch </code> </span> </a> command provides an interface to MongoDB's haystack index functionality. These indexes are useful for returning results based on location coordinates <em> after </em> collecting results based on some other query (i.e. a "haystack.") </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.geoSearch" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> geoSearch </code> </span> </a> command accepts a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-document"> document </a> that contains the following fields. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> geoSearch </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The collection to query. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> search </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Query to filter documents. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> near </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> array </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Coordinates of a point. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> maxDistance </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> number </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Optional. Maximum distance from the specified point. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> limit </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> number </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Optional. Maximum number of documents to return. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> readConcern </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. Specifies the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-read-concern"> read concern <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> readConcern </code> option has the following syntax: <code class="leafygreen-ui-1l06pbn"> readConcern: { level: &lt;value&gt; } </code> </p> <p class="leafygreen-ui-1kp3ins"> Possible read concern levels are: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-"> <code class="leafygreen-ui-1l06pbn"> "local" </code> </a> . This is the default read concern level for read operations against the primary and secondaries. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-"> <code class="leafygreen-ui-1l06pbn"> "available" </code> </a> . Available for read operations against the primary and secondaries. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-"> <code class="leafygreen-ui-1l06pbn"> "available" </code> </a> behaves the same as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-"> <code class="leafygreen-ui-1l06pbn"> "local" </code> </a> against the primary and non-sharded secondaries. The query returns the instance's most recent data. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> . Available for replica sets that use <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger"> WiredTiger storage engine <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-"> <code class="leafygreen-ui-1l06pbn"> "linearizable" </code> </a> . Available for read operations on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY"> <code class="leafygreen-ui-1l06pbn"> primary </code> </a> only. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For more formation on the read concern levels, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/#std-label-read-concern-levels"> Read Concern Levels <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> For more information on the read concern levels, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/#std-label-read-concern-levels"> Read Concern Levels <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> comment </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> any </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref"> mongod log messages </a> , in the <code class="leafygreen-ui-1l06pbn"> attr.command.cursor.comment </code> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler"> Database profiler </a> output, in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#mongodb-data-system.profile.command"> <code class="leafygreen-ui-1l06pbn"> command.comment </code> </a> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp"> <code class="leafygreen-ui-1l06pbn"> currentOp </code> </a> output, in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.command"> <code class="leafygreen-ui-1l06pbn"> command.comment </code> </a> field. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> A comment can be any valid <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types"> BSON type </a> (string, integer, object, array, etc). </p> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This command is available in deployments hosted 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> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command is not supported in serverless instances. For more information, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self"> <span> Unsupported Commands <!-- --> . </span> </a> </p> </div> </div> <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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Limit <a class="headerlink leafygreen-ui-1kepx47" href="#limit" 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="limit"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Unless specified otherwise, the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.geoSearch" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> geoSearch </code> </span> </a> command limits results to 50 documents. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Sharded Clusters <a class="headerlink leafygreen-ui-1kepx47" href="#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="sharded-clusters"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.geoSearch" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> geoSearch </code> </span> </a> is not supported for sharded clusters. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" 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> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.geoSearch" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> geoSearch </code> </span> </a> can be used inside <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> distributed transactions <!-- --> . </a> </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> In most cases, a distributed transaction incurs a greater performance cost over single document writes, and the availability of distributed transactions should not be a replacement for effective schema design. For many scenarios, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding"> denormalized data model (embedded documents and arrays) </a> will continue to be optimal for your data and use cases. That is, for many scenarios, modeling your data appropriately will minimize the need for distributed transactions. </p> <p class="leafygreen-ui-1kp3ins"> For additional transactions usage considerations (such as runtime limit and oplog size limit), see also <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-production-consideration/#std-label-production-considerations"> Production Considerations <!-- --> . </a> </p> </div> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Consider the following example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand({\n geoSearch : \"places\",\n near: [ -73.9667, 40.78 ],\n maxDistance : 6,\n search : { type : \"restaurant\" },\n limit : 30\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->geoSearch <!-- -->: <span class="lg-highlight-string">"places"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">near</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.9667</span>, <span class="lg-highlight-number">40.78</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->maxDistance <!-- -->: <span class="lg-highlight-number">6</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->search <!-- -->: <!-- -->{ <!-- -->type <!-- -->: <span class="lg-highlight-string">"restaurant"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->limit <!-- -->: <span class="lg-highlight-number">30</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> <p class="leafygreen-ui-1kp3ins"> The above command returns all documents with a <code class="leafygreen-ui-1l06pbn"> type </code> of <code class="leafygreen-ui-1l06pbn"> restaurant </code> having a maximum distance of 6 units from the coordinates <code class="leafygreen-ui-1l06pbn"> [ -73.9667, 40.78 ] </code> in the collection <code class="leafygreen-ui-1l06pbn"> places </code> up to a maximum of 30 results. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Override Default Read Concern <a class="headerlink leafygreen-ui-1kepx47" href="#override-default-read-concern" 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="override-default-read-concern"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To override the default read concern level of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-"> <code class="leafygreen-ui-1l06pbn"> "local" </code> </a> , use the <code class="leafygreen-ui-1l06pbn"> readConcern </code> option. </p> <p class="leafygreen-ui-1kp3ins"> The following operation on a replica set specifies a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/"> Read Concern </a> of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> to read the most recent copy of the data confirmed as having been written to a majority of the nodes. </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"> Regardless of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-read-concern"> read concern </a> level, the most recent data on a node may not reflect the most recent version of the data in the system. </p> </div> </div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n geoSearch: \"places\",\n near: [ -73.9667, 40.78 ],\n search : { type : \"restaurant\" },\n readConcern: { level: \"majority\" }\n }\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">geoSearch</span>: <span class="lg-highlight-string">"places"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">near</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.9667</span>, <span class="lg-highlight-number">40.78</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->search <!-- -->: <!-- -->{ <!-- -->type <!-- -->: <span class="lg-highlight-string">"restaurant"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">readConcern</span>: <!-- -->{ <span class="lg-highlight-attr">level</span>: <span class="lg-highlight-string">"majority"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> To ensure that a single thread can read its own writes, use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> read concern and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> write concern against the primary of the replica set. </p> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/insert/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> insert <a class="headerlink leafygreen-ui-1kepx47" href="#insert" 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"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self"> <span> Command Fields </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#output" target="_self"> <span> Output </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="dbcommand"> <dt> <code class="leafygreen-ui-1l06pbn"> insert </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.insert" title="Permalink to this definition"> <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="mongodb-dbcommand-dbcmd.insert"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.insert" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insert </code> </span> </a> command inserts one or more documents and returns a document containing the status of all inserts. The insert methods provided by the MongoDB drivers use this command internally. </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"> In <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongosh </code> </span> </a> , this command can also be run through the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.insertOne/#mongodb-method-db.collection.insertOne"> <code class="leafygreen-ui-1l06pbn"> db.collection.insertOne() </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.insertMany/#mongodb-method-db.collection.insertMany"> <code class="leafygreen-ui-1l06pbn"> db.collection.insertMany() </code> </a> helper methods <!-- --> . </p> <p class="leafygreen-ui-1kp3ins"> Helper methods are convenient for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongosh </code> </span> </a> users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command. </p> </div> </div> <table class="css-11h39yh e1nex8bq0"> <colgroup> <col class="field-name"/> <col class="field-body"/> </colgroup> <tbody> <tr class="css-x8snli"> <th> Returns <!-- --> : </th> <td> A document that contains the status of the operation. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-insert-command-output" target="_self"> <span> Output </span> </a> for details. </td> </tr> </tbody> </table> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This command is available in deployments hosted 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> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self"> <span> Unsupported Commands <!-- --> . </span> </a> </p> </div> </div> <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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n insert: &lt;collection&gt;,\n documents: [ &lt;document&gt;, &lt;document&gt;, &lt;document&gt;, ... ],\n ordered: &lt;boolean&gt;,\n maxTimeMS: &lt;integer&gt;,\n writeConcern: { &lt;write&gt; },\n bypassDocumentValidation: &lt;boolean&gt;,\n comment: &lt;any&gt;\n }\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insert</span>: &lt;<!-- -->collection<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">documents</span>: <!-- -->[ &lt;<span class="lg-highlight-variable lg-highlight-language">document</span>&gt;<!-- -->,<!-- --> <!-- -->&lt;<span class="lg-highlight-variable lg-highlight-language">document</span>&gt;<!-- -->,<!-- --> <!-- -->&lt;<span class="lg-highlight-variable lg-highlight-language">document</span>&gt;<!-- -->,<!-- --> <!-- -->...<!-- --> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ordered</span>: &lt;<!-- -->boolean<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">maxTimeMS</span>: &lt;<!-- -->integer<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">writeConcern</span>: <!-- -->{ <!-- -->&lt;write concern&gt; },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> bypassDocumentValidation: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> comment: &lt;any&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Command Fields <a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" 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="command-fields"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command takes the following fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> insert </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The name of the target collection. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> documents </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> array </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An array of one or more documents to insert into the named collection. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> ordered </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Optional. If <code class="leafygreen-ui-1l06pbn"> true </code> , then when an insert of a document fails, return without inserting any remaining documents listed in the <code class="leafygreen-ui-1l06pbn"> inserts </code> array. If <code class="leafygreen-ui-1l06pbn"> false </code> , then when an insert of a document fails, continue to insert the remaining documents. Defaults to <code class="leafygreen-ui-1l06pbn"> true </code> . </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> maxTimeMS </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> non-negative integer </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. </p> <p class="leafygreen-ui-1kp3ins"> Specifies a time limit in milliseconds. If you do not specify a value for <code class="leafygreen-ui-1l06pbn"> maxTimeMS </code> , operations will not time out. A value of <code class="leafygreen-ui-1l06pbn"> 0 </code> explicitly specifies the default unbounded behavior. </p> <p class="leafygreen-ui-1kp3ins"> MongoDB terminates operations that exceed their allotted time limit using the same mechanism as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.killOp/#mongodb-method-db.killOp"> <code class="leafygreen-ui-1l06pbn"> db.killOp() </code> </a> . MongoDB only terminates an operation at one of its designated <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-interrupt-point"> interrupt points <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> writeConcern </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A document that expresses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern"> write concern </a> of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.insert" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insert </code> </span> </a> command. Omit to use the default write concern. </p> <p class="leafygreen-ui-1kp3ins"> Do not explicitly set the write concern for the operation if run in a transaction. To use write concern with transactions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern"> Transactions and Write Concern <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Optional. Enables <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.insert" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insert </code> </span> </a> to bypass document validation during the operation. This lets you insert documents that do not meet the validation requirements. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> comment </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> any </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref"> mongod log messages </a> , in the <code class="leafygreen-ui-1l06pbn"> attr.command.cursor.comment </code> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler"> Database profiler </a> output, in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#mongodb-data-system.profile.command"> <code class="leafygreen-ui-1l06pbn"> command.comment </code> </a> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp"> <code class="leafygreen-ui-1l06pbn"> currentOp </code> </a> output, in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.command"> <code class="leafygreen-ui-1l06pbn"> command.comment </code> </a> field. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> A comment can be any valid <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types"> BSON type </a> (string, integer, object, array, etc). </p> </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Size Limit <a class="headerlink leafygreen-ui-1kepx47" href="#size-limit" 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="size-limit"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The total size of all the <code class="leafygreen-ui-1l06pbn"> documents </code> array elements must be less than or equal to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#mongodb-limit-BSON-Document-Size"> maximum BSON document size <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> The total number of documents in the <code class="leafygreen-ui-1l06pbn"> documents </code> array must be less than or equal to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#mongodb-limit-Write-Command-Batch-Limit-Size"> maximum bulk size <!-- --> . </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Document Validation <a class="headerlink leafygreen-ui-1kepx47" href="#document-validation" 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="document-validation"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.insert" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insert </code> </span> </a> command adds support for the <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation </code> option, which lets you bypass <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/schema-validation/#std-label-schema-validation-overview"> document validation </a> when inserting or updating documents in a collection with validation rules. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" 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> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.insert" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insert </code> </span> </a> can be used inside <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> distributed transactions <!-- --> . </a> </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> In most cases, a distributed transaction incurs a greater performance cost over single document writes, and the availability of distributed transactions should not be a replacement for effective schema design. For many scenarios, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding"> denormalized data model (embedded documents and arrays) </a> will continue to be optimal for your data and use cases. That is, for many scenarios, modeling your data appropriately will minimize the need for distributed transactions. </p> <p class="leafygreen-ui-1kp3ins"> For additional transactions usage considerations (such as runtime limit and oplog size limit), see also <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-production-consideration/#std-label-production-considerations"> Production Considerations <!-- --> . </a> </p> </div> </div> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Collection Creation in Transactions <a class="headerlink leafygreen-ui-1kepx47" href="#collection-creation-in-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="collection-creation-in-transactions"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can create collections and indexes inside a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-create-collections-indexes"> distributed transaction </a> if the transaction is <strong class="css-4dei7l"> not </strong> a cross-shard write transaction. </p> <p class="leafygreen-ui-1kp3ins"> If you specify an insert on a non-existing collection in a transaction, MongoDB creates the collection implicitly. </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/transactions/#std-label-transactions-create-collections-indexes"> Create Collections and Indexes in a Transaction </a> </p> </div> </div> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Write Concerns and Transactions <a class="headerlink leafygreen-ui-1kepx47" href="#write-concerns-and-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="write-concerns-and-transactions"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Do not explicitly set the write concern for the operation if run in a transaction. To use write concern with transactions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern"> Transactions and Write Concern <!-- --> . </a> </p> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Insert Inaccuracies <a class="headerlink leafygreen-ui-1kepx47" href="#insert-inaccuracies" 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-inaccuracies"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Even if you encounter a server error during an insert, some documents may have been inserted. </p> <p class="leafygreen-ui-1kp3ins"> After a successful insert, the system returns <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-insert.n" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insert.n </code> </span> </a> , the number of documents inserted into the collection. If the insert operation is interrupted by a replica set state change, the system may continue inserting documents. As a result, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-insert.n" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insert.n </code> </span> </a> may report fewer documents than actually inserted. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Insert a Single Document <a class="headerlink leafygreen-ui-1kepx47" href="#insert-a-single-document" 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-a-single-document"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Insert a document into the <code class="leafygreen-ui-1l06pbn"> users </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n insert: \"users\",\n documents: [ { _id: 1, user: \"abc123\", status: \"A\" } ]\n }\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insert</span>: <span class="lg-highlight-string">"users"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">documents</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"abc123"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"A"</span> } ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The returned document shows that the command successfully inserted a document. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-insert-command-output" target="_self"> <span> Output </span> </a> for details. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"ok\" : 1, \"n\" : 1 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-string">"ok"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-number">1</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Bulk Insert <a class="headerlink leafygreen-ui-1kepx47" href="#bulk-insert" 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="bulk-insert"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Insert three documents into the <code class="leafygreen-ui-1l06pbn"> users </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n insert: \"users\",\n documents: [\n { _id: 2, user: \"ijk123\", status: \"A\" },\n { _id: 3, user: \"xyz123\", status: \"P\" },\n { _id: 4, user: \"mop123\", status: \"P\" }\n ],\n ordered: false,\n writeConcern: { w: \"majority\", wtimeout: 5000 }\n }\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insert</span>: <span class="lg-highlight-string">"users"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">documents</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"ijk123"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"A"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"xyz123"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"P"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"mop123"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"P"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ordered</span>: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">writeConcern</span>: <!-- -->{ <span class="lg-highlight-attr">w</span>: <span class="lg-highlight-string">"majority"</span>, <span class="lg-highlight-attr">wtimeout</span>: <span class="lg-highlight-number">5000</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The returned document shows that the command successfully inserted the three documents. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-insert-command-output" target="_self"> <span> Output </span> </a> for details. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"ok\" : 1, \"n\" : 3 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-string">"ok"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-number">3</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Using Insert with <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation </code> <a class="headerlink leafygreen-ui-1kepx47" href="#using-insert-with-bypassdocumentvalidation" 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="using-insert-with-bypassdocumentvalidation"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/schema-validation/#std-label-schema-validation-overview"> schema validation validationActions </a> are set to <code class="leafygreen-ui-1l06pbn"> error </code> , inserts to a collection return errors for documents that violate the schema validation rules. To insert documents which would violate these rules set <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation: true </code> . </p> <p class="leafygreen-ui-1kp3ins"> Create the <code class="leafygreen-ui-1l06pbn"> user </code> collection with a validation rule on the <code class="leafygreen-ui-1l06pbn"> status </code> fields. </p> <p class="leafygreen-ui-1kp3ins"> The validation rule validates that the status must be "Unknown" or "Incomplete": </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.createCollection(\"users\", {\n validator:\n {\n status: {\n $in: [ \"Unknown\", \"Incomplete\" ]\n }\n }\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">db.<span class="lg-highlight-title lg-highlight-function">createCollection</span>(<span class="lg-highlight-string">"users"</span>, <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">validator</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">status</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$in</span>: <!-- -->[ <span class="lg-highlight-string">"Unknown"</span>, <span class="lg-highlight-string">"Incomplete"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> Attempt to insert a document which violates the validation rule: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand({\n insert: \"users\",\n documents: [ {user: \"123\", status: \"Active\" } ]\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insert</span>: <span class="lg-highlight-string">"users"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">documents</span>: <!-- -->[ <!-- -->{<span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"123"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"Active"</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> <p class="leafygreen-ui-1kp3ins"> The insert returns a write error message: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n n: 0,\n writeErrors: [\n {\n index: 0,\n code: 121,\n errInfo: {\n failingDocumentId: ObjectId('6197a7f2d84e85d1cc90d270'),\n details: {\n operatorName: '$in',\n specifiedAs: { status: { '$in': [Array] } },\n reason: 'no matching value found in array',\n consideredValue: 'Active'\n }\n },\n errmsg: 'Document failed validation'\n }\n ],\n ok: 1\n}","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">writeErrors</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">index</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">code</span>: <span class="lg-highlight-number">121</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">errInfo</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">failingDocumentId</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">'6197a7f2d84e85d1cc90d270'</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">details</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">operatorName</span>: <span class="lg-highlight-string">'$in'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">specifiedAs</span>: <!-- -->{ <span class="lg-highlight-attr">status</span>: <!-- -->{ <span class="lg-highlight-string">'$in'</span>: <!-- -->[<span class="lg-highlight-title lg-highlight-class">Array</span>] } }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">reason</span>: <span class="lg-highlight-string">'no matching value found in array'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">consideredValue</span>: <span class="lg-highlight-string">'Active'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">errmsg</span>: <span class="lg-highlight-string">'Document failed validation'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ok</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Set <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation : true </code> and rerun the insert: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand({\n insert: \"users\",\n documents: [ {user: \"123\", status: \"Active\" } ],\n bypassDocumentValidation: true\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insert</span>: <span class="lg-highlight-string">"users"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">documents</span>: <!-- -->[ <!-- -->{<span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"123"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"Active"</span> } ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bypassDocumentValidation</span>: <span class="lg-highlight-literal">true</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> <p class="leafygreen-ui-1kp3ins"> The operation succeeds. </p> <p class="leafygreen-ui-1kp3ins"> To check for documents that violate schema validation rules, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/validate/#mongodb-dbcommand-dbcmd.validate"> <code class="leafygreen-ui-1l06pbn"> validate </code> </a> command. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-insert-command-output"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Output <a class="headerlink leafygreen-ui-1kepx47" href="#output" 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="output"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The returned document contains a subset of the following fields: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> insert.ok </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-insert.ok" title="Permalink to this definition"> <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="mongodb-data-insert.ok"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The status of the command. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> insert.n </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-insert.n" title="Permalink to this definition"> <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="mongodb-data-insert.n"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The number of documents inserted. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> insert.writeErrors </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-insert.writeErrors" title="Permalink to this definition"> <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="mongodb-data-insert.writeErrors"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> An array of documents that contains information regarding any error encountered during the insert operation. The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-insert.writeErrors" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> writeErrors </code> </span> </a> array contains an error document for each insert that errors. </p> <p class="leafygreen-ui-1kp3ins"> Each error document contains the following fields: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> insert.writeErrors.index </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-insert.writeErrors.index" title="Permalink to this definition"> <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="mongodb-data-insert.writeErrors.index"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> An integer that identifies the document in the <code class="leafygreen-ui-1l06pbn"> documents </code> array, which uses a zero-based index. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> insert.writeErrors.code </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-insert.writeErrors.code" title="Permalink to this definition"> <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="mongodb-data-insert.writeErrors.code"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> An integer value identifying the error. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> insert.writeErrors.errmsg </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-insert.writeErrors.errmsg" title="Permalink to this definition"> <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="mongodb-data-insert.writeErrors.errmsg"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A description of the error. </p> </dd> </dl> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> insert.writeConcernError </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-insert.writeConcernError" title="Permalink to this definition"> <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="mongodb-data-insert.writeConcernError"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Document describing errors that relate to the write concern. </p> <div> <p> <em> Changed <!-- --> in version <!-- --> 7.1 </em> : <!-- --> When <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/insert/#mongodb-dbcommand-dbcmd.insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> executes on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-program-mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> , write concern errors are always reported, even when one or more write errors occur. </p> <p class="leafygreen-ui-1kp3ins"> In previous releases, the occurrence of write errors could cause the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.insert" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insert </code> </span> </a> to not report write concern errors. </p> </div> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> writeConcernError </code> documents contain the following fields: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> insert.writeConcernError.code </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-insert.writeConcernError.code" title="Permalink to this definition"> <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="mongodb-data-insert.writeConcernError.code"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> An integer value identifying the cause of the write concern error. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> insert.writeConcernError.errmsg </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-insert.writeConcernError.errmsg" title="Permalink to this definition"> <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="mongodb-data-insert.writeConcernError.errmsg"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A description of the cause of the write concern error. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> insert.writeConcernError.errInfo.writeConcern </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-insert.writeConcernError.errInfo.writeConcern" title="Permalink to this definition"> <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="mongodb-data-insert.writeConcernError.errInfo.writeConcern"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The write concern object used for the corresponding operation. For information on write concern object fields, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-specs"> Write Concern Specification <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> The write concern object may also contain the following field, indicating the source of the write concern: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> insert.writeConcernError.errInfo.writeConcern.provenance </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-insert.writeConcernError.errInfo.writeConcern.provenance" title="Permalink to this definition"> <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="mongodb-data-insert.writeConcernError.errInfo.writeConcern.provenance"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A string value indicating where the write concern originated (known as write concern <code class="leafygreen-ui-1l06pbn"> provenance </code> ). The following table shows the possible values for this field and their significance: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:40%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Provenance </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> clientSupplied </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern was specified in the application. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> customDefault </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern originated from a custom defined default value. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#mongodb-dbcommand-dbcmd.setDefaultRWConcern"> <code class="leafygreen-ui-1l06pbn"> setDefaultRWConcern </code> . </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> getLastErrorDefaults </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern originated from the replica set's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.getLastErrorDefaults"> <code class="leafygreen-ui-1l06pbn"> settings.getLastErrorDefaults </code> </a> field. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> implicitDefault </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern originated from the server in absence of all other write concern specifications. </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> </dd> </dl> </dd> </dl> <p class="leafygreen-ui-1kp3ins"> The following is an example document returned for a successful <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.insert" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insert </code> </span> </a> of a single document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ ok: 1, n: 1 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">ok</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-number">1</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> <p class="leafygreen-ui-1kp3ins"> The following is an example document returned for an <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.insert" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insert </code> </span> </a> of two documents that successfully inserted one document but encountered an error with the other document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"ok\" : 1,\n \"n\" : 1,\n \"writeErrors\" : [\n {\n \"index\" : 1,\n \"code\" : 11000,\n \"errmsg\" : \"insertDocument :: caused by :: 11000 E11000 duplicate key error index: test.users.$_id_ dup key: { : 1.0 }\"\n }\n ]\n}","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"writeErrors"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"index"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"code"</span> <!-- -->: <span class="lg-highlight-number">11000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"errmsg"</span> <!-- -->: <span class="lg-highlight-string">"insertDocument :: caused by :: 11000 E11000 duplicate key error index: test.users.$_id_ dup key: { : 1.0 }"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/db.collection.insertOne/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> db.collection.insertOne() <a class="headerlink leafygreen-ui-1kepx47" href="#db.collection.insertone--" 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="db.collection.insertone--"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behaviors" target="_self"> <span> Behaviors </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <div class="leafygreen-ui-147elvs"> <p class="leafygreen-ui-1ronz74"> MongoDB with drivers </p> <div class="leafygreen-ui-18k5rfm"> <p class="leafygreen-ui-1kp3ins"> This page documents a <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> method. To see the equivalent method in a MongoDB driver, see the corresponding page for your programming language: </p> </div> <div class="leafygreen-ui-zgrwqu notranslate"> <a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/csharp/current/fundamentals/crud/write-operations/insert/#insert-one-document" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59964)"> <g clip-path="url(#clip1_1351_59964)"> <path d="M25.7709 9.2495C25.7709 8.79827 25.678 8.39408 25.4827 8.04627C25.2874 7.70785 25.0084 7.42586 24.627 7.20025C21.465 5.35781 18.2937 3.51538 15.1317 1.67295C14.2761 1.17474 13.4484 1.19354 12.6021 1.70115C11.3466 2.45316 5.04112 6.10042 3.15321 7.20025C2.3813 7.65142 2 8.34705 2 9.24005C2 12.9531 2 16.6568 2 20.3698C2 20.8117 2.093 21.2064 2.279 21.5449C2.4743 21.8927 2.7626 22.1841 3.15321 22.4191C5.03182 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2761 28.4446 15.1317 27.9463C18.2937 26.1039 21.465 24.2615 24.627 22.4191C25.0177 22.1935 25.306 21.9021 25.5012 21.5449C25.6873 21.2064 25.7803 20.8117 25.7803 20.3698C25.7709 20.3698 25.7709 12.9531 25.7709 9.2495Z" fill="#A179DC"> </path> <path d="M13.9227 14.7673L2.27905 21.5449C2.47435 21.8927 2.76265 22.1841 3.15326 22.4191C5.03187 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2762 28.4445 15.1317 27.9463C18.2938 26.1039 21.4651 24.2615 24.6271 22.4191C25.0177 22.1935 25.306 21.9021 25.5013 21.5449L13.9227 14.7673Z" fill="#280068"> </path> <path d="M25.7711 9.24949C25.7711 8.79827 25.6781 8.39408 25.4828 8.04626L13.9229 14.7768L25.4921 21.5543C25.6781 21.2159 25.7711 20.8211 25.7711 20.3793C25.7711 20.3699 25.7711 12.9531 25.7711 9.24949Z" fill="#390091"> </path> <path d="M20.7771 12.2387V13.5078H22.0325V12.2387H22.6557V13.5078H23.9111V14.1376H22.6557V15.4066H23.9111V16.0364H22.6557V17.3054H22.0325V16.0364H20.7771V17.3054H20.1539V16.0364H18.8984V15.4066H20.1539V14.1376H18.8984V13.5078H20.1539V12.2387H20.7771ZM22.0325 14.1376H20.7771V15.4066H22.0325V14.1376Z" fill="white"> </path> <path d="M13.9508 5.87482C17.2151 5.87482 20.0702 7.67022 21.6047 10.3399L21.5861 10.3117L17.7452 12.5489C16.9919 11.2517 15.5969 10.3775 14.0066 10.3587H13.9601C11.5328 10.3587 9.56116 12.3515 9.56116 14.805C9.56116 15.604 9.77503 16.3654 10.1377 17.014C10.9004 18.3488 12.3232 19.2512 13.9601 19.2512C15.6062 19.2512 17.0384 18.3394 17.7917 16.9858L17.7731 17.014L21.614 19.2606C20.0981 21.9021 17.2895 23.6975 14.0531 23.7257H13.9508C10.6679 23.7257 7.81274 21.9209 6.28753 19.2418C5.54353 17.9352 5.11572 16.4124 5.11572 14.7956C5.11572 9.87931 9.06825 5.87482 13.9508 5.87482Z" fill="white"> </path> </g> </g> <defs> <clippath id="clip0_1351_59964"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59964"> <rect fill="white" height="27" transform="translate(2 1.30966)" width="24"> </rect> </clippath> </defs> </svg> <span> C# </span> </a> <a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/java/sync/current/fundamentals/crud/write-operations/insert/#insert-a-single-document" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD"> </path> <path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD"> </path> <path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E"> </path> <path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD"> </path> <path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD"> </path> <path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD"> </path> <path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E"> </path> <path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD"> </path> </svg> <span> Java Sync </span> </a> <a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/node/current/fundamentals/crud/write-operations/insert/#insert-a-single-document" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 30" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:R2dtlqcmqn9:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R2dtlqcmqn9:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":R2dtlqcmqn9:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":R2dtlqcmqn9:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <span> Node.js </span> </a> <a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/languages/python/pymongo-driver/current/write/insert/#insert-one-document" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 111.6 147" width="24" xmlns="http://www.w3.org/2000/svg"> <lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R2htlqcmqn9:aa" x1="280.848" x2="389.865" y1="-268.463" y2="-362.257"> <stop offset="0" stop-color="#5a9fd4"> </stop> <stop offset="1" stop-color="#306998"> </stop> </lineargradient> <path d="M55.3 3.2c-4.6 0-9 .4-12.8 1.1-11.3 2-13.4 6.2-13.4 13.9v10.2h26.8v3.4H19c-7.8 0-14.6 4.7-16.8 13.6C-.3 55.6-.4 62 2.2 72.7c1.9 7.9 6.5 13.6 14.2 13.6h9.2V74c0-8.8 7.7-16.7 16.7-16.7h26.8c7.5 0 13.4-6.1 13.4-13.6V18.2c0-7.3-6.1-12.7-13.4-13.9-4.4-.8-9.2-1.1-13.8-1.1zm-14.5 8.2c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1s2.2-5.1 5-5.1z" fill="url(#:R2htlqcmqn9:aa)"> </path> <lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R2htlqcmqn9:bb" x1="432.011" x2="393.081" y1="-419.025" y2="-363.946"> <stop offset="0" stop-color="#ffd43b"> </stop> <stop offset="1" stop-color="#ffe873"> </stop> </lineargradient> <path d="M86 31.8v11.9c0 9.2-7.8 17-16.8 17H42.5c-7.3 0-13.4 6.3-13.4 13.6v25.5c0 7.3 6.3 11.5 13.4 13.6 8.5 2.5 16.6 2.9 26.8 0 6.8-2 13.4-5.9 13.4-13.6V89.7H55.9v-3.4h40.2c7.8 0 10.7-5.4 13.4-13.6 2.8-8.4 2.7-16.5 0-27.3-1.9-7.8-5.6-13.6-13.4-13.6H86zM71 96.5c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1-.1-2.8 2.2-5.1 5-5.1z" fill="url(#:R2htlqcmqn9:bb)"> </path> <radialgradient cx="-2274.721" cy="144.526" gradienttransform="matrix(0 -.2399 -1.0547 0 208.637 -414.922)" gradientunits="userSpaceOnUse" id=":R2htlqcmqn9:cc" r="29.037"> <stop offset="0" stop-color="#b8b8b8" stop-opacity=".498"> </stop> <stop offset="1" stop-color="#7f7f7f" stop-opacity="0"> </stop> </radialgradient> <path d="M92.1 130.9c0 3.8-16.1 7-35.9 7s-35.9-3.1-35.9-7c0-3.8 16.1-7 35.9-7s35.9 3.1 35.9 7z" fill="url(#:R2htlqcmqn9:cc)" opacity=".444"> </path> </svg> <span> PyMongo </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongoc.org/libmongoc/current/mongoc_collection_insert_one.html" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59955)"> <g clip-path="url(#clip1_1351_59955)"> <path clip-rule="evenodd" d="M13.118 1.49532C13.5403 1.25103 14.0559 1.25103 14.4783 1.49532C16.5652 2.70389 22.8385 6.34889 24.9193 7.55748C25.3416 7.80172 25.6025 8.25176 25.6025 8.74672C25.6025 11.1703 25.6025 18.4539 25.6025 20.8774C25.6025 21.366 25.3416 21.8224 24.9193 22.0667C22.8385 23.2753 16.5652 26.9203 14.4783 28.1289C14.0559 28.3732 13.5403 28.3732 13.118 28.1289C11.0373 26.9139 4.76398 23.2689 2.68323 22.0603C2.26087 21.816 2 21.366 2 20.871C2 18.4474 2 11.1639 2 8.7403C2 8.25176 2.26087 7.7953 2.68323 7.55106C4.76398 6.34889 11.0373 2.70389 13.118 1.49532Z" fill="#004482" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M2.18634 21.4946C2.01863 21.2632 2 21.051 2 20.7553C2 18.351 2 11.1061 2 8.70176C2 8.21317 2.26087 7.76319 2.67702 7.51889C4.75776 6.31675 11.0062 2.69104 13.0807 1.4889C13.5031 1.24461 14.0683 1.25104 14.4907 1.49533C16.5652 2.69747 22.795 6.29104 24.8696 7.49319C25.0373 7.58963 25.1677 7.70535 25.2795 7.86606L2.18634 21.4946Z" fill="#659AD2" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M13.8011 5.8089C18.6024 5.8089 22.4968 9.83964 22.4968 14.8089C22.4968 19.7782 18.6024 23.8089 13.8011 23.8089C8.99986 23.8089 5.10547 19.7782 5.10547 14.8089C5.10547 9.83964 8.99986 5.8089 13.8011 5.8089ZM13.8011 10.3089C16.1987 10.3089 18.1489 12.3275 18.1489 14.8089C18.1489 17.2903 16.1987 19.3089 13.8011 19.3089C11.4036 19.3089 9.4533 17.2903 9.4533 14.8089C9.4533 12.3275 11.4036 10.3089 13.8011 10.3089Z" fill="white" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M25.2857 7.87247C25.6087 8.18102 25.6025 8.65034 25.6025 9.01673C25.6025 11.4596 25.5839 18.396 25.6087 20.8325C25.6087 21.0896 25.528 21.3532 25.4099 21.5589L13.5466 14.8089L25.2857 7.87247Z" fill="#00599C" fill-rule="evenodd"> </path> </g> </g> <defs> <clippath id="clip0_1351_59955"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59955"> <rect fill="white" height="27" transform="translate(2 1.30887)" width="24"> </rect> </clippath> </defs> </svg> <span> C </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/languages/cpp/cpp-driver/current/write/insert/#insert-one-document" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59959)"> <g clip-path="url(#clip1_1351_59959)"> <path d="M25.4013 21.5646C25.5872 21.2353 25.7034 20.8745 25.7034 20.5373V9.08012C25.7034 8.75078 25.5872 8.38217 25.4013 8.05283L13.8516 14.8127L25.4013 21.5646Z" fill="#00599C"> </path> <path d="M14.8738 28.0657L24.6729 22.3411C24.9517 22.1764 25.2151 21.8941 25.401 21.5647L13.8513 14.8127L2.30151 21.5647C2.48743 21.8941 2.74305 22.1764 3.02967 22.3411L12.8288 28.0657C13.3865 28.3951 14.316 28.3951 14.8738 28.0657Z" fill="#004482"> </path> <path d="M25.4011 8.06086C25.2152 7.73146 24.9596 7.44915 24.673 7.2845L14.8739 1.55983C14.3084 1.23046 13.3866 1.23046 12.8211 1.55983L3.02202 7.2845C2.46429 7.61385 1.99951 8.42158 1.99951 9.08033V20.5375C1.99951 20.8669 2.11571 21.2354 2.30162 21.5647L13.8514 14.8128L25.4011 8.06086Z" fill="#659AD2"> </path> <path d="M13.8512 22.8115C9.49778 22.8115 5.94995 19.2199 5.94995 14.8127C5.94995 10.4055 9.49778 6.81387 13.8512 6.81387C16.6631 6.81387 19.2813 8.34305 20.6912 10.8133L17.2751 12.813C16.5701 11.5818 15.261 10.8133 13.8512 10.8133C11.6745 10.8133 9.90055 12.6091 9.90055 14.8127C9.90055 17.0163 11.6745 18.8121 13.8512 18.8121C15.261 18.8121 16.5701 18.0436 17.2751 16.8124L20.6912 18.8121C19.2813 21.2745 16.6631 22.8115 13.8512 22.8115Z" fill="white"> </path> <path d="M21.7524 14.3657H20.8771V13.4796H19.994V14.3657H19.1187V15.2518H19.994V16.1458H20.8771V15.2518H21.7524V14.3657Z" fill="white"> </path> <path d="M25.0446 14.3657H24.1693V13.4796H23.2862V14.3657H22.4109V15.2518H23.2862V16.1458H24.1693V15.2518H25.0446V14.3657Z" fill="white"> </path> </g> </g> <defs> <clippath id="clip0_1351_59959"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59959"> <rect fill="white" height="27" transform="translate(1.99951 1.30878)" width="24"> </rect> </clippath> </defs> </svg> <span> C++ </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/go/current/fundamentals/crud/write-operations/insert/#insert-a-document-1" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" id="Layer_1" style="fill:#00ACD7" version="1.1" viewbox="0 0 205.4 76.7" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0"> <path class="st00" d="M15.5 23.2c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h35.7c.4 0 .5.3.3.6l-1.7 2.6c-.2.3-.7.6-1 .6l-36.2-.1zM.4 32.4c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h45.6c.4 0 .6.3.5.6l-.8 2.4c-.1.4-.5.6-.9.6l-47.3.1zM24.6 41.6c-.4 0-.5-.3-.3-.6l1.4-2.5c.2-.3.6-.6 1-.6h20c.4 0 .6.3.6.7l-.2 2.4c0 .4-.4.7-.7.7l-21.8-.1z"> </path> <g id="CXHf1q_3_"> <path class="st00" d="M128.4 21.4c-6.3 1.6-10.6 2.8-16.8 4.4-1.5.4-1.6.5-2.9-1-1.5-1.7-2.6-2.8-4.7-3.8-6.3-3.1-12.4-2.2-18.1 1.5-6.8 4.4-10.3 10.9-10.2 19 .1 8 5.6 14.6 13.5 15.7 6.8.9 12.5-1.5 17-6.6.9-1.1 1.7-2.3 2.7-3.7H89.6c-2.1 0-2.6-1.3-1.9-3 1.3-3.1 3.7-8.3 5.1-10.9.3-.6 1-1.6 2.5-1.6h36.4c-.2 2.7-.2 5.4-.6 8.1-1.1 7.2-3.8 13.8-8.2 19.6-7.2 9.5-16.6 15.4-28.5 17-9.8 1.3-18.9-.6-26.9-6.6-7.4-5.6-11.6-13-12.7-22.2-1.3-10.9 1.9-20.7 8.5-29.3C70.4 8.7 79.8 2.8 91.3.7c9.4-1.7 18.4-.6 26.5 4.9 5.3 3.5 9.1 8.3 11.6 14.1.6.9.2 1.4-1 1.7z"> </path> <path class="st00" d="M161.5 76.7c-9.1-.2-17.4-2.8-24.4-8.8-5.9-5.1-9.6-11.6-10.8-19.3-1.8-11.3 1.3-21.3 8.1-30.2 7.3-9.6 16.1-14.6 28-16.7 10.2-1.8 19.8-.8 28.5 5.1 7.9 5.4 12.8 12.7 14.1 22.3 1.7 13.5-2.2 24.5-11.5 33.9-6.6 6.7-14.7 10.9-24 12.8-2.7.5-5.4.6-8 .9zm23.8-40.4c-.1-1.3-.1-2.3-.3-3.3-1.8-9.9-10.9-15.5-20.4-13.3-9.3 2.1-15.3 8-17.5 17.4-1.8 7.8 2 15.7 9.2 18.9 5.5 2.4 11 2.1 16.3-.6 7.9-4.1 12.2-10.5 12.7-19.1z"> </path> </g> </svg> <span> Go </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/languages/java/reactive-streams-driver/current/write/insert-documents/#insert-one-document" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD"> </path> <path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD"> </path> <path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E"> </path> <path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD"> </path> <path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD"> </path> <path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD"> </path> <path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E"> </path> <path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD"> </path> </svg> <span> Java RS </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/kotlin/coroutine/current/fundamentals/crud/write-operations/insert/#insert-a-single-document" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R35tlqcmqn9:paint0_linear_211_40588)"> </path> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R35tlqcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29"> <stop offset="0.00343514" stop-color="#E44857"> </stop> <stop offset="0.4689" stop-color="#C711E1"> </stop> <stop offset="1" stop-color="#7F52FF"> </stop> </lineargradient> </defs> </svg> <span> Kotlin Coroutine </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/languages/kotlin/kotlin-sync-driver/current/write/insert/#insert-one-document" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R39tlqcmqn9:paint0_linear_211_40588)"> </path> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R39tlqcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29"> <stop offset="0.00343514" stop-color="#E44857"> </stop> <stop offset="0.4689" stop-color="#C711E1"> </stop> <stop offset="1" stop-color="#7F52FF"> </stop> </lineargradient> </defs> </svg> <span> Kotlin Sync </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/php-library/current/write/insert/#insert-one-document" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 700 301" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0"> <defs> <clippath clippathunits="userSpaceOnUse" id="a"> <path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439"> </path> </clippath> <clippath clippathunits="userSpaceOnUse" id="c"> <path d="M0 324h576V0H0v324z"> </path> </clippath> <clippath clippathunits="userSpaceOnUse" id="d"> <path d="M0 324h576V0H0v324z"> </path> </clippath> <radialgradient cx="0" cy="0" fx="0" fy="0" gradienttransform="matrix(363.05789 0 0 -363.05789 177.52 256.307)" gradientunits="userSpaceOnUse" id="b" r="1" spreadmethod="pad"> <stop offset="0" stop-color="#aeb2d5"> </stop> <stop offset=".3" stop-color="#aeb2d5"> </stop> <stop offset=".75" stop-color="#484c89"> </stop> <stop offset="1" stop-color="#484c89"> </stop> </radialgradient> </defs> <g clip-path="url(#a)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439" fill="url(#b)"> </path> </g> <g clip-path="url(#c)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M288 27.36c146.729 0 265.68 60.28 265.68 134.64 0 74.36-118.951 134.641-265.68 134.641S22.32 236.36 22.32 162.001C22.32 87.64 141.271 27.358 288 27.358" fill="#777bb3"> </path> </g> <g clip-path="url(#d)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M161.734 145.307c12.065 0 21.072 2.225 26.771 6.61 5.638 4.342 9.532 11.863 11.573 22.354 1.903 9.806 1.178 16.653-2.154 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.28l-10.69-55h15.673zm-63.063-67.75a2.998 2.998 0 00-2.944 3.572l28.328 145.75a3 3 0 002.945 2.428h61.054c19.188 0 33.47-5.21 42.447-15.487 9.025-10.331 11.812-24.772 8.283-42.921-1.436-7.394-3.906-14.261-7.34-20.41-3.44-6.154-7.985-11.85-13.512-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.28-3.93-30.548-3.93h-24.722l-7.06-36.321a3 3 0 00-2.944-2.428h-31.75z"> </path> <path d="M159.224 197.307h16.808c13.42 0 18.083-2.945 19.667-4.7 2.628-2.914 3.124-9.058 1.435-17.767-1.898-9.75-5.416-16.663-10.458-20.545-5.162-3.974-13.554-5.988-24.941-5.988H149.7l9.523 49zm28.83 35H127a6 6 0 01-5.89-4.855L92.784 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.588 33.895h22.249c12.582 0 23.174 1.372 31.479 4.077 8.54 2.775 16.399 7.48 23.354 13.984 5.752 5.292 10.49 11.232 14.08 17.657 3.59 6.427 6.17 13.594 7.668 21.302 3.715 19.104.697 34.402-8.97 45.466-9.571 10.958-24.613 16.514-44.705 16.514m-45.633-90h19.313c12.8 0 22.336 2.411 28.6 7.234 6.267 4.824 10.493 12.875 12.689 24.157 2.1 10.832 1.144 18.476-2.871 22.93-4.02 4.452-12.06 6.68-24.121 6.68h-21.754l-11.856-61m45.633 84c18.367 0 31.766-4.82 40.188-14.462 8.42-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.621-3.782-29.621-3.782h-27.196l-7.531-38.75h-31.75L127 226.307h61.055" fill="#fff"> </path> <path d="M311.583 116.307c-.896 0-1.745.4-2.314 1.092a2.994 2.994 0 00-.631 2.48l12.531 64.489c1.192 6.133.898 10.535-.827 12.395-1.056 1.137-4.228 3.044-13.607 3.044h-22.702l-15.755-81.072a3 3 0 00-2.945-2.428h-31.5a2.998 2.998 0 00-2.945 3.572l28.328 145.75a3 3 0 002.945 2.428h31.5a3 3 0 002.945-3.572l-6.836-35.178h24.422c18.605 0 31.221-3.28 38.569-10.028 7.49-6.884 9.827-17.891 6.947-32.72l-13.18-67.824a3 3 0 00-2.945-2.428h-32z"> </path> <path d="M293.661 271.057h-31.5a6 6 0 01-5.89-4.855l-28.328-145.75a5.998 5.998 0 015.89-7.145h31.5a6 6 0 015.89 4.855l15.283 78.645h20.23c9.362 0 11.327-2 11.406-2.086.568-.61 1.315-3.44.082-9.78l-12.53-64.49a5.998 5.998 0 015.89-7.144h32a6 6 0 015.89 4.855l13.178 67.825c3.093 15.921.447 27.864-7.86 35.5-7.929 7.281-21.209 10.82-40.6 10.82h-20.784l6.143 31.605a6.001 6.001 0 01-5.89 7.145m0-6l-7.53-38.75h28.061c17.657 0 29.836-3.082 36.54-9.238 6.702-6.16 8.71-16.14 6.031-29.938l-13.18-67.824h-32l12.531 64.488c1.426 7.336.902 12.34-1.574 15.008-2.477 2.668-7.746 4.004-15.805 4.004H281.56l-16.226-83.5h-31.5l28.328 145.75h31.5" fill="#fff"> </path> <path d="M409.55 145.307c12.065 0 21.072 2.225 26.77 6.61 5.639 4.34 9.533 11.862 11.575 22.354 1.903 9.806 1.178 16.653-2.155 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.281l-10.69-55h15.674zm-63.062-67.75a2.999 2.999 0 00-2.945 3.572l28.328 145.75a3.002 3.002 0 002.946 2.428h61.053c19.189 0 33.47-5.21 42.448-15.487 9.025-10.33 11.81-24.771 8.283-42.921-1.438-7.394-3.907-14.261-7.342-20.41-3.44-6.154-7.984-11.85-13.511-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.281-3.93-30.548-3.93H388.24l-7.057-36.321a3.001 3.001 0 00-2.946-2.428h-31.75z"> </path> <path d="M407.04 197.307h16.807c13.421 0 18.083-2.945 19.667-4.7 2.63-2.914 3.125-9.058 1.435-17.766-1.898-9.75-5.417-16.664-10.458-20.546-5.162-3.974-13.554-5.988-24.94-5.988h-12.034l9.522 49zm28.83 35h-61.054a6 6 0 01-5.889-4.855L340.6 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.587 33.895h22.25c12.581 0 23.173 1.372 31.478 4.077 8.541 2.775 16.401 7.481 23.356 13.986 5.752 5.291 10.488 11.23 14.078 17.655 3.591 6.427 6.171 13.594 7.668 21.302 3.715 19.105.697 34.403-8.969 45.467-9.572 10.957-24.613 16.513-44.706 16.513m-45.632-90h19.312c12.801 0 22.336 2.411 28.601 7.234 6.267 4.824 10.492 12.875 12.688 24.157 2.102 10.832 1.145 18.476-2.87 22.93-4.02 4.452-12.06 6.68-24.122 6.68h-21.754l-11.855-61m45.632 84c18.367 0 31.766-4.82 40.188-14.462 8.422-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.62-3.782-29.62-3.782h-27.197l-7.53-38.75h-31.75l28.328 145.75h61.054" fill="#fff"> </path> </g> </svg> <span> PHP </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/mongoid/current/reference/crud/#standard" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" preserveaspectratio="xMidYMid" viewbox="0 0 300 240" width="24" xmlns="http://www.w3.org/2000/svg"> <defs> <lineargradient id=":R3htlqcmqn9:a" x1="84.75%" x2="58.254%" y1="111.399%" y2="64.584%"> <stop offset="0%" stop-color="#FB7655"> </stop> <stop offset="0%" stop-color="#FB7655"> </stop> <stop offset="41%" stop-color="#E42B1E"> </stop> <stop offset="99%" stop-color="#900"> </stop> <stop offset="100%" stop-color="#900"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:b" x1="116.651%" x2="1.746%" y1="60.89%" y2="19.288%"> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="99%" stop-color="#911209"> </stop> <stop offset="100%" stop-color="#911209"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:c" x1="75.774%" x2="38.978%" y1="219.327%" y2="7.829%"> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="99%" stop-color="#911209"> </stop> <stop offset="100%" stop-color="#911209"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:d" x1="50.012%" x2="66.483%" y1="7.234%" y2="79.135%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="23%" stop-color="#E57252"> </stop> <stop offset="46%" stop-color="#DE3B20"> </stop> <stop offset="99%" stop-color="#A60003"> </stop> <stop offset="100%" stop-color="#A60003"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:e" x1="46.174%" x2="49.932%" y1="16.348%" y2="83.047%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="23%" stop-color="#E4714E"> </stop> <stop offset="56%" stop-color="#BE1A0D"> </stop> <stop offset="99%" stop-color="#A80D00"> </stop> <stop offset="100%" stop-color="#A80D00"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:f" x1="36.965%" x2="49.528%" y1="15.594%" y2="92.478%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="18%" stop-color="#E46342"> </stop> <stop offset="40%" stop-color="#C82410"> </stop> <stop offset="99%" stop-color="#A80D00"> </stop> <stop offset="100%" stop-color="#A80D00"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:g" x1="13.609%" x2="85.764%" y1="58.346%" y2="-46.717%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="54%" stop-color="#C81F11"> </stop> <stop offset="99%" stop-color="#BF0905"> </stop> <stop offset="100%" stop-color="#BF0905"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:h" x1="27.624%" x2="50.745%" y1="21.135%" y2="79.056%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="31%" stop-color="#DE4024"> </stop> <stop offset="99%" stop-color="#BF190B"> </stop> <stop offset="100%" stop-color="#BF190B"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:i" x1="-20.667%" x2="104.242%" y1="122.282%" y2="-6.342%"> <stop offset="0%" stop-color="#BD0012"> </stop> <stop offset="0%" stop-color="#BD0012"> </stop> <stop offset="7%" stop-color="#FFF"> </stop> <stop offset="17%" stop-color="#FFF"> </stop> <stop offset="27%" stop-color="#C82F1C"> </stop> <stop offset="33%" stop-color="#820C01"> </stop> <stop offset="46%" stop-color="#A31601"> </stop> <stop offset="72%" stop-color="#B31301"> </stop> <stop offset="99%" stop-color="#E82609"> </stop> <stop offset="100%" stop-color="#E82609"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:j" x1="58.792%" x2="11.964%" y1="65.205%" y2="50.128%"> <stop offset="0%" stop-color="#8C0C01"> </stop> <stop offset="0%" stop-color="#8C0C01"> </stop> <stop offset="54%" stop-color="#990C00"> </stop> <stop offset="99%" stop-color="#A80D0E"> </stop> <stop offset="100%" stop-color="#A80D0E"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:k" x1="79.319%" x2="23.088%" y1="62.754%" y2="17.888%"> <stop offset="0%" stop-color="#7E110B"> </stop> <stop offset="0%" stop-color="#7E110B"> </stop> <stop offset="99%" stop-color="#9E0C00"> </stop> <stop offset="100%" stop-color="#9E0C00"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:l" x1="92.88%" x2="59.841%" y1="74.122%" y2="39.704%"> <stop offset="0%" stop-color="#79130D"> </stop> <stop offset="0%" stop-color="#79130D"> </stop> <stop offset="99%" stop-color="#9E120B"> </stop> <stop offset="100%" stop-color="#9E120B"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:o" x1="56.57%" x2="3.105%" y1="101.717%" y2="11.993%"> <stop offset="0%" stop-color="#8B2114"> </stop> <stop offset="0%" stop-color="#8B2114"> </stop> <stop offset="43%" stop-color="#9E100A"> </stop> <stop offset="99%" stop-color="#B3100C"> </stop> <stop offset="100%" stop-color="#B3100C"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:p" x1="30.87%" x2="92.471%" y1="35.599%" y2="100.694%"> <stop offset="0%" stop-color="#B31000"> </stop> <stop offset="0%" stop-color="#B31000"> </stop> <stop offset="44%" stop-color="#910F08"> </stop> <stop offset="99%" stop-color="#791C12"> </stop> <stop offset="100%" stop-color="#791C12"> </stop> </lineargradient> <radialgradient cx="32.001%" cy="40.21%" fx="32.001%" fy="40.21%" id=":R3htlqcmqn9:m" r="69.573%"> <stop offset="0%" stop-color="#A80D00"> </stop> <stop offset="0%" stop-color="#A80D00"> </stop> <stop offset="99%" stop-color="#7E0E08"> </stop> <stop offset="100%" stop-color="#7E0E08"> </stop> </radialgradient> <radialgradient cx="13.549%" cy="40.86%" fx="13.549%" fy="40.86%" id=":R3htlqcmqn9:n" r="88.386%"> <stop offset="0%" stop-color="#A30C00"> </stop> <stop offset="0%" stop-color="#A30C00"> </stop> <stop offset="99%" stop-color="#800E08"> </stop> <stop offset="100%" stop-color="#800E08"> </stop> </radialgradient> </defs> <path d="M197.467 167.764l-145.52 86.41 188.422-12.787L254.88 51.393l-57.414 116.37z" fill="url(#:R3htlqcmqn9:a)"> </path> <path d="M240.677 241.257L224.482 129.48l-44.113 58.25 60.308 53.528z" fill="url(#:R3htlqcmqn9:b)"> </path> <path d="M240.896 241.257l-118.646-9.313-69.674 21.986 188.32-12.673z" fill="url(#:R3htlqcmqn9:c)"> </path> <path d="M52.744 253.955l29.64-97.1L17.16 170.8l35.583 83.154z" fill="url(#:R3htlqcmqn9:d)"> </path> <path d="M180.358 188.05L153.085 81.226l-78.047 73.16 105.32 33.666z" fill="url(#:R3htlqcmqn9:e)"> </path> <path d="M248.693 82.73l-73.777-60.256-20.544 66.418 94.321-6.162z" fill="url(#:R3htlqcmqn9:f)"> </path> <path d="M214.191.99L170.8 24.97 143.424.669l70.767.322z" fill="url(#:R3htlqcmqn9:g)"> </path> <path d="M0 203.372l18.177-33.151-14.704-39.494L0 203.372z" fill="url(#:R3htlqcmqn9:h)"> </path> <path d="M2.496 129.48l14.794 41.963 64.283-14.422 73.39-68.207 20.712-65.787L143.063 0 87.618 20.75c-17.469 16.248-51.366 48.396-52.588 49-1.21.618-22.384 40.639-32.534 59.73z" fill="#FFF"> </path> <path d="M54.442 54.094c37.86-37.538 86.667-59.716 105.397-40.818 18.72 18.898-1.132 64.823-38.992 102.349-37.86 37.525-86.062 60.925-104.78 42.027-18.73-18.885.515-66.032 38.375-103.558z" fill="url(#:R3htlqcmqn9:i)"> </path> <path d="M52.744 253.916l29.408-97.409 97.665 31.376c-35.312 33.113-74.587 61.106-127.073 66.033z" fill="url(#:R3htlqcmqn9:j)"> </path> <path d="M155.092 88.622l25.073 99.313c29.498-31.016 55.972-64.36 68.938-105.603l-94.01 6.29z" fill="url(#:R3htlqcmqn9:k)"> </path> <path d="M248.847 82.833c10.035-30.282 12.35-73.725-34.966-81.791l-38.825 21.445 73.791 60.346z" fill="url(#:R3htlqcmqn9:l)"> </path> <path d="M0 202.935c1.39 49.979 37.448 50.724 52.808 51.162l-35.48-82.86L0 202.935z" fill="#9E1209"> </path> <path d="M155.232 88.777c22.667 13.932 68.35 41.912 69.276 42.426 1.44.81 19.695-30.784 23.838-48.64l-93.114 6.214z" fill="url(#:R3htlqcmqn9:m)"> </path> <path d="M82.113 156.507l39.313 75.848c23.246-12.607 41.45-27.967 58.121-44.42l-97.434-31.428z" fill="url(#:R3htlqcmqn9:n)"> </path> <path d="M17.174 171.34l-5.57 66.328c10.51 14.357 24.97 15.605 40.136 14.486-10.973-27.311-32.894-81.92-34.566-80.814z" fill="url(#:R3htlqcmqn9:o)"> </path> <path d="M174.826 22.654l78.1 10.96c-4.169-17.662-16.969-29.06-38.787-32.623l-39.313 21.663z" fill="url(#:R3htlqcmqn9:p)"> </path> </svg> <span> Mongoid </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/rust/current/fundamentals/crud/write-operations/insert/#insert-a-document" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 30 30" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_5454_14623)"> <path d="M15.2561 3.08398C8.56014 3.08398 3.11035 8.53634 3.11035 15.2297C3.11035 21.9231 8.56271 27.3755 15.2561 27.3755C21.9495 27.3755 27.4019 21.9231 27.4019 15.2297C27.4019 8.53634 21.9495 3.08398 15.2561 3.08398ZM15.2381 4.16315C15.4458 4.16853 15.6432 4.25509 15.7881 4.40437C15.9331 4.55365 16.0142 4.75384 16.0141 4.96225C16.0141 5.17418 15.9299 5.37744 15.7801 5.5273C15.6302 5.67715 15.4269 5.76134 15.215 5.76134C15.0031 5.76134 14.7998 5.67715 14.65 5.5273C14.5001 5.37744 14.4159 5.17418 14.4159 4.96225C14.4159 4.85533 14.4373 4.7495 14.4789 4.65101C14.5205 4.55252 14.5814 4.46338 14.6581 4.38887C14.7347 4.31435 14.8256 4.25598 14.9252 4.21721C15.0249 4.17844 15.1313 4.16006 15.2381 4.16315ZM17.0676 5.47871C18.4704 5.74146 19.7992 6.30644 20.9617 7.13439C22.1242 7.96235 23.0926 9.03345 23.7995 10.2733L22.8565 12.4008C22.6947 12.7682 22.8617 13.1999 23.2265 13.3643L25.0406 14.1686C25.0968 14.7356 25.1037 15.3065 25.0611 15.8747H24.0513C23.9511 15.8747 23.91 15.9415 23.91 16.0391V16.5016C23.91 17.5911 23.2959 17.83 22.7563 17.8891C22.2424 17.9482 21.6746 17.6733 21.6026 17.3598C21.2994 15.6563 20.7958 15.294 19.9993 14.6645C20.9885 14.0375 22.0163 13.11 22.0163 11.8715C22.0163 10.5328 21.099 9.69002 20.4747 9.27634C19.5959 8.69822 18.6247 8.5826 18.3626 8.5826H7.93063C9.37312 6.97114 11.3066 5.88021 13.4318 5.47871L14.6626 6.76857C14.9401 7.05891 15.4 7.07176 15.6903 6.79169L17.0676 5.47871ZM5.71063 11.3936C5.91853 11.3996 6.11589 11.4864 6.26079 11.6356C6.40568 11.7849 6.48669 11.9847 6.4866 12.1927C6.4866 12.4046 6.40241 12.6079 6.25255 12.7577C6.10269 12.9076 5.89944 12.9918 5.6875 12.9918C5.47557 12.9918 5.27232 12.9076 5.12246 12.7577C4.9726 12.6079 4.88841 12.4046 4.88841 12.1927C4.88836 12.0858 4.90977 11.9799 4.95137 11.8814C4.99297 11.7829 5.0539 11.6938 5.13057 11.6193C5.20724 11.5448 5.29809 11.4864 5.39772 11.4476C5.49736 11.4089 5.60376 11.3905 5.71063 11.3936ZM24.7631 11.4295C24.971 11.4356 25.1683 11.5224 25.3132 11.6716C25.4581 11.8208 25.5391 12.0206 25.539 12.2286C25.539 12.4406 25.4548 12.6438 25.305 12.7937C25.1551 12.9435 24.9519 13.0277 24.7399 13.0277C24.528 13.0277 24.3247 12.9435 24.1749 12.7937C24.025 12.6438 23.9408 12.4406 23.9408 12.2286C23.9408 12.1217 23.9622 12.0159 24.0038 11.9174C24.0454 11.8189 24.1063 11.7298 24.183 11.6553C24.2597 11.5807 24.3505 11.5224 24.4502 11.4836C24.5498 11.4448 24.6562 11.4264 24.7631 11.4295ZM7.21632 11.558H8.60896V17.8377H5.79799C5.45083 16.6186 5.34264 15.3439 5.47938 14.0838L7.20091 13.3181C7.56834 13.1536 7.73535 12.7245 7.57091 12.3571L7.21632 11.558ZM13.0284 11.6248H16.3456C16.5177 11.6248 17.5558 11.8227 17.5558 12.6012C17.5558 13.2461 16.7592 13.4774 16.104 13.4774H13.0258L13.0284 11.6248ZM13.0284 16.1368H15.5696C15.8008 16.1368 16.8106 16.2036 17.1318 17.4934C17.232 17.8891 17.4556 19.179 17.6072 19.5927C17.7588 20.0552 18.3729 20.9802 19.0281 20.9802H23.1751C22.8972 21.3524 22.5933 21.7044 22.2656 22.0336L20.5774 21.6713C20.1843 21.5866 19.7963 21.8384 19.7115 22.2315L19.3107 24.102C18.0217 24.6859 16.622 24.9848 15.2069 24.9781C13.7919 24.9714 12.395 24.6595 11.1116 24.0635L10.7108 22.1929C10.626 21.7998 10.2406 21.548 9.84743 21.6328L8.19528 21.9874C7.88869 21.6711 7.6037 21.3346 7.34223 20.9802H15.3769C15.4668 20.9802 15.5285 20.9647 15.5285 20.88V18.0381C15.5285 17.9559 15.4668 17.9379 15.3769 17.9379H13.0258L13.0284 16.1368ZM9.3207 22.6452C9.5286 22.6512 9.72596 22.738 9.87085 22.8872C10.0157 23.0364 10.0968 23.2363 10.0967 23.4443C10.0967 23.6562 10.0125 23.8594 9.86262 24.0093C9.71276 24.1592 9.50951 24.2434 9.29757 24.2434C9.08564 24.2434 8.88239 24.1592 8.73253 24.0093C8.58267 23.8594 8.49848 23.6562 8.49848 23.4443C8.49843 23.3373 8.51984 23.2315 8.56144 23.133C8.60303 23.0345 8.66397 22.9454 8.74064 22.8709C8.81731 22.7964 8.90815 22.738 9.00779 22.6992C9.10743 22.6605 9.21383 22.6421 9.3207 22.6452ZM21.153 22.6811C21.3609 22.6872 21.5583 22.774 21.7031 22.9232C21.848 23.0724 21.929 23.2722 21.929 23.4802C21.929 23.6922 21.8448 23.8954 21.6949 24.0453C21.5451 24.1951 21.3418 24.2793 21.1299 24.2793C20.9179 24.2793 20.7147 24.1951 20.5648 24.0453C20.415 23.8954 20.3308 23.6922 20.3308 23.4802C20.3307 23.3733 20.3521 23.2675 20.3937 23.169C20.4353 23.0705 20.4963 22.9814 20.5729 22.9068C20.6496 22.8323 20.7404 22.774 20.8401 22.7352C20.9397 22.6964 21.0461 22.678 21.153 22.6811Z" fill="black"> </path> <path clip-rule="evenodd" d="M26.7232 15.2304C26.7232 18.2717 25.515 21.1885 23.3645 23.3391C21.2139 25.4896 18.2971 26.6978 15.2558 26.6978C12.2144 26.6978 9.29761 25.4896 7.14705 23.3391C4.99649 21.1885 3.78832 18.2717 3.78832 15.2304C3.78832 12.189 4.99649 9.27222 7.14705 7.12166C9.29761 4.9711 12.2144 3.76293 15.2558 3.76293C18.2971 3.76293 21.2139 4.9711 23.3645 7.12166C25.515 9.27222 26.7232 12.189 26.7232 15.2304ZM26.5073 14.1229L28.2957 15.2304L26.5073 16.3378L28.0439 17.7741L26.0757 18.5115L27.3039 20.2202L25.2252 20.5594L26.0988 22.4762L23.9944 22.4017L24.4775 24.4521L22.4271 23.969L22.5016 26.0734L20.5848 25.1998L20.2456 27.2785L18.5369 26.0503L17.7995 28.0185L16.3632 26.482L15.2558 28.2703L14.1483 26.482L12.712 28.0185L11.9746 26.0503L10.2659 27.2785L9.92672 25.1998L8.00992 26.0734L8.08443 23.969L6.03401 24.4521L6.51707 22.4017L4.4127 22.4762L5.28631 20.5594L3.20763 20.2202L4.43582 18.5115L2.46763 17.7741L4.00415 16.3378L2.21582 15.2304L4.00415 14.1229L2.46763 12.6866L4.43582 11.9492L3.20763 10.2405L5.28631 9.90133L4.4127 7.98453L6.51707 8.05904L6.03401 6.00862L8.08443 6.49168L8.00992 4.3873L9.92672 5.26092L10.2659 3.18223L11.9746 4.41043L12.712 2.44224L14.1483 3.97876L15.2558 2.19043L16.3632 3.97876L17.7995 2.44224L18.5369 4.41043L20.2456 3.18223L20.5848 5.26092L22.5016 4.3873L22.4271 6.49168L24.4775 6.00862L23.9944 8.05904L26.0988 7.98453L25.2252 9.90133L27.3039 10.2405L26.0757 11.9492L28.0439 12.6866L26.5073 14.1229Z" fill="black" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"> </path> </g> <defs> <clippath id="clip0_5454_14623"> <rect fill="black" height="30" width="30"> </rect> </clippath> </defs> </svg> <span> Rust </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/languages/scala/scala-driver/current/tutorials/write-ops/#insert-a-document" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 70 70" width="24" xmlns="http://www.w3.org/2000/svg"> <defs> <lineargradient id=":R3ptlqcmqn9:aaa" x1=".006%" x2="96.837%" y1="49.998%" y2="49.998%"> <stop offset="0%" stop-color="#CD413F"> </stop> <stop offset="75.091%" stop-color="#CD4543"> </stop> <stop offset="100%" stop-color="#D04543"> </stop> </lineargradient> </defs> <g fill="none" fill-rule="nonzero"> <path d="M13 39v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 36.745 13 38.157 13 39M13 20v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 17.745 13 19.157 13 20" fill="#731818"> </path> <g fill="url(#:R3ptlqcmqn9:aaa)" transform="translate(13)"> <path d="M0 29.53v14.766c0-1.232 39-3.692 39-9.844V19.686c0 6.152-39 8.612-39 9.844M0 9.843V24.61c0-1.231 39-3.691 39-9.843V0C39 6.152 0 8.612 0 9.843M0 49.216v14.766c0-1.231 39-3.691 39-9.843V39.373c0 6.151-39 8.612-39 9.843"> </path> </g> </g> </svg> <span> Scala </span> </a> </div> <button class="leafygreen-ui-ki2t97"> Show all <svg aria-label="Chevron Down Icon" class="" fill="none" height="16" role="img" viewbox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"> <path clip-rule="evenodd" d="M1.636 5.364a1 1 0 0 0 0 1.414l4.95 4.95.707.707a1 1 0 0 0 1.414 0l.707-.707 4.95-4.95a1 1 0 0 0 0-1.414l-.707-.707a1 1 0 0 0-1.414 0L8 8.899 3.757 4.657a1 1 0 0 0-1.414 0l-.707.707Z" fill="currentColor" fill-rule="evenodd"> </path> </svg> </button> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> db.collection.insertOne() </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.collection.insertOne" title="Permalink to this definition"> <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="mongodb-method-db.collection.insertOne"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Inserts a single document into a collection. </p> <table class="css-11h39yh e1nex8bq0"> <colgroup> <col class="field-name"/> <col class="field-body"/> </colgroup> <tbody> <tr class="css-x8snli"> <th> Returns <!-- --> : </th> <td> A document containing: <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A boolean <code class="leafygreen-ui-1l06pbn"> acknowledged </code> as <code class="leafygreen-ui-1l06pbn"> true </code> if the operation ran with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-write-concern"> write concern </a> or <code class="leafygreen-ui-1l06pbn"> false </code> if write concern was disabled. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A field <code class="leafygreen-ui-1l06pbn"> insertedId </code> with the <code class="leafygreen-ui-1l06pbn"> _id </code> value of the inserted document. </p> </li> </ul> </td> </tr> </tbody> </table> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> You can use <code class="leafygreen-ui-1l06pbn"> db.collection.insertOne() </code> for deployments hosted 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> </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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.insertOne" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insertOne() </code> </span> </a> method has the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.insertOne(\n &lt;document&gt;,\n {\n writeConcern: &lt;document&gt;\n }\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">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> &lt;<span class="lg-highlight-variable lg-highlight-language">document</span>&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">writeConcern</span>: &lt;<span class="lg-highlight-variable lg-highlight-language">document</span>&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</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> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.insertOne" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insertOne() </code> </span> </a> method takes the following parameters: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Parameter </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> document </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> A document to insert into the collection. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> writeConcern </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Optional. A document expressing the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/"> write concern </a> . Omit to use the default write concern. .. include:: /includes/extracts/transactions-operations-write-concern.rst </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behaviors <a class="headerlink leafygreen-ui-1kepx47" href="#behaviors" 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="behaviors"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Collection Creation <a class="headerlink leafygreen-ui-1kepx47" href="#collection-creation" 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="collection-creation"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If the collection does not exist, then the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.insertOne" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insertOne() </code> </span> </a> method creates the collection. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> _id </code> Field <a class="headerlink leafygreen-ui-1kepx47" href="#_id-field" 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="_id-field"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If the document does not specify an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-_id"> _id </a> field, then <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> will add the <code class="leafygreen-ui-1l06pbn"> _id </code> field and assign a unique <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId/#mongodb-method-ObjectId"> <code class="leafygreen-ui-1l06pbn"> ObjectId() </code> </a> for the document before inserting. Most drivers create an ObjectId and insert the <code class="leafygreen-ui-1l06pbn"> _id </code> field, but the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> will create and populate the <code class="leafygreen-ui-1l06pbn"> _id </code> if the driver or application does not. </p> <p class="leafygreen-ui-1kp3ins"> If the document contains an <code class="leafygreen-ui-1l06pbn"> _id </code> field, the <code class="leafygreen-ui-1l06pbn"> _id </code> value must be unique within the collection to avoid duplicate key error. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Explainability <a class="headerlink leafygreen-ui-1kepx47" href="#explainability" 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="explainability"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.insertOne" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insertOne() </code> </span> </a> is not compatible with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.explain/#mongodb-method-db.collection.explain"> <code class="leafygreen-ui-1l06pbn"> db.collection.explain() </code> . </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Error Handling <a class="headerlink leafygreen-ui-1kepx47" href="#error-handling" 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="error-handling"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> On error, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.insertOne" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.insertOne() </code> </span> </a> throws either a <code class="leafygreen-ui-1l06pbn"> writeError </code> or <code class="leafygreen-ui-1l06pbn"> writeConcernError </code> exception. </p> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Schema Validation Errors <a class="headerlink leafygreen-ui-1kepx47" href="#schema-validation-errors" 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="schema-validation-errors"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> If your collection uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/schema-validation/#std-label-schema-validation-overview"> schema validation </a> and has <code class="leafygreen-ui-1l06pbn"> validationAction </code> set to <code class="leafygreen-ui-1l06pbn"> error </code> , inserting an invalid document throws a <code class="leafygreen-ui-1l06pbn"> MongoServerError </code> and <code class="leafygreen-ui-1l06pbn"> db.collection.insertOne() </code> fails. </p> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" 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> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.insertOne" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.insertOne() </code> </span> </a> can be used inside <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> distributed transactions <!-- --> . </a> </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> In most cases, a distributed transaction incurs a greater performance cost over single document writes, and the availability of distributed transactions should not be a replacement for effective schema design. For many scenarios, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding"> denormalized data model (embedded documents and arrays) </a> will continue to be optimal for your data and use cases. That is, for many scenarios, modeling your data appropriately will minimize the need for distributed transactions. </p> <p class="leafygreen-ui-1kp3ins"> For additional transactions usage considerations (such as runtime limit and oplog size limit), see also <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-production-consideration/#std-label-production-considerations"> Production Considerations <!-- --> . </a> </p> </div> </div> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Collection Creation in Transactions <a class="headerlink leafygreen-ui-1kepx47" href="#collection-creation-in-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="collection-creation-in-transactions"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can create collections and indexes inside a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-create-collections-indexes"> distributed transaction </a> if the transaction is <strong class="css-4dei7l"> not </strong> a cross-shard write transaction. </p> <p class="leafygreen-ui-1kp3ins"> If you specify an insert on a non-existing collection in a transaction, MongoDB creates the collection implicitly. </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/transactions/#std-label-transactions-create-collections-indexes"> Create Collections and Indexes in a Transaction </a> </p> </div> </div> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Write Concerns and Transactions <a class="headerlink leafygreen-ui-1kepx47" href="#write-concerns-and-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="write-concerns-and-transactions"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Do not explicitly set the write concern for the operation if run in a transaction. To use write concern with transactions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern"> Transactions and Write Concern <!-- --> . </a> </p> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Oplog Entries <a class="headerlink leafygreen-ui-1kepx47" href="#oplog-entries" 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="oplog-entries"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If a <code class="leafygreen-ui-1l06pbn"> db.collection.insertOne() </code> operation successfully inserts a document, the operation adds an entry on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> (operations log). If the operation fails, the operation does not add an entry on the oplog. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-insertOne-examples"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Insert a Document without Specifying an <code class="leafygreen-ui-1l06pbn"> _id </code> Field <a class="headerlink leafygreen-ui-1kepx47" href="#insert-a-document-without-specifying-an-_id-field" 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-a-document-without-specifying-an-_id-field"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> In the following example, the document passed to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.insertOne" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insertOne() </code> </span> </a> method does not contain the <code class="leafygreen-ui-1l06pbn"> _id </code> field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"try {\n db.products.insertOne( { item: \"card\", qty: 15 } );\n} catch (e) {\n print (e);\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"><span class="lg-highlight-keyword">try</span> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->db.<span class="lg-highlight-property">products</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"card"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">15</span> } )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} <span class="lg-highlight-keyword">catch</span> <!-- -->(<!-- -->e) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->print <!-- -->(<!-- -->e)<!-- -->;</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"acknowledged\" : true,\n \"insertedId\" : ObjectId(\"56fc40f9d735c28df206d078\")\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"acknowledged"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insertedId"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"56fc40f9d735c28df206d078"</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> <p class="leafygreen-ui-1kp3ins"> Because the documents did not include <code class="leafygreen-ui-1l06pbn"> _id </code> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> creates and adds the <code class="leafygreen-ui-1l06pbn"> _id </code> field and assigns it a unique <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId/#mongodb-method-ObjectId"> <code class="leafygreen-ui-1l06pbn"> ObjectId() </code> </a> value. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> ObjectId </code> values are specific to the machine and time when the operation is run. As such, your values may differ from those in the example. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Insert a Document Specifying an <code class="leafygreen-ui-1l06pbn"> _id </code> Field <a class="headerlink leafygreen-ui-1kepx47" href="#insert-a-document-specifying-an-_id-field" 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-a-document-specifying-an-_id-field"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> In the following example, the document passed to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.insertOne" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> insertOne() </code> </span> </a> method includes the <code class="leafygreen-ui-1l06pbn"> _id </code> field. The value of <code class="leafygreen-ui-1l06pbn"> _id </code> must be unique within the collection to avoid duplicate key error. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"try {\n db.products.insertOne( { _id: 10, item: \"box\", qty: 20 } );\n} catch (e) {\n print (e);\n}","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">try</span> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->db.<span class="lg-highlight-property">products</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"box"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">20</span> } )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} <span class="lg-highlight-keyword">catch</span> <!-- -->(<!-- -->e) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->print <!-- -->(<!-- -->e)<!-- -->;</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"acknowledged\" : true, \"insertedId\" : 10 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-string">"acknowledged"</span> <!-- -->: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"insertedId"</span> <!-- -->: <span class="lg-highlight-number">10</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> <p class="leafygreen-ui-1kp3ins"> Inserting an duplicate value for any key that is part of a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-unique-index"> unique index </a> , such as <code class="leafygreen-ui-1l06pbn"> _id </code> , throws an exception. The following attempts to insert a document with a <code class="leafygreen-ui-1l06pbn"> _id </code> value that already exists: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"try {\n db.products.insertOne( { _id: 10, \"item\" : \"packing peanuts\", \"qty\" : 200 } );\n} catch (e) {\n print (e);\n}","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">try</span> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->db.<span class="lg-highlight-property">products</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"packing peanuts"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">200</span> } )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} <span class="lg-highlight-keyword">catch</span> <!-- -->(<!-- -->e) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->print <!-- -->(<!-- -->e)<!-- -->;</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> <p class="leafygreen-ui-1kp3ins"> Since <code class="leafygreen-ui-1l06pbn"> _id: 10 </code> already exists, the following exception is thrown: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"WriteError({\n \"index\" : 0,\n \"code\" : 11000,\n \"errmsg\" : \"E11000 duplicate key error collection: inventory.products index: _id_ dup key: { : 10.0 }\",\n \"op\" : {\n \"_id\" : 10,\n \"item\" : \"packing peanuts\",\n \"qty\" : 200\n }\n})","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">WriteError</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"index"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"code"</span> <!-- -->: <span class="lg-highlight-number">11000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"errmsg"</span> <!-- -->: <span class="lg-highlight-string">"E11000 duplicate key error collection: inventory.products index: _id_ dup key: { : 10.0 }"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"op"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">10</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"packing peanuts"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">200</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-insertOne-override-write-concern"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Increase Write Concern <a class="headerlink leafygreen-ui-1kepx47" href="#increase-write-concern" 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="increase-write-concern"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Given a three member replica set, the following operation specifies a <code class="leafygreen-ui-1l06pbn"> w </code> of <code class="leafygreen-ui-1l06pbn"> majority </code> , <code class="leafygreen-ui-1l06pbn"> wtimeout </code> of <code class="leafygreen-ui-1l06pbn"> 100 </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"try {\n db.products.insertOne(\n { \"item\": \"envelopes\", \"qty\": 100, type: \"Self-Sealing\" },\n { writeConcern: { w : \"majority\", wtimeout : 100 } }\n );\n} catch (e) {\n print (e);\n}","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">try</span> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->db.<span class="lg-highlight-property">products</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"item"</span>: <span class="lg-highlight-string">"envelopes"</span>, <span class="lg-highlight-string">"qty"</span>: <span class="lg-highlight-number">100</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Self-Sealing"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">writeConcern</span>: <!-- -->{ <!-- -->w <!-- -->: <span class="lg-highlight-string">"majority"</span>, <!-- -->wtimeout <!-- -->: <span class="lg-highlight-number">100</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} <span class="lg-highlight-keyword">catch</span> <!-- -->(<!-- -->e) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->print <!-- -->(<!-- -->e)<!-- -->;</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> <p class="leafygreen-ui-1kp3ins"> If the acknowledgment takes longer than the <code class="leafygreen-ui-1l06pbn"> wtimeout </code> limit, the following exception is thrown: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"WriteConcernError({\n \"code\" : 64,\n \"errmsg\" : \"waiting for replication timed out\",\n \"errInfo\" : {\n \"wtimeout\" : true,\n \"writeConcern\" : {\n \"w\" : \"majority\",\n \"wtimeout\" : 100,\n \"provenance\" : \"getLastErrorDefaults\"\n }\n }\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"><span class="lg-highlight-title lg-highlight-class">WriteConcernError</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"code"</span> <!-- -->: <span class="lg-highlight-number">64</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"errmsg"</span> <!-- -->: <span class="lg-highlight-string">"waiting for replication timed out"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"errInfo"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"wtimeout"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"writeConcern"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-string">"majority"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"wtimeout"</span> <!-- -->: <span class="lg-highlight-number">100</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"provenance"</span> <!-- -->: <span class="lg-highlight-string">"getLastErrorDefaults"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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 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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To insert multiple documents, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.insertMany/#mongodb-method-db.collection.insertMany"> <code class="leafygreen-ui-1l06pbn"> db.collection.insertMany() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/WriteResult/#mongodb-data-WriteResult.writeConcernError"> <code class="leafygreen-ui-1l06pbn"> WriteResult.writeConcernError </code> </a> </p> </li> </ul> </div> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/js-native/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Native Methods in <code class="leafygreen-ui-1l06pbn"> mongosh </code> <a class="headerlink leafygreen-ui-1kepx47" href="#native-methods-in-mongosh" 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="native-methods-in-mongosh"> </div> </a> </h1> <p class="leafygreen-ui-1kp3ins"> The methods listed in this section are <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> functional replacements for the native methods that were available in the legacy <code class="leafygreen-ui-1l06pbn"> mongo </code> shell. These methods are not exact replacements: output formats and some functionality may differ from the corresponding legacy methods. </p> <p class="leafygreen-ui-1kp3ins"> In addition to these methods, the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb-labs/mongosh-snippets/blob/main/snippets/mongocompat/index.js" rel="noopener noreferrer"> <span> mongocompat snippet </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> provides access to legacy <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> shell APIs. </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"> In the following table <code class="leafygreen-ui-1l06pbn"> &lt;path&gt; </code> and <code class="leafygreen-ui-1l06pbn"> &lt;filename&gt; </code> are strings and should be in quotes. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// process.chdir( &lt;path&gt; )\n\nprocess.chdir( \"./data/incoming\" )","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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"><span class="lg-highlight-comment">// process.chdir( &lt;path&gt; )</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">process.<span class="lg-highlight-title lg-highlight-function">chdir</span>( <span class="lg-highlight-string">"./data/incoming"</span> )</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Legacy Method Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Replacement </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> cat() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns the contents of the specified file </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"fs.readFileSync( &lt;filename&gt;, 'utf8' )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">fs.<span class="lg-highlight-title lg-highlight-function">readFileSync</span>( &lt;<!-- -->filename<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-string">'utf8'</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> <p class="leafygreen-ui-1kp3ins"> The legacy <code class="leafygreen-ui-1l06pbn"> useBinaryMode </code> option is not supported. Emulate the <code class="leafygreen-ui-1l06pbn"> useBinaryMode = false </code> option with: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"fs.readFileSync( &lt;filename&gt;, 'utf8' ).replace( /\\r\\n/g, '\\n' )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">fs.<span class="lg-highlight-title lg-highlight-function">readFileSync</span>( &lt;<!-- -->filename<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-string">'utf8'</span> ).<span class="lg-highlight-title lg-highlight-function">replace</span>( <span class="lg-highlight-regexp">/</span><span class="lg-highlight-regexp">\r</span><span class="lg-highlight-regexp">\n</span><span class="lg-highlight-regexp">/g</span>,<!-- --> <span class="lg-highlight-string">'</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">'</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> cd() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Changes the current working directory to the specified path. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"process.chdir( &lt;path&gt; )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">process.<span class="lg-highlight-title lg-highlight-function">chdir</span>( &lt;<!-- -->path<!-- -->&gt; <!-- -->)</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> getHostName() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns the hostname of the system running <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> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"os.hostname()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">os.<span class="lg-highlight-title lg-highlight-function">hostname</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> getMemInfo() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns a document that reports memory used by the shell. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"process.memoryUsage()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">process.<span class="lg-highlight-title lg-highlight-function">memoryUsage</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> hostname() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns the hostname of the computer running the shell. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"os.hostname()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">os.<span class="lg-highlight-title lg-highlight-function">hostname</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> isInteractive() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns a boolean indicating whether <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> is running in interactive or script mode. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"isInteractive()"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">isInteractive()</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> listFiles() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns an array of documents that give the name and type of each object in the directory. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"fs.readdirSync( &lt;path&gt;, { withFileTypes: true } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">fs.<span class="lg-highlight-title lg-highlight-function">readdirSync</span>( &lt;<!-- -->path<!-- -->&gt;<!-- -->,<!-- --> <!-- -->{ <span class="lg-highlight-attr">withFileTypes</span>: <span class="lg-highlight-literal">true</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> load() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Loads and runs a JavaScript file in the shell. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> load() </code> is available in <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> . See also <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/write-scripts/require-load-differences/#std-label-load-and-require" target="_self"> <span> Differences Between require() and load() <!-- --> . </span> </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> ls() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns a list of the files in the current directory. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"fs.readdirSync( &lt;path&gt; )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">fs.<span class="lg-highlight-title lg-highlight-function">readdirSync</span>( &lt;<!-- -->path<!-- -->&gt; <!-- -->)</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> md5sumFile() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-md5"> md5 </a> hash of the specified file. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"crypto.createHash( 'md5' ).update( fs.readFileSync( &lt;filename&gt; ) ).digest( 'hex' )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">crypto.<span class="lg-highlight-title lg-highlight-function">createHash</span>( <span class="lg-highlight-string">'md5'</span> ).<span class="lg-highlight-title lg-highlight-function">update</span>( <!-- -->fs.<span class="lg-highlight-title lg-highlight-function">readFileSync</span>( &lt;<!-- -->filename<!-- -->&gt; <!-- -->) ).<span class="lg-highlight-title lg-highlight-function">digest</span>( <span class="lg-highlight-string">'hex'</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mkdir() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Creates a directory at the specified path. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"fs.mkdirSync( &lt;path&gt;, { recursive: true } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">fs.<span class="lg-highlight-title lg-highlight-function">mkdirSync</span>( &lt;<!-- -->path<!-- -->&gt;<!-- -->,<!-- --> <!-- -->{ <span class="lg-highlight-attr">recursive</span>: <span class="lg-highlight-literal">true</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> pwd() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns the current directory. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"process.cwd()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">process.<span class="lg-highlight-title lg-highlight-function">cwd</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> quit() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Exits the current shell session. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"quit()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-title lg-highlight-function">quit</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> removeFile() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Removes the specified file from the local file system. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"fs.unlinkSync( &lt;filename&gt; )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">fs.<span class="lg-highlight-title lg-highlight-function">unlinkSync</span>( &lt;<!-- -->filename<!-- -->&gt; <!-- -->)</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> sleep() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Sleep for the specified number of milliseconds. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sleep( &lt;number&gt; )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-title lg-highlight-function">sleep</span>( &lt;<!-- -->number<!-- -->&gt; <!-- -->)</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> version() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns the current version of <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> instance. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"version()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-title lg-highlight-function">version</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> _isWindows() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns <code class="leafygreen-ui-1l06pbn"> true </code> if the shell in running on Windows. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"process.platform === 'win32'","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">process.<span class="lg-highlight-property">platform</span> <!-- -->=== <span class="lg-highlight-string">'win32'</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> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> _rand() </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns a random number between <code class="leafygreen-ui-1l06pbn"> 0 </code> and <code class="leafygreen-ui-1l06pbn"> 1 </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Math.random()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-title lg-highlight-class">Math</span>.<span class="lg-highlight-title lg-highlight-function">random</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> </td> </tr> </tbody> </table> </div> </section>
https://www.mongodb.com/docs/manual/reference/method/db.collection.findOneAndDelete/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> db.collection.findOneAndDelete() <a class="headerlink leafygreen-ui-1kepx47" href="#db.collection.findoneanddelete--" 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="db.collection.findoneanddelete--"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <div class="leafygreen-ui-147elvs"> <p class="leafygreen-ui-1ronz74"> MongoDB with drivers </p> <div class="leafygreen-ui-18k5rfm"> <p class="leafygreen-ui-1kp3ins"> This page documents a <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> method. To see the equivalent method in a MongoDB driver, see the corresponding page for your programming language: </p> </div> <div class="leafygreen-ui-zgrwqu notranslate"> <a class="leafygreen-ui-v22cck" href="https://mongodb.github.io/mongo-csharp-driver/2.29.0/api/MongoDB.Driver/MongoDB.Driver.IMongoCollectionExtensions.FindOneAndDelete.html" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59964)"> <g clip-path="url(#clip1_1351_59964)"> <path d="M25.7709 9.2495C25.7709 8.79827 25.678 8.39408 25.4827 8.04627C25.2874 7.70785 25.0084 7.42586 24.627 7.20025C21.465 5.35781 18.2937 3.51538 15.1317 1.67295C14.2761 1.17474 13.4484 1.19354 12.6021 1.70115C11.3466 2.45316 5.04112 6.10042 3.15321 7.20025C2.3813 7.65142 2 8.34705 2 9.24005C2 12.9531 2 16.6568 2 20.3698C2 20.8117 2.093 21.2064 2.279 21.5449C2.4743 21.8927 2.7626 22.1841 3.15321 22.4191C5.03182 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2761 28.4446 15.1317 27.9463C18.2937 26.1039 21.465 24.2615 24.627 22.4191C25.0177 22.1935 25.306 21.9021 25.5012 21.5449C25.6873 21.2064 25.7803 20.8117 25.7803 20.3698C25.7709 20.3698 25.7709 12.9531 25.7709 9.2495Z" fill="#A179DC"> </path> <path d="M13.9227 14.7673L2.27905 21.5449C2.47435 21.8927 2.76265 22.1841 3.15326 22.4191C5.03187 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2762 28.4445 15.1317 27.9463C18.2938 26.1039 21.4651 24.2615 24.6271 22.4191C25.0177 22.1935 25.306 21.9021 25.5013 21.5449L13.9227 14.7673Z" fill="#280068"> </path> <path d="M25.7711 9.24949C25.7711 8.79827 25.6781 8.39408 25.4828 8.04626L13.9229 14.7768L25.4921 21.5543C25.6781 21.2159 25.7711 20.8211 25.7711 20.3793C25.7711 20.3699 25.7711 12.9531 25.7711 9.24949Z" fill="#390091"> </path> <path d="M20.7771 12.2387V13.5078H22.0325V12.2387H22.6557V13.5078H23.9111V14.1376H22.6557V15.4066H23.9111V16.0364H22.6557V17.3054H22.0325V16.0364H20.7771V17.3054H20.1539V16.0364H18.8984V15.4066H20.1539V14.1376H18.8984V13.5078H20.1539V12.2387H20.7771ZM22.0325 14.1376H20.7771V15.4066H22.0325V14.1376Z" fill="white"> </path> <path d="M13.9508 5.87482C17.2151 5.87482 20.0702 7.67022 21.6047 10.3399L21.5861 10.3117L17.7452 12.5489C16.9919 11.2517 15.5969 10.3775 14.0066 10.3587H13.9601C11.5328 10.3587 9.56116 12.3515 9.56116 14.805C9.56116 15.604 9.77503 16.3654 10.1377 17.014C10.9004 18.3488 12.3232 19.2512 13.9601 19.2512C15.6062 19.2512 17.0384 18.3394 17.7917 16.9858L17.7731 17.014L21.614 19.2606C20.0981 21.9021 17.2895 23.6975 14.0531 23.7257H13.9508C10.6679 23.7257 7.81274 21.9209 6.28753 19.2418C5.54353 17.9352 5.11572 16.4124 5.11572 14.7956C5.11572 9.87931 9.06825 5.87482 13.9508 5.87482Z" fill="white"> </path> </g> </g> <defs> <clippath id="clip0_1351_59964"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59964"> <rect fill="white" height="27" transform="translate(2 1.30966)" width="24"> </rect> </clippath> </defs> </svg> <span> C# </span> </a> <a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/java/sync/current/fundamentals/crud/write-operations/delete/#find-and-delete-a-document" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD"> </path> <path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD"> </path> <path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E"> </path> <path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD"> </path> <path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD"> </path> <path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD"> </path> <path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E"> </path> <path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD"> </path> </svg> <span> Java Sync </span> </a> <a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/node/current/fundamentals/crud/compound-operations/#built-in-methods" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 30" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:R16v5qcmqn9:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R16v5qcmqn9:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":R16v5qcmqn9:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":R16v5qcmqn9:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <span> Node.js </span> </a> <a class="leafygreen-ui-v22cck" href="https://pymongo.readthedocs.io/en/4.8.0/api/pymongo/collection.html#pymongo.collection.Collection.find_one_and_delete" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 111.6 147" width="24" xmlns="http://www.w3.org/2000/svg"> <lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R18v5qcmqn9:aa" x1="280.848" x2="389.865" y1="-268.463" y2="-362.257"> <stop offset="0" stop-color="#5a9fd4"> </stop> <stop offset="1" stop-color="#306998"> </stop> </lineargradient> <path d="M55.3 3.2c-4.6 0-9 .4-12.8 1.1-11.3 2-13.4 6.2-13.4 13.9v10.2h26.8v3.4H19c-7.8 0-14.6 4.7-16.8 13.6C-.3 55.6-.4 62 2.2 72.7c1.9 7.9 6.5 13.6 14.2 13.6h9.2V74c0-8.8 7.7-16.7 16.7-16.7h26.8c7.5 0 13.4-6.1 13.4-13.6V18.2c0-7.3-6.1-12.7-13.4-13.9-4.4-.8-9.2-1.1-13.8-1.1zm-14.5 8.2c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1s2.2-5.1 5-5.1z" fill="url(#:R18v5qcmqn9:aa)"> </path> <lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R18v5qcmqn9:bb" x1="432.011" x2="393.081" y1="-419.025" y2="-363.946"> <stop offset="0" stop-color="#ffd43b"> </stop> <stop offset="1" stop-color="#ffe873"> </stop> </lineargradient> <path d="M86 31.8v11.9c0 9.2-7.8 17-16.8 17H42.5c-7.3 0-13.4 6.3-13.4 13.6v25.5c0 7.3 6.3 11.5 13.4 13.6 8.5 2.5 16.6 2.9 26.8 0 6.8-2 13.4-5.9 13.4-13.6V89.7H55.9v-3.4h40.2c7.8 0 10.7-5.4 13.4-13.6 2.8-8.4 2.7-16.5 0-27.3-1.9-7.8-5.6-13.6-13.4-13.6H86zM71 96.5c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1-.1-2.8 2.2-5.1 5-5.1z" fill="url(#:R18v5qcmqn9:bb)"> </path> <radialgradient cx="-2274.721" cy="144.526" gradienttransform="matrix(0 -.2399 -1.0547 0 208.637 -414.922)" gradientunits="userSpaceOnUse" id=":R18v5qcmqn9:cc" r="29.037"> <stop offset="0" stop-color="#b8b8b8" stop-opacity=".498"> </stop> <stop offset="1" stop-color="#7f7f7f" stop-opacity="0"> </stop> </radialgradient> <path d="M92.1 130.9c0 3.8-16.1 7-35.9 7s-35.9-3.1-35.9-7c0-3.8 16.1-7 35.9-7s35.9 3.1 35.9 7z" fill="url(#:R18v5qcmqn9:cc)" opacity=".444"> </path> </svg> <span> PyMongo </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongoc.org/libmongoc/current/mongoc_collection_delete_one.html" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59955)"> <g clip-path="url(#clip1_1351_59955)"> <path clip-rule="evenodd" d="M13.118 1.49532C13.5403 1.25103 14.0559 1.25103 14.4783 1.49532C16.5652 2.70389 22.8385 6.34889 24.9193 7.55748C25.3416 7.80172 25.6025 8.25176 25.6025 8.74672C25.6025 11.1703 25.6025 18.4539 25.6025 20.8774C25.6025 21.366 25.3416 21.8224 24.9193 22.0667C22.8385 23.2753 16.5652 26.9203 14.4783 28.1289C14.0559 28.3732 13.5403 28.3732 13.118 28.1289C11.0373 26.9139 4.76398 23.2689 2.68323 22.0603C2.26087 21.816 2 21.366 2 20.871C2 18.4474 2 11.1639 2 8.7403C2 8.25176 2.26087 7.7953 2.68323 7.55106C4.76398 6.34889 11.0373 2.70389 13.118 1.49532Z" fill="#004482" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M2.18634 21.4946C2.01863 21.2632 2 21.051 2 20.7553C2 18.351 2 11.1061 2 8.70176C2 8.21317 2.26087 7.76319 2.67702 7.51889C4.75776 6.31675 11.0062 2.69104 13.0807 1.4889C13.5031 1.24461 14.0683 1.25104 14.4907 1.49533C16.5652 2.69747 22.795 6.29104 24.8696 7.49319C25.0373 7.58963 25.1677 7.70535 25.2795 7.86606L2.18634 21.4946Z" fill="#659AD2" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M13.8011 5.8089C18.6024 5.8089 22.4968 9.83964 22.4968 14.8089C22.4968 19.7782 18.6024 23.8089 13.8011 23.8089C8.99986 23.8089 5.10547 19.7782 5.10547 14.8089C5.10547 9.83964 8.99986 5.8089 13.8011 5.8089ZM13.8011 10.3089C16.1987 10.3089 18.1489 12.3275 18.1489 14.8089C18.1489 17.2903 16.1987 19.3089 13.8011 19.3089C11.4036 19.3089 9.4533 17.2903 9.4533 14.8089C9.4533 12.3275 11.4036 10.3089 13.8011 10.3089Z" fill="white" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M25.2857 7.87247C25.6087 8.18102 25.6025 8.65034 25.6025 9.01673C25.6025 11.4596 25.5839 18.396 25.6087 20.8325C25.6087 21.0896 25.528 21.3532 25.4099 21.5589L13.5466 14.8089L25.2857 7.87247Z" fill="#00599C" fill-rule="evenodd"> </path> </g> </g> <defs> <clippath id="clip0_1351_59955"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59955"> <rect fill="white" height="27" transform="translate(2 1.30887)" width="24"> </rect> </clippath> </defs> </svg> <span> C </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongocxx.org/api/current/classmongocxx_1_1v__noabi_1_1collection.html#a37bb101d650aa25d32e585f50e1c2c2f" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59959)"> <g clip-path="url(#clip1_1351_59959)"> <path d="M25.4013 21.5646C25.5872 21.2353 25.7034 20.8745 25.7034 20.5373V9.08012C25.7034 8.75078 25.5872 8.38217 25.4013 8.05283L13.8516 14.8127L25.4013 21.5646Z" fill="#00599C"> </path> <path d="M14.8738 28.0657L24.6729 22.3411C24.9517 22.1764 25.2151 21.8941 25.401 21.5647L13.8513 14.8127L2.30151 21.5647C2.48743 21.8941 2.74305 22.1764 3.02967 22.3411L12.8288 28.0657C13.3865 28.3951 14.316 28.3951 14.8738 28.0657Z" fill="#004482"> </path> <path d="M25.4011 8.06086C25.2152 7.73146 24.9596 7.44915 24.673 7.2845L14.8739 1.55983C14.3084 1.23046 13.3866 1.23046 12.8211 1.55983L3.02202 7.2845C2.46429 7.61385 1.99951 8.42158 1.99951 9.08033V20.5375C1.99951 20.8669 2.11571 21.2354 2.30162 21.5647L13.8514 14.8128L25.4011 8.06086Z" fill="#659AD2"> </path> <path d="M13.8512 22.8115C9.49778 22.8115 5.94995 19.2199 5.94995 14.8127C5.94995 10.4055 9.49778 6.81387 13.8512 6.81387C16.6631 6.81387 19.2813 8.34305 20.6912 10.8133L17.2751 12.813C16.5701 11.5818 15.261 10.8133 13.8512 10.8133C11.6745 10.8133 9.90055 12.6091 9.90055 14.8127C9.90055 17.0163 11.6745 18.8121 13.8512 18.8121C15.261 18.8121 16.5701 18.0436 17.2751 16.8124L20.6912 18.8121C19.2813 21.2745 16.6631 22.8115 13.8512 22.8115Z" fill="white"> </path> <path d="M21.7524 14.3657H20.8771V13.4796H19.994V14.3657H19.1187V15.2518H19.994V16.1458H20.8771V15.2518H21.7524V14.3657Z" fill="white"> </path> <path d="M25.0446 14.3657H24.1693V13.4796H23.2862V14.3657H22.4109V15.2518H23.2862V16.1458H24.1693V15.2518H25.0446V14.3657Z" fill="white"> </path> </g> </g> <defs> <clippath id="clip0_1351_59959"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59959"> <rect fill="white" height="27" transform="translate(1.99951 1.30878)" width="24"> </rect> </clippath> </defs> </svg> <span> C++ </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/go/current/fundamentals/crud/compound-operations/#find-and-delete" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" id="Layer_1" style="fill:#00ACD7" version="1.1" viewbox="0 0 205.4 76.7" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0"> <path class="st00" d="M15.5 23.2c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h35.7c.4 0 .5.3.3.6l-1.7 2.6c-.2.3-.7.6-1 .6l-36.2-.1zM.4 32.4c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h45.6c.4 0 .6.3.5.6l-.8 2.4c-.1.4-.5.6-.9.6l-47.3.1zM24.6 41.6c-.4 0-.5-.3-.3-.6l1.4-2.5c.2-.3.6-.6 1-.6h20c.4 0 .6.3.6.7l-.2 2.4c0 .4-.4.7-.7.7l-21.8-.1z"> </path> <g id="CXHf1q_3_"> <path class="st00" d="M128.4 21.4c-6.3 1.6-10.6 2.8-16.8 4.4-1.5.4-1.6.5-2.9-1-1.5-1.7-2.6-2.8-4.7-3.8-6.3-3.1-12.4-2.2-18.1 1.5-6.8 4.4-10.3 10.9-10.2 19 .1 8 5.6 14.6 13.5 15.7 6.8.9 12.5-1.5 17-6.6.9-1.1 1.7-2.3 2.7-3.7H89.6c-2.1 0-2.6-1.3-1.9-3 1.3-3.1 3.7-8.3 5.1-10.9.3-.6 1-1.6 2.5-1.6h36.4c-.2 2.7-.2 5.4-.6 8.1-1.1 7.2-3.8 13.8-8.2 19.6-7.2 9.5-16.6 15.4-28.5 17-9.8 1.3-18.9-.6-26.9-6.6-7.4-5.6-11.6-13-12.7-22.2-1.3-10.9 1.9-20.7 8.5-29.3C70.4 8.7 79.8 2.8 91.3.7c9.4-1.7 18.4-.6 26.5 4.9 5.3 3.5 9.1 8.3 11.6 14.1.6.9.2 1.4-1 1.7z"> </path> <path class="st00" d="M161.5 76.7c-9.1-.2-17.4-2.8-24.4-8.8-5.9-5.1-9.6-11.6-10.8-19.3-1.8-11.3 1.3-21.3 8.1-30.2 7.3-9.6 16.1-14.6 28-16.7 10.2-1.8 19.8-.8 28.5 5.1 7.9 5.4 12.8 12.7 14.1 22.3 1.7 13.5-2.2 24.5-11.5 33.9-6.6 6.7-14.7 10.9-24 12.8-2.7.5-5.4.6-8 .9zm23.8-40.4c-.1-1.3-.1-2.3-.3-3.3-1.8-9.9-10.9-15.5-20.4-13.3-9.3 2.1-15.3 8-17.5 17.4-1.8 7.8 2 15.7 9.2 18.9 5.5 2.4 11 2.1 16.3-.6 7.9-4.1 12.2-10.5 12.7-19.1z"> </path> </g> </svg> <span> Go </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#findOneAndDelete(org.bson.conversions.Bson)" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD"> </path> <path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD"> </path> <path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E"> </path> <path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD"> </path> <path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD"> </path> <path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD"> </path> <path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E"> </path> <path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD"> </path> </svg> <span> Java RS </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/kotlin/coroutine/current/fundamentals/crud/write-operations/delete/#find-and-delete-a-document" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R1iv5qcmqn9:paint0_linear_211_40588)"> </path> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R1iv5qcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29"> <stop offset="0.00343514" stop-color="#E44857"> </stop> <stop offset="0.4689" stop-color="#C711E1"> </stop> <stop offset="1" stop-color="#7F52FF"> </stop> </lineargradient> </defs> </svg> <span> Kotlin Coroutine </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-kotlin-sync/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/find-one-and-delete.html?query=fun%20findOneAndDelete(clientSession:%20ClientSession,%20filter:%20Bson,%20options:%20FindOneAndDeleteOptions%20=%20FindOneAndDeleteOptions()):%20T?" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R1kv5qcmqn9:paint0_linear_211_40588)"> </path> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R1kv5qcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29"> <stop offset="0.00343514" stop-color="#E44857"> </stop> <stop offset="0.4689" stop-color="#C711E1"> </stop> <stop offset="1" stop-color="#7F52FF"> </stop> </lineargradient> </defs> </svg> <span> Kotlin Sync </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/php-library/current/reference/method/MongoDBCollection-findOneAndDelete/" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 700 301" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0"> <defs> <clippath clippathunits="userSpaceOnUse" id="a"> <path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439"> </path> </clippath> <clippath clippathunits="userSpaceOnUse" id="c"> <path d="M0 324h576V0H0v324z"> </path> </clippath> <clippath clippathunits="userSpaceOnUse" id="d"> <path d="M0 324h576V0H0v324z"> </path> </clippath> <radialgradient cx="0" cy="0" fx="0" fy="0" gradienttransform="matrix(363.05789 0 0 -363.05789 177.52 256.307)" gradientunits="userSpaceOnUse" id="b" r="1" spreadmethod="pad"> <stop offset="0" stop-color="#aeb2d5"> </stop> <stop offset=".3" stop-color="#aeb2d5"> </stop> <stop offset=".75" stop-color="#484c89"> </stop> <stop offset="1" stop-color="#484c89"> </stop> </radialgradient> </defs> <g clip-path="url(#a)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439" fill="url(#b)"> </path> </g> <g clip-path="url(#c)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M288 27.36c146.729 0 265.68 60.28 265.68 134.64 0 74.36-118.951 134.641-265.68 134.641S22.32 236.36 22.32 162.001C22.32 87.64 141.271 27.358 288 27.358" fill="#777bb3"> </path> </g> <g clip-path="url(#d)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M161.734 145.307c12.065 0 21.072 2.225 26.771 6.61 5.638 4.342 9.532 11.863 11.573 22.354 1.903 9.806 1.178 16.653-2.154 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.28l-10.69-55h15.673zm-63.063-67.75a2.998 2.998 0 00-2.944 3.572l28.328 145.75a3 3 0 002.945 2.428h61.054c19.188 0 33.47-5.21 42.447-15.487 9.025-10.331 11.812-24.772 8.283-42.921-1.436-7.394-3.906-14.261-7.34-20.41-3.44-6.154-7.985-11.85-13.512-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.28-3.93-30.548-3.93h-24.722l-7.06-36.321a3 3 0 00-2.944-2.428h-31.75z"> </path> <path d="M159.224 197.307h16.808c13.42 0 18.083-2.945 19.667-4.7 2.628-2.914 3.124-9.058 1.435-17.767-1.898-9.75-5.416-16.663-10.458-20.545-5.162-3.974-13.554-5.988-24.941-5.988H149.7l9.523 49zm28.83 35H127a6 6 0 01-5.89-4.855L92.784 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.588 33.895h22.249c12.582 0 23.174 1.372 31.479 4.077 8.54 2.775 16.399 7.48 23.354 13.984 5.752 5.292 10.49 11.232 14.08 17.657 3.59 6.427 6.17 13.594 7.668 21.302 3.715 19.104.697 34.402-8.97 45.466-9.571 10.958-24.613 16.514-44.705 16.514m-45.633-90h19.313c12.8 0 22.336 2.411 28.6 7.234 6.267 4.824 10.493 12.875 12.689 24.157 2.1 10.832 1.144 18.476-2.871 22.93-4.02 4.452-12.06 6.68-24.121 6.68h-21.754l-11.856-61m45.633 84c18.367 0 31.766-4.82 40.188-14.462 8.42-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.621-3.782-29.621-3.782h-27.196l-7.531-38.75h-31.75L127 226.307h61.055" fill="#fff"> </path> <path d="M311.583 116.307c-.896 0-1.745.4-2.314 1.092a2.994 2.994 0 00-.631 2.48l12.531 64.489c1.192 6.133.898 10.535-.827 12.395-1.056 1.137-4.228 3.044-13.607 3.044h-22.702l-15.755-81.072a3 3 0 00-2.945-2.428h-31.5a2.998 2.998 0 00-2.945 3.572l28.328 145.75a3 3 0 002.945 2.428h31.5a3 3 0 002.945-3.572l-6.836-35.178h24.422c18.605 0 31.221-3.28 38.569-10.028 7.49-6.884 9.827-17.891 6.947-32.72l-13.18-67.824a3 3 0 00-2.945-2.428h-32z"> </path> <path d="M293.661 271.057h-31.5a6 6 0 01-5.89-4.855l-28.328-145.75a5.998 5.998 0 015.89-7.145h31.5a6 6 0 015.89 4.855l15.283 78.645h20.23c9.362 0 11.327-2 11.406-2.086.568-.61 1.315-3.44.082-9.78l-12.53-64.49a5.998 5.998 0 015.89-7.144h32a6 6 0 015.89 4.855l13.178 67.825c3.093 15.921.447 27.864-7.86 35.5-7.929 7.281-21.209 10.82-40.6 10.82h-20.784l6.143 31.605a6.001 6.001 0 01-5.89 7.145m0-6l-7.53-38.75h28.061c17.657 0 29.836-3.082 36.54-9.238 6.702-6.16 8.71-16.14 6.031-29.938l-13.18-67.824h-32l12.531 64.488c1.426 7.336.902 12.34-1.574 15.008-2.477 2.668-7.746 4.004-15.805 4.004H281.56l-16.226-83.5h-31.5l28.328 145.75h31.5" fill="#fff"> </path> <path d="M409.55 145.307c12.065 0 21.072 2.225 26.77 6.61 5.639 4.34 9.533 11.862 11.575 22.354 1.903 9.806 1.178 16.653-2.155 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.281l-10.69-55h15.674zm-63.062-67.75a2.999 2.999 0 00-2.945 3.572l28.328 145.75a3.002 3.002 0 002.946 2.428h61.053c19.189 0 33.47-5.21 42.448-15.487 9.025-10.33 11.81-24.771 8.283-42.921-1.438-7.394-3.907-14.261-7.342-20.41-3.44-6.154-7.984-11.85-13.511-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.281-3.93-30.548-3.93H388.24l-7.057-36.321a3.001 3.001 0 00-2.946-2.428h-31.75z"> </path> <path d="M407.04 197.307h16.807c13.421 0 18.083-2.945 19.667-4.7 2.63-2.914 3.125-9.058 1.435-17.766-1.898-9.75-5.417-16.664-10.458-20.546-5.162-3.974-13.554-5.988-24.94-5.988h-12.034l9.522 49zm28.83 35h-61.054a6 6 0 01-5.889-4.855L340.6 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.587 33.895h22.25c12.581 0 23.173 1.372 31.478 4.077 8.541 2.775 16.401 7.481 23.356 13.986 5.752 5.291 10.488 11.23 14.078 17.655 3.591 6.427 6.171 13.594 7.668 21.302 3.715 19.105.697 34.403-8.969 45.467-9.572 10.957-24.613 16.513-44.706 16.513m-45.632-90h19.312c12.801 0 22.336 2.411 28.601 7.234 6.267 4.824 10.492 12.875 12.688 24.157 2.102 10.832 1.145 18.476-2.87 22.93-4.02 4.452-12.06 6.68-24.122 6.68h-21.754l-11.855-61m45.632 84c18.367 0 31.766-4.82 40.188-14.462 8.422-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.62-3.782-29.62-3.782h-27.197l-7.53-38.75h-31.75l28.328 145.75h61.054" fill="#fff"> </path> </g> </svg> <span> PHP </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/mongoid/master/api/Mongoid/Contextual/Mongo.html#find_one_and_delete-instance_method" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" preserveaspectratio="xMidYMid" viewbox="0 0 300 240" width="24" xmlns="http://www.w3.org/2000/svg"> <defs> <lineargradient id=":R1ov5qcmqn9:a" x1="84.75%" x2="58.254%" y1="111.399%" y2="64.584%"> <stop offset="0%" stop-color="#FB7655"> </stop> <stop offset="0%" stop-color="#FB7655"> </stop> <stop offset="41%" stop-color="#E42B1E"> </stop> <stop offset="99%" stop-color="#900"> </stop> <stop offset="100%" stop-color="#900"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:b" x1="116.651%" x2="1.746%" y1="60.89%" y2="19.288%"> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="99%" stop-color="#911209"> </stop> <stop offset="100%" stop-color="#911209"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:c" x1="75.774%" x2="38.978%" y1="219.327%" y2="7.829%"> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="99%" stop-color="#911209"> </stop> <stop offset="100%" stop-color="#911209"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:d" x1="50.012%" x2="66.483%" y1="7.234%" y2="79.135%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="23%" stop-color="#E57252"> </stop> <stop offset="46%" stop-color="#DE3B20"> </stop> <stop offset="99%" stop-color="#A60003"> </stop> <stop offset="100%" stop-color="#A60003"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:e" x1="46.174%" x2="49.932%" y1="16.348%" y2="83.047%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="23%" stop-color="#E4714E"> </stop> <stop offset="56%" stop-color="#BE1A0D"> </stop> <stop offset="99%" stop-color="#A80D00"> </stop> <stop offset="100%" stop-color="#A80D00"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:f" x1="36.965%" x2="49.528%" y1="15.594%" y2="92.478%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="18%" stop-color="#E46342"> </stop> <stop offset="40%" stop-color="#C82410"> </stop> <stop offset="99%" stop-color="#A80D00"> </stop> <stop offset="100%" stop-color="#A80D00"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:g" x1="13.609%" x2="85.764%" y1="58.346%" y2="-46.717%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="54%" stop-color="#C81F11"> </stop> <stop offset="99%" stop-color="#BF0905"> </stop> <stop offset="100%" stop-color="#BF0905"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:h" x1="27.624%" x2="50.745%" y1="21.135%" y2="79.056%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="31%" stop-color="#DE4024"> </stop> <stop offset="99%" stop-color="#BF190B"> </stop> <stop offset="100%" stop-color="#BF190B"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:i" x1="-20.667%" x2="104.242%" y1="122.282%" y2="-6.342%"> <stop offset="0%" stop-color="#BD0012"> </stop> <stop offset="0%" stop-color="#BD0012"> </stop> <stop offset="7%" stop-color="#FFF"> </stop> <stop offset="17%" stop-color="#FFF"> </stop> <stop offset="27%" stop-color="#C82F1C"> </stop> <stop offset="33%" stop-color="#820C01"> </stop> <stop offset="46%" stop-color="#A31601"> </stop> <stop offset="72%" stop-color="#B31301"> </stop> <stop offset="99%" stop-color="#E82609"> </stop> <stop offset="100%" stop-color="#E82609"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:j" x1="58.792%" x2="11.964%" y1="65.205%" y2="50.128%"> <stop offset="0%" stop-color="#8C0C01"> </stop> <stop offset="0%" stop-color="#8C0C01"> </stop> <stop offset="54%" stop-color="#990C00"> </stop> <stop offset="99%" stop-color="#A80D0E"> </stop> <stop offset="100%" stop-color="#A80D0E"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:k" x1="79.319%" x2="23.088%" y1="62.754%" y2="17.888%"> <stop offset="0%" stop-color="#7E110B"> </stop> <stop offset="0%" stop-color="#7E110B"> </stop> <stop offset="99%" stop-color="#9E0C00"> </stop> <stop offset="100%" stop-color="#9E0C00"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:l" x1="92.88%" x2="59.841%" y1="74.122%" y2="39.704%"> <stop offset="0%" stop-color="#79130D"> </stop> <stop offset="0%" stop-color="#79130D"> </stop> <stop offset="99%" stop-color="#9E120B"> </stop> <stop offset="100%" stop-color="#9E120B"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:o" x1="56.57%" x2="3.105%" y1="101.717%" y2="11.993%"> <stop offset="0%" stop-color="#8B2114"> </stop> <stop offset="0%" stop-color="#8B2114"> </stop> <stop offset="43%" stop-color="#9E100A"> </stop> <stop offset="99%" stop-color="#B3100C"> </stop> <stop offset="100%" stop-color="#B3100C"> </stop> </lineargradient> <lineargradient id=":R1ov5qcmqn9:p" x1="30.87%" x2="92.471%" y1="35.599%" y2="100.694%"> <stop offset="0%" stop-color="#B31000"> </stop> <stop offset="0%" stop-color="#B31000"> </stop> <stop offset="44%" stop-color="#910F08"> </stop> <stop offset="99%" stop-color="#791C12"> </stop> <stop offset="100%" stop-color="#791C12"> </stop> </lineargradient> <radialgradient cx="32.001%" cy="40.21%" fx="32.001%" fy="40.21%" id=":R1ov5qcmqn9:m" r="69.573%"> <stop offset="0%" stop-color="#A80D00"> </stop> <stop offset="0%" stop-color="#A80D00"> </stop> <stop offset="99%" stop-color="#7E0E08"> </stop> <stop offset="100%" stop-color="#7E0E08"> </stop> </radialgradient> <radialgradient cx="13.549%" cy="40.86%" fx="13.549%" fy="40.86%" id=":R1ov5qcmqn9:n" r="88.386%"> <stop offset="0%" stop-color="#A30C00"> </stop> <stop offset="0%" stop-color="#A30C00"> </stop> <stop offset="99%" stop-color="#800E08"> </stop> <stop offset="100%" stop-color="#800E08"> </stop> </radialgradient> </defs> <path d="M197.467 167.764l-145.52 86.41 188.422-12.787L254.88 51.393l-57.414 116.37z" fill="url(#:R1ov5qcmqn9:a)"> </path> <path d="M240.677 241.257L224.482 129.48l-44.113 58.25 60.308 53.528z" fill="url(#:R1ov5qcmqn9:b)"> </path> <path d="M240.896 241.257l-118.646-9.313-69.674 21.986 188.32-12.673z" fill="url(#:R1ov5qcmqn9:c)"> </path> <path d="M52.744 253.955l29.64-97.1L17.16 170.8l35.583 83.154z" fill="url(#:R1ov5qcmqn9:d)"> </path> <path d="M180.358 188.05L153.085 81.226l-78.047 73.16 105.32 33.666z" fill="url(#:R1ov5qcmqn9:e)"> </path> <path d="M248.693 82.73l-73.777-60.256-20.544 66.418 94.321-6.162z" fill="url(#:R1ov5qcmqn9:f)"> </path> <path d="M214.191.99L170.8 24.97 143.424.669l70.767.322z" fill="url(#:R1ov5qcmqn9:g)"> </path> <path d="M0 203.372l18.177-33.151-14.704-39.494L0 203.372z" fill="url(#:R1ov5qcmqn9:h)"> </path> <path d="M2.496 129.48l14.794 41.963 64.283-14.422 73.39-68.207 20.712-65.787L143.063 0 87.618 20.75c-17.469 16.248-51.366 48.396-52.588 49-1.21.618-22.384 40.639-32.534 59.73z" fill="#FFF"> </path> <path d="M54.442 54.094c37.86-37.538 86.667-59.716 105.397-40.818 18.72 18.898-1.132 64.823-38.992 102.349-37.86 37.525-86.062 60.925-104.78 42.027-18.73-18.885.515-66.032 38.375-103.558z" fill="url(#:R1ov5qcmqn9:i)"> </path> <path d="M52.744 253.916l29.408-97.409 97.665 31.376c-35.312 33.113-74.587 61.106-127.073 66.033z" fill="url(#:R1ov5qcmqn9:j)"> </path> <path d="M155.092 88.622l25.073 99.313c29.498-31.016 55.972-64.36 68.938-105.603l-94.01 6.29z" fill="url(#:R1ov5qcmqn9:k)"> </path> <path d="M248.847 82.833c10.035-30.282 12.35-73.725-34.966-81.791l-38.825 21.445 73.791 60.346z" fill="url(#:R1ov5qcmqn9:l)"> </path> <path d="M0 202.935c1.39 49.979 37.448 50.724 52.808 51.162l-35.48-82.86L0 202.935z" fill="#9E1209"> </path> <path d="M155.232 88.777c22.667 13.932 68.35 41.912 69.276 42.426 1.44.81 19.695-30.784 23.838-48.64l-93.114 6.214z" fill="url(#:R1ov5qcmqn9:m)"> </path> <path d="M82.113 156.507l39.313 75.848c23.246-12.607 41.45-27.967 58.121-44.42l-97.434-31.428z" fill="url(#:R1ov5qcmqn9:n)"> </path> <path d="M17.174 171.34l-5.57 66.328c10.51 14.357 24.97 15.605 40.136 14.486-10.973-27.311-32.894-81.92-34.566-80.814z" fill="url(#:R1ov5qcmqn9:o)"> </path> <path d="M174.826 22.654l78.1 10.96c-4.169-17.662-16.969-29.06-38.787-32.623l-39.313 21.663z" fill="url(#:R1ov5qcmqn9:p)"> </path> </svg> <span> Mongoid </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/rust/current/fundamentals/crud/compound-operations/#find-and-delete-a-document" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 30 30" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_5454_14623)"> <path d="M15.2561 3.08398C8.56014 3.08398 3.11035 8.53634 3.11035 15.2297C3.11035 21.9231 8.56271 27.3755 15.2561 27.3755C21.9495 27.3755 27.4019 21.9231 27.4019 15.2297C27.4019 8.53634 21.9495 3.08398 15.2561 3.08398ZM15.2381 4.16315C15.4458 4.16853 15.6432 4.25509 15.7881 4.40437C15.9331 4.55365 16.0142 4.75384 16.0141 4.96225C16.0141 5.17418 15.9299 5.37744 15.7801 5.5273C15.6302 5.67715 15.4269 5.76134 15.215 5.76134C15.0031 5.76134 14.7998 5.67715 14.65 5.5273C14.5001 5.37744 14.4159 5.17418 14.4159 4.96225C14.4159 4.85533 14.4373 4.7495 14.4789 4.65101C14.5205 4.55252 14.5814 4.46338 14.6581 4.38887C14.7347 4.31435 14.8256 4.25598 14.9252 4.21721C15.0249 4.17844 15.1313 4.16006 15.2381 4.16315ZM17.0676 5.47871C18.4704 5.74146 19.7992 6.30644 20.9617 7.13439C22.1242 7.96235 23.0926 9.03345 23.7995 10.2733L22.8565 12.4008C22.6947 12.7682 22.8617 13.1999 23.2265 13.3643L25.0406 14.1686C25.0968 14.7356 25.1037 15.3065 25.0611 15.8747H24.0513C23.9511 15.8747 23.91 15.9415 23.91 16.0391V16.5016C23.91 17.5911 23.2959 17.83 22.7563 17.8891C22.2424 17.9482 21.6746 17.6733 21.6026 17.3598C21.2994 15.6563 20.7958 15.294 19.9993 14.6645C20.9885 14.0375 22.0163 13.11 22.0163 11.8715C22.0163 10.5328 21.099 9.69002 20.4747 9.27634C19.5959 8.69822 18.6247 8.5826 18.3626 8.5826H7.93063C9.37312 6.97114 11.3066 5.88021 13.4318 5.47871L14.6626 6.76857C14.9401 7.05891 15.4 7.07176 15.6903 6.79169L17.0676 5.47871ZM5.71063 11.3936C5.91853 11.3996 6.11589 11.4864 6.26079 11.6356C6.40568 11.7849 6.48669 11.9847 6.4866 12.1927C6.4866 12.4046 6.40241 12.6079 6.25255 12.7577C6.10269 12.9076 5.89944 12.9918 5.6875 12.9918C5.47557 12.9918 5.27232 12.9076 5.12246 12.7577C4.9726 12.6079 4.88841 12.4046 4.88841 12.1927C4.88836 12.0858 4.90977 11.9799 4.95137 11.8814C4.99297 11.7829 5.0539 11.6938 5.13057 11.6193C5.20724 11.5448 5.29809 11.4864 5.39772 11.4476C5.49736 11.4089 5.60376 11.3905 5.71063 11.3936ZM24.7631 11.4295C24.971 11.4356 25.1683 11.5224 25.3132 11.6716C25.4581 11.8208 25.5391 12.0206 25.539 12.2286C25.539 12.4406 25.4548 12.6438 25.305 12.7937C25.1551 12.9435 24.9519 13.0277 24.7399 13.0277C24.528 13.0277 24.3247 12.9435 24.1749 12.7937C24.025 12.6438 23.9408 12.4406 23.9408 12.2286C23.9408 12.1217 23.9622 12.0159 24.0038 11.9174C24.0454 11.8189 24.1063 11.7298 24.183 11.6553C24.2597 11.5807 24.3505 11.5224 24.4502 11.4836C24.5498 11.4448 24.6562 11.4264 24.7631 11.4295ZM7.21632 11.558H8.60896V17.8377H5.79799C5.45083 16.6186 5.34264 15.3439 5.47938 14.0838L7.20091 13.3181C7.56834 13.1536 7.73535 12.7245 7.57091 12.3571L7.21632 11.558ZM13.0284 11.6248H16.3456C16.5177 11.6248 17.5558 11.8227 17.5558 12.6012C17.5558 13.2461 16.7592 13.4774 16.104 13.4774H13.0258L13.0284 11.6248ZM13.0284 16.1368H15.5696C15.8008 16.1368 16.8106 16.2036 17.1318 17.4934C17.232 17.8891 17.4556 19.179 17.6072 19.5927C17.7588 20.0552 18.3729 20.9802 19.0281 20.9802H23.1751C22.8972 21.3524 22.5933 21.7044 22.2656 22.0336L20.5774 21.6713C20.1843 21.5866 19.7963 21.8384 19.7115 22.2315L19.3107 24.102C18.0217 24.6859 16.622 24.9848 15.2069 24.9781C13.7919 24.9714 12.395 24.6595 11.1116 24.0635L10.7108 22.1929C10.626 21.7998 10.2406 21.548 9.84743 21.6328L8.19528 21.9874C7.88869 21.6711 7.6037 21.3346 7.34223 20.9802H15.3769C15.4668 20.9802 15.5285 20.9647 15.5285 20.88V18.0381C15.5285 17.9559 15.4668 17.9379 15.3769 17.9379H13.0258L13.0284 16.1368ZM9.3207 22.6452C9.5286 22.6512 9.72596 22.738 9.87085 22.8872C10.0157 23.0364 10.0968 23.2363 10.0967 23.4443C10.0967 23.6562 10.0125 23.8594 9.86262 24.0093C9.71276 24.1592 9.50951 24.2434 9.29757 24.2434C9.08564 24.2434 8.88239 24.1592 8.73253 24.0093C8.58267 23.8594 8.49848 23.6562 8.49848 23.4443C8.49843 23.3373 8.51984 23.2315 8.56144 23.133C8.60303 23.0345 8.66397 22.9454 8.74064 22.8709C8.81731 22.7964 8.90815 22.738 9.00779 22.6992C9.10743 22.6605 9.21383 22.6421 9.3207 22.6452ZM21.153 22.6811C21.3609 22.6872 21.5583 22.774 21.7031 22.9232C21.848 23.0724 21.929 23.2722 21.929 23.4802C21.929 23.6922 21.8448 23.8954 21.6949 24.0453C21.5451 24.1951 21.3418 24.2793 21.1299 24.2793C20.9179 24.2793 20.7147 24.1951 20.5648 24.0453C20.415 23.8954 20.3308 23.6922 20.3308 23.4802C20.3307 23.3733 20.3521 23.2675 20.3937 23.169C20.4353 23.0705 20.4963 22.9814 20.5729 22.9068C20.6496 22.8323 20.7404 22.774 20.8401 22.7352C20.9397 22.6964 21.0461 22.678 21.153 22.6811Z" fill="black"> </path> <path clip-rule="evenodd" d="M26.7232 15.2304C26.7232 18.2717 25.515 21.1885 23.3645 23.3391C21.2139 25.4896 18.2971 26.6978 15.2558 26.6978C12.2144 26.6978 9.29761 25.4896 7.14705 23.3391C4.99649 21.1885 3.78832 18.2717 3.78832 15.2304C3.78832 12.189 4.99649 9.27222 7.14705 7.12166C9.29761 4.9711 12.2144 3.76293 15.2558 3.76293C18.2971 3.76293 21.2139 4.9711 23.3645 7.12166C25.515 9.27222 26.7232 12.189 26.7232 15.2304ZM26.5073 14.1229L28.2957 15.2304L26.5073 16.3378L28.0439 17.7741L26.0757 18.5115L27.3039 20.2202L25.2252 20.5594L26.0988 22.4762L23.9944 22.4017L24.4775 24.4521L22.4271 23.969L22.5016 26.0734L20.5848 25.1998L20.2456 27.2785L18.5369 26.0503L17.7995 28.0185L16.3632 26.482L15.2558 28.2703L14.1483 26.482L12.712 28.0185L11.9746 26.0503L10.2659 27.2785L9.92672 25.1998L8.00992 26.0734L8.08443 23.969L6.03401 24.4521L6.51707 22.4017L4.4127 22.4762L5.28631 20.5594L3.20763 20.2202L4.43582 18.5115L2.46763 17.7741L4.00415 16.3378L2.21582 15.2304L4.00415 14.1229L2.46763 12.6866L4.43582 11.9492L3.20763 10.2405L5.28631 9.90133L4.4127 7.98453L6.51707 8.05904L6.03401 6.00862L8.08443 6.49168L8.00992 4.3873L9.92672 5.26092L10.2659 3.18223L11.9746 4.41043L12.712 2.44224L14.1483 3.97876L15.2558 2.19043L16.3632 3.97876L17.7995 2.44224L18.5369 4.41043L20.2456 3.18223L20.5848 5.26092L22.5016 4.3873L22.4271 6.49168L24.4775 6.00862L23.9944 8.05904L26.0988 7.98453L25.2252 9.90133L27.3039 10.2405L26.0757 11.9492L28.0439 12.6866L26.5073 14.1229Z" fill="black" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"> </path> </g> <defs> <clippath id="clip0_5454_14623"> <rect fill="black" height="30" width="30"> </rect> </clippath> </defs> </svg> <span> Rust </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongo-scala-driver/org/mongodb/scala/MongoCollection.html#findOneAndDelete(clientSession:org.mongodb.scala.ClientSession,filter:org.mongodb.scala.bson.conversions.Bson,options:org.mongodb.scala.model.FindOneAndDeleteOptions):org.mongodb.scala.SingleObservable[TResult]" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 70 70" width="24" xmlns="http://www.w3.org/2000/svg"> <defs> <lineargradient id=":R1sv5qcmqn9:aaa" x1=".006%" x2="96.837%" y1="49.998%" y2="49.998%"> <stop offset="0%" stop-color="#CD413F"> </stop> <stop offset="75.091%" stop-color="#CD4543"> </stop> <stop offset="100%" stop-color="#D04543"> </stop> </lineargradient> </defs> <g fill="none" fill-rule="nonzero"> <path d="M13 39v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 36.745 13 38.157 13 39M13 20v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 17.745 13 19.157 13 20" fill="#731818"> </path> <g fill="url(#:R1sv5qcmqn9:aaa)" transform="translate(13)"> <path d="M0 29.53v14.766c0-1.232 39-3.692 39-9.844V19.686c0 6.152-39 8.612-39 9.844M0 9.843V24.61c0-1.231 39-3.691 39-9.843V0C39 6.152 0 8.612 0 9.843M0 49.216v14.766c0-1.231 39-3.691 39-9.843V39.373c0 6.151-39 8.612-39 9.843"> </path> </g> </g> </svg> <span> Scala </span> </a> </div> <button class="leafygreen-ui-ki2t97"> Show all <svg aria-label="Chevron Down Icon" class="" fill="none" height="16" role="img" viewbox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"> <path clip-rule="evenodd" d="M1.636 5.364a1 1 0 0 0 0 1.414l4.95 4.95.707.707a1 1 0 0 0 1.414 0l.707-.707 4.95-4.95a1 1 0 0 0 0-1.414l-.707-.707a1 1 0 0 0-1.414 0L8 8.899 3.757 4.657a1 1 0 0 0-1.414 0l-.707.707Z" fill="currentColor" fill-rule="evenodd"> </path> </svg> </button> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndDelete( filter, options ) </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.collection.findOneAndDelete" title="Permalink to this definition"> <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="mongodb-method-db.collection.findOneAndDelete"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Deletes a single document based on the <code class="leafygreen-ui-1l06pbn"> filter </code> and <code class="leafygreen-ui-1l06pbn"> sort </code> criteria, returning the deleted document. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndDelete" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findOneAndDelete() </code> </span> </a> method has the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.findOneAndDelete(\n &lt;filter&gt;,\n {\n writeConcern: &lt;document&gt;,\n projection: &lt;document&gt;,\n sort: &lt;document&gt;,\n maxTimeMS: &lt;number&gt;,\n collation: &lt;document&gt;\n }\n)"} </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.collection.findOneAndDelete(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> &lt;filter&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> writeConcern: &lt;document&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> projection: &lt;document&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> sort: &lt;document&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> maxTimeMS: &lt;number&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> collation: &lt;document&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndDelete" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findOneAndDelete() </code> </span> </a> method takes the following parameters: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Parameter </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> filter </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> The selection criteria for the deletion. The same <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/#std-label-query-selectors"> query selectors </a> as in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find"> <code class="leafygreen-ui-1l06pbn"> find() </code> </a> method are available. </p> <p class="leafygreen-ui-1kp3ins"> Specify an empty document <code class="leafygreen-ui-1l06pbn"> { } </code> to delete the first document returned in the collection. </p> <p class="leafygreen-ui-1kp3ins"> If unspecified, defaults to an empty document. </p> <p class="leafygreen-ui-1kp3ins"> If the query argument is not a document, the operation errors. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> writeConcern </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A document expressing the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern"> write concern </a> . Omit to use the default write concern. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ w: &lt;value&gt;, j: &lt;boolean&gt;, wtimeout: &lt;number&gt; }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">w</span>: &lt;<!-- -->value<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">j</span>: &lt;<!-- -->boolean<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">wtimeout</span>: &lt;<!-- -->number<!-- -->&gt; <!-- -->}</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"> See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-delete-a-document-using-writeconcern" target="_self"> <span> Delete A Document Using WriteConcern </span> </a> for usage. </p> <p class="leafygreen-ui-1kp3ins"> Do not explicitly set the write concern for the operation if run in a transaction. To use write concern with transactions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern"> Transactions and Write Concern <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> projection </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A subset of fields to return. </p> <p class="leafygreen-ui-1kp3ins"> To return all fields in the returned document, omit this parameter. </p> <p class="leafygreen-ui-1kp3ins"> If the projection argument is not a document, the operation errors. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> sort </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. Specifies a sorting order for the documents matched by the <code class="leafygreen-ui-1l06pbn"> filter </code> . </p> <p class="leafygreen-ui-1kp3ins"> If the sort argument is not a document, the operation errors. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#mongodb-method-cursor.sort"> <code class="leafygreen-ui-1l06pbn"> cursor.sort() </code> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> maxTimeMS </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> number </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Optional. Specifies a time limit in milliseconds within which the operation must complete within. Throws an error if the limit is exceeded. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> collation </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. </p> <p class="leafygreen-ui-1kp3ins"> Specifies the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> collation </a> to use for the operation. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> Collation </a> allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks. </p> <p class="leafygreen-ui-1kp3ins"> The collation option has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"collation: {\n locale: &lt;string&gt;,\n caseLevel: &lt;boolean&gt;,\n caseFirst: &lt;string&gt;,\n strength: &lt;int&gt;,\n numericOrdering: &lt;boolean&gt;,\n alternate: &lt;string&gt;,\n maxVariable: &lt;string&gt;,\n backwards: &lt;boolean&gt;\n}"} </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">collation: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> locale: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> caseLevel: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> caseFirst: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> strength: &lt;int&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> numericOrdering: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> alternate: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> maxVariable: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> backwards: &lt;boolean&gt;</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> <p class="leafygreen-ui-1kp3ins"> When specifying collation, the <code class="leafygreen-ui-1l06pbn"> locale </code> field is mandatory; all other collation fields are optional. For descriptions of the fields, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation-document-fields"> Collation Document <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> If the collation is unspecified but the collection has a default collation (see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.createCollection/#mongodb-method-db.createCollection"> <code class="leafygreen-ui-1l06pbn"> db.createCollection() </code> </a> ), the operation uses the collation specified for the collection. </p> <p class="leafygreen-ui-1kp3ins"> If no collation is specified for the collection or for the operations, MongoDB uses the simple binary comparison used in prior versions for string comparisons. </p> <p class="leafygreen-ui-1kp3ins"> You cannot specify multiple collations for an operation. For example, you cannot specify different collations per field, or if performing a find with a sort, you cannot use one collation for the find and another for the sort. </p> </div> </div> </td> </tr> </tbody> </table> </div> <table class="css-11h39yh e1nex8bq0"> <colgroup> <col class="field-name"/> <col class="field-body"/> </colgroup> <tbody> <tr class="css-x8snli"> <th> Returns <!-- --> : </th> <td> Returns the deleted document. </td> </tr> </tbody> </table> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Document Match <a class="headerlink leafygreen-ui-1kepx47" href="#document-match" 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="document-match"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndDelete" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findOneAndDelete() </code> </span> </a> deletes the first matching document in the collection that matches the <code class="leafygreen-ui-1l06pbn"> filter </code> . The <code class="leafygreen-ui-1l06pbn"> sort </code> parameter can be used to influence which document is deleted. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Projection <a class="headerlink leafygreen-ui-1kepx47" href="#projection" 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="projection"> </div> </a> </h3> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Language Consistency </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> As part of making <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find"> <code class="leafygreen-ui-1l06pbn"> find() </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify"> <code class="leafygreen-ui-1l06pbn"> findAndModify() </code> </a> projection consistent with aggregation's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> stage, </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find"> <code class="leafygreen-ui-1l06pbn"> find() </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify"> <code class="leafygreen-ui-1l06pbn"> findAndModify() </code> </a> projection can accept <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> aggregation expressions and syntax <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> MongoDB enforces additional restrictions with regards to projections. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#mongodb-limit-Projection-Restrictions"> Projection Restrictions </a> for details. </p> </li> </ul> </div> </div> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> projection </code> parameter takes a document in the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ field1: &lt;value&gt;, field2: &lt;value&gt; ... }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">field1</span>: &lt;<!-- -->value<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">field2</span>: &lt;<!-- -->value<!-- -->&gt; <!-- -->...<!-- --> }</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 class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:40%"/> <col style="width:60%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Projection </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> &lt;field&gt;: &lt;1 or true&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Specifies the inclusion of a field. If you specify a non-zero integer for the projection value, the operation treats the value as <code class="leafygreen-ui-1l06pbn"> true </code> . </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> &lt;field&gt;: &lt;0 or false&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Specifies the exclusion of a field. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> "&lt;field&gt;.$": &lt;1 or true&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/positional/#mongodb-projection-proj.-"> <code class="leafygreen-ui-1l06pbn"> $ </code> </a> array projection operator to return the first element that matches the query condition on the array field. If you specify a non-zero integer for the projection value, the operation treats the value as <code class="leafygreen-ui-1l06pbn"> true </code> . </p> <p class="leafygreen-ui-1kp3ins"> Not available for <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page"> views <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> &lt;field&gt;: &lt;array projection&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Uses the array projection operators ( <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/elemMatch/#mongodb-projection-proj.-elemMatch"> <code class="leafygreen-ui-1l06pbn"> $elemMatch </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/slice/#mongodb-projection-proj.-slice"> <code class="leafygreen-ui-1l06pbn"> $slice </code> </a> ) to specify the array elements to include. </p> <p class="leafygreen-ui-1kp3ins"> Not available for <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page"> views <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> &lt;field&gt;: &lt;aggregation expression&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Specifies the value of the projected field. </p> <p class="leafygreen-ui-1kp3ins"> With the use of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> aggregation expressions and syntax </a> , including the use of literals and aggregation variables, you can project new fields or project existing fields with new values. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If you specify a non-numeric, non-boolean literal (such as a literal string or an array or an operator expression) for the projection value, the field is projected with the new value, for example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: [ 1, 2, 3, "$someExistingField" ] } </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: "New String Value" } </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: { status: "Active", total: { $sum: "$existingArray" } } } </code> </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To project a literal value for a field, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal"> <code class="leafygreen-ui-1l06pbn"> $literal </code> </a> aggregation expression, for example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: { $literal: 5 } } </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: { $literal: true } } </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: { $literal: { fieldWithValue0: 0, fieldWithValue1: 1 } } } </code> </p> </li> </ul> </li> </ul> </div> </div> </td> </tr> </tbody> </table> </div> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Embedded Field Specification <a class="headerlink leafygreen-ui-1kepx47" href="#embedded-field-specification" 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="embedded-field-specification"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> For fields in an embedded documents, you can specify the field using either: </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/document/#std-label-document-dot-notation-embedded-fields"> dot notation </a> , for example <code class="leafygreen-ui-1l06pbn"> "field.nestedfield": &lt;value&gt; </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> nested form, for example <code class="leafygreen-ui-1l06pbn"> { field: { nestedfield: &lt;value&gt; } } </code> </p> </li> </ul> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> <code class="leafygreen-ui-1l06pbn"> _id </code> Field Projection <a class="headerlink leafygreen-ui-1kepx47" href="#_id-field-projection" 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="_id-field-projection"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> _id </code> field is included in the returned documents by default unless you explicitly specify <code class="leafygreen-ui-1l06pbn"> _id: 0 </code> in the projection to suppress the field. </p> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Inclusion or Exclusion <a class="headerlink leafygreen-ui-1kepx47" href="#inclusion-or-exclusion" 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="inclusion-or-exclusion"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> projection </code> <em> cannot </em> contain <em> both </em> include and exclude specifications, with the exception of the <code class="leafygreen-ui-1l06pbn"> _id </code> field: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> In projections that <em> explicitly include </em> fields, the <code class="leafygreen-ui-1l06pbn"> _id </code> field is the only field that you can <em> explicitly exclude </em> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> In projections that <em> explicitly excludes </em> fields, the <code class="leafygreen-ui-1l06pbn"> _id </code> field is the only field that you can <em> explicitly include </em> ; however, the <code class="leafygreen-ui-1l06pbn"> _id </code> field is included by default. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For more information on projection, see also: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/project-fields-from-query-results/#std-label-read-operations-projection"> Project Fields to Return from Query </a> </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-method-findOneAndDelete-sharded-collection"> </span> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Sharded Collections <a class="headerlink leafygreen-ui-1kepx47" href="#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-collections"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> When using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndDelete" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndDelete() </code> </span> </a> against a sharded collection, the <code class="leafygreen-ui-1l06pbn"> query </code> <strong> must </strong> contain an equality condition on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Documents in a sharded collection can be <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key-missing"> missing the shard key fields </a> . To target a document that is missing the shard key, you can use the <code class="leafygreen-ui-1l06pbn"> null </code> equality match <strong class="css-4dei7l"> in conjunction with </strong> another filter condition (such as on the <code class="leafygreen-ui-1l06pbn"> _id </code> field). For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: &lt;value&gt;, &lt;shardkeyfield&gt;: null } // _id of the document missing shard key","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: &lt;<!-- -->value<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->shardkeyfield<!-- -->&gt;<!-- -->: <span class="lg-highlight-literal">null</span> } <span class="lg-highlight-comment">// _id of</span><span class="lg-highlight-comment"> the document missing </span><span class="lg-highlight-comment">shard key</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" 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> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndDelete" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndDelete() </code> </span> </a> can be used inside <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> distributed transactions <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Do not explicitly set the write concern for the operation if run in a transaction. To use write concern with transactions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern"> Transactions and Write Concern <!-- --> . </a> </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> In most cases, a distributed transaction incurs a greater performance cost over single document writes, and the availability of distributed transactions should not be a replacement for effective schema design. For many scenarios, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding"> denormalized data model (embedded documents and arrays) </a> will continue to be optimal for your data and use cases. That is, for many scenarios, modeling your data appropriately will minimize the need for distributed transactions. </p> <p class="leafygreen-ui-1kp3ins"> For additional transactions usage considerations (such as runtime limit and oplog size limit), see also <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-production-consideration/#std-label-production-considerations"> Production Considerations <!-- --> . </a> </p> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Oplog Entries <a class="headerlink leafygreen-ui-1kepx47" href="#oplog-entries" 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="oplog-entries"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If a <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndDelete() </code> operation successfully deletes a document, the operation adds an entry on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> (operations log). If the operation fails or does not find a document to delete, the operation does not add an entry on the oplog. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndDelete-examples"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndDelete-example-replace-document"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Delete A Document <a class="headerlink leafygreen-ui-1kepx47" href="#delete-a-document" 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="delete-a-document"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> scores </code> collection contains documents similar to the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":" db.scores.insertMany( [\n { _id: 6305, name : \"A. MacDyver\", \"assignment\" : 5, \"points\" : 24 },\n { _id: 6308, name : \"B. Batlock\", \"assignment\" : 3, \"points\" : 22 },\n { _id: 6312, name : \"M. Tagnum\", \"assignment\" : 5, \"points\" : 30 },\n { _id: 6319, name : \"R. Stiles\", \"assignment\" : 2, \"points\" : 12 },\n { _id: 6322, name : \"A. MacDyver\", \"assignment\" : 2, \"points\" : 14 },\n { _id: 6234, name : \"R. Stiles\", \"assignment\" : 1, \"points\" : 10 }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"> db.<span class="lg-highlight-property">scores</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6305</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">24</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6308</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"B. Batlock"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">22</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6312</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"M. Tagnum"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">30</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6319</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"R. Stiles"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">12</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6322</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">14</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6234</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"R. Stiles"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">10</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> <p class="leafygreen-ui-1kp3ins"> The following operation finds the first document where <code class="leafygreen-ui-1l06pbn"> name : M. Tagnum </code> and deletes it: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.scores.findOneAndDelete(\n { \"name\" : \"M. Tagnum\" }\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">db.<span class="lg-highlight-property">scores</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndDelete</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"M. Tagnum"</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the <em> original </em> document that has been deleted: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 6312, name: \"M. Tagnum\", \"assignment\" : 5, \"points\" : 30 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6312</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"M. Tagnum"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">30</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-delete-a-document-using-writeconcern"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Delete A Document Using WriteConcern <a class="headerlink leafygreen-ui-1kepx47" href="#delete-a-document-using-writeconcern" 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="delete-a-document-using-writeconcern"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> scores </code> collection contains documents similar to the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.scores.insertMany( [\n { _id: 6305, name : \"A. MacDyver\", \"assignment\" : 5, \"points\" : 24 },\n { _id: 6308, name : \"B. Batlock\", \"assignment\" : 3, \"points\" : 22 },\n { _id: 6312, name : \"M. Tagnum\", \"assignment\" : 5, \"points\" : 30 },\n { _id: 6319, name : \"R. Stiles\", \"assignment\" : 2, \"points\" : 12 },\n { _id: 6322, name : \"A. MacDyver\", \"assignment\" : 2, \"points\" : 14 },\n { _id: 6234, name : \"R. Stiles\", \"assignment\" : 1, \"points\" : 10 }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">scores</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6305</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">24</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6308</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"B. Batlock"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">22</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6312</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"M. Tagnum"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">30</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6319</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"R. Stiles"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">12</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6322</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">14</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6234</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"R. Stiles"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">10</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> <p class="leafygreen-ui-1kp3ins"> The following operation uses a write concern document inside of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndDelete" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndDelete() </code> </span> </a> method with options: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> w:1 </code> to requests acknowledgment that the write operation has propagated to the standalone mongod or the primary in a replica set. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> j:true </code> to tell the number of MongoDB instances specified in <code class="leafygreen-ui-1l06pbn"> w:1 </code> to have the delete written to on-disk journel. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> wtimeout : 1000 </code> to specify a time limit, in milliseconds, for the write concern. <code class="leafygreen-ui-1l06pbn"> wtimeout </code> is only applicable for <code class="leafygreen-ui-1l06pbn"> w </code> values greater than 1. </p> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.scores.findOneAndDelete(\n { name: \"A. MacDyver\" },\n {\n writeConcern: {\n w : 1,\n j : true,\n wtimeout : 1000\n }\n }\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">db.<span class="lg-highlight-property">scores</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndDelete</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"A. MacDyver"</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">writeConcern</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->w <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->j <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->wtimeout <!-- -->: <span class="lg-highlight-number">1000</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 6305, name: 'A. MacDyver', assignment: 5, points: 24 }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6305</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'A. MacDyver'</span>, <span class="lg-highlight-attr">assignment</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">points</span>: <span class="lg-highlight-number">24</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> The document is deleted with the writeConcern options specified. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndDelete-example-sort-and-replace-document"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Sort And Delete A Document <a class="headerlink leafygreen-ui-1kepx47" href="#sort-and-delete-a-document" 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="sort-and-delete-a-document"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> scores </code> collection contains documents similar to the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.scores.insertMany( [\n { _id: 6305, name : \"A. MacDyver\", \"assignment\" : 5, \"points\" : 24 },\n { _id: 6308, name : \"B. Batlock\", \"assignment\" : 3, \"points\" : 22 },\n { _id: 6312, name : \"M. Tagnum\", \"assignment\" : 5, \"points\" : 30 },\n { _id: 6319, name : \"R. Stiles\", \"assignment\" : 2, \"points\" : 12 },\n { _id: 6322, name : \"A. MacDyver\", \"assignment\" : 2, \"points\" : 14 },\n { _id: 6234, name : \"R. Stiles\", \"assignment\" : 1, \"points\" : 10 }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">scores</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6305</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">24</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6308</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"B. Batlock"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">22</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6312</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"M. Tagnum"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">30</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6319</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"R. Stiles"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">12</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6322</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">14</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6234</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"R. Stiles"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">10</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> <p class="leafygreen-ui-1kp3ins"> The following operation first finds all documents where <code class="leafygreen-ui-1l06pbn"> name : "A. MacDyver" </code> . It then sorts by <code class="leafygreen-ui-1l06pbn"> points </code> ascending before deleting the document with the lowest points value: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.scores.findOneAndDelete(\n { \"name\" : \"A. MacDyver\" },\n { sort : { \"points\" : 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">db.<span class="lg-highlight-property">scores</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndDelete</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->sort <!-- -->: <!-- -->{ <span class="lg-highlight-string">"points"</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the <em> original </em> document that has been deleted: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 6322, name: \"A. MacDyver\", \"assignment\" : 2, \"points\" : 14 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6322</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">14</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndDelete-example-project-deleted-document"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Projecting the Deleted Document <a class="headerlink leafygreen-ui-1kepx47" href="#projecting-the-deleted-document" 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="projecting-the-deleted-document"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following operation uses projection to only return the <code class="leafygreen-ui-1l06pbn"> _id </code> and <code class="leafygreen-ui-1l06pbn"> assignment </code> fields in the returned document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.scores.findOneAndDelete(\n { \"name\" : \"A. MacDyver\" },\n { sort : { \"points\" : 1 }, projection: { \"assignment\" : 1 } }\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">scores</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndDelete</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->sort <!-- -->: <!-- -->{ <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-attr">projection</span>: <!-- -->{ <span class="lg-highlight-string">"assignment"</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the <em> original </em> document with the <code class="leafygreen-ui-1l06pbn"> assignment </code> and <code class="leafygreen-ui-1l06pbn"> _id </code> fields: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 6322, \"assignment\" : 2 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6322</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndDelete-example-replace-with-time-limit"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Update Document with Time Limit <a class="headerlink leafygreen-ui-1kepx47" href="#update-document-with-time-limit" 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="update-document-with-time-limit"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following operation sets a 5ms time limit to complete the deletion: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"try {\n db.scores.findOneAndDelete(\n { \"name\" : \"A. MacDyver\" },\n { sort : { \"points\" : 1 }, maxTimeMS : 5 }\n )\n}\ncatch(e){\n print(e)\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"><span class="lg-highlight-keyword">try</span> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->db.<span class="lg-highlight-property">scores</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndDelete</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->sort <!-- -->: <!-- -->{ <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <!-- -->maxTimeMS <!-- -->: <span class="lg-highlight-number">5</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">catch</span>(<!-- -->e)<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">print</span>(<!-- -->e)</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> <p class="leafygreen-ui-1kp3ins"> If the operation exceeds the time limit, it returns: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoServerError: operation exceeded time limit: { \"ok\": 0, \"code\" : 50, \"codeName\" : \"MaxTimeMSExpired\" }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">MongoServerError</span>: <!-- -->operation exceeded time <span class="lg-highlight-attr">limit</span>: <!-- -->{ <span class="lg-highlight-string">"ok"</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"code"</span> <!-- -->: <span class="lg-highlight-number">50</span>, <span class="lg-highlight-string">"codeName"</span> <!-- -->: <span class="lg-highlight-string">"MaxTimeMSExpired"</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 class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This error message has been shortened for brevity. </p> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Specify Collation <a class="headerlink leafygreen-ui-1kepx47" href="#specify-collation" 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="specify-collation"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> Collation </a> allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks. </p> <p class="leafygreen-ui-1kp3ins"> A collection <code class="leafygreen-ui-1l06pbn"> myColl </code> has the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.myColl.insertMany( [\n { _id: 1, category: \"café\", status: \"A\" },\n { _id: 2, category: \"cafe\", status: \"a\" },\n { _id: 3, category: \"cafE\", status: \"a\" }\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">db.<span class="lg-highlight-property">myColl</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"café"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"A"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafe"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"a"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafE"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"a"</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> <p class="leafygreen-ui-1kp3ins"> The following operation includes the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> collation </a> option: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.myColl.findOneAndDelete(\n { category: \"cafe\", status: \"a\" },\n { collation: { locale: \"fr\", strength: 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">db.<span class="lg-highlight-property">myColl</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndDelete</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafe"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"a"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">collation</span>: <!-- -->{ <span class="lg-highlight-attr">locale</span>: <span class="lg-highlight-string">"fr"</span>, <span class="lg-highlight-attr">strength</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"category\" : \"café\", \"status\" : \"A\" }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"category"</span> <!-- -->: <span class="lg-highlight-string">"café"</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</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> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/db.collection.getIndexes/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> db.collection.getIndexes() <a class="headerlink leafygreen-ui-1kepx47" href="#db.collection.getindexes--" 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="db.collection.getindexes--"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#required-access" target="_self"> <span> Required Access </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#output" target="_self"> <span> Output </span> </a> </li> </ul> </div> <div class="leafygreen-ui-147elvs"> <p class="leafygreen-ui-1ronz74"> MongoDB with drivers </p> <div class="leafygreen-ui-18k5rfm"> <p class="leafygreen-ui-1kp3ins"> This page documents a <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> method. To see the equivalent method in a MongoDB driver, see the corresponding page for your programming language: </p> </div> <div class="leafygreen-ui-zgrwqu notranslate"> <a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/csharp/current/fundamentals/indexes/#list-indexes" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59964)"> <g clip-path="url(#clip1_1351_59964)"> <path d="M25.7709 9.2495C25.7709 8.79827 25.678 8.39408 25.4827 8.04627C25.2874 7.70785 25.0084 7.42586 24.627 7.20025C21.465 5.35781 18.2937 3.51538 15.1317 1.67295C14.2761 1.17474 13.4484 1.19354 12.6021 1.70115C11.3466 2.45316 5.04112 6.10042 3.15321 7.20025C2.3813 7.65142 2 8.34705 2 9.24005C2 12.9531 2 16.6568 2 20.3698C2 20.8117 2.093 21.2064 2.279 21.5449C2.4743 21.8927 2.7626 22.1841 3.15321 22.4191C5.03182 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2761 28.4446 15.1317 27.9463C18.2937 26.1039 21.465 24.2615 24.627 22.4191C25.0177 22.1935 25.306 21.9021 25.5012 21.5449C25.6873 21.2064 25.7803 20.8117 25.7803 20.3698C25.7709 20.3698 25.7709 12.9531 25.7709 9.2495Z" fill="#A179DC"> </path> <path d="M13.9227 14.7673L2.27905 21.5449C2.47435 21.8927 2.76265 22.1841 3.15326 22.4191C5.03187 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2762 28.4445 15.1317 27.9463C18.2938 26.1039 21.4651 24.2615 24.6271 22.4191C25.0177 22.1935 25.306 21.9021 25.5013 21.5449L13.9227 14.7673Z" fill="#280068"> </path> <path d="M25.7711 9.24949C25.7711 8.79827 25.6781 8.39408 25.4828 8.04626L13.9229 14.7768L25.4921 21.5543C25.6781 21.2159 25.7711 20.8211 25.7711 20.3793C25.7711 20.3699 25.7711 12.9531 25.7711 9.24949Z" fill="#390091"> </path> <path d="M20.7771 12.2387V13.5078H22.0325V12.2387H22.6557V13.5078H23.9111V14.1376H22.6557V15.4066H23.9111V16.0364H22.6557V17.3054H22.0325V16.0364H20.7771V17.3054H20.1539V16.0364H18.8984V15.4066H20.1539V14.1376H18.8984V13.5078H20.1539V12.2387H20.7771ZM22.0325 14.1376H20.7771V15.4066H22.0325V14.1376Z" fill="white"> </path> <path d="M13.9508 5.87482C17.2151 5.87482 20.0702 7.67022 21.6047 10.3399L21.5861 10.3117L17.7452 12.5489C16.9919 11.2517 15.5969 10.3775 14.0066 10.3587H13.9601C11.5328 10.3587 9.56116 12.3515 9.56116 14.805C9.56116 15.604 9.77503 16.3654 10.1377 17.014C10.9004 18.3488 12.3232 19.2512 13.9601 19.2512C15.6062 19.2512 17.0384 18.3394 17.7917 16.9858L17.7731 17.014L21.614 19.2606C20.0981 21.9021 17.2895 23.6975 14.0531 23.7257H13.9508C10.6679 23.7257 7.81274 21.9209 6.28753 19.2418C5.54353 17.9352 5.11572 16.4124 5.11572 14.7956C5.11572 9.87931 9.06825 5.87482 13.9508 5.87482Z" fill="white"> </path> </g> </g> <defs> <clippath id="clip0_1351_59964"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59964"> <rect fill="white" height="27" transform="translate(2 1.30966)" width="24"> </rect> </clippath> </defs> </svg> <span> C# </span> </a> <a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/java/sync/v5.2/fundamentals/indexes/#remove-an-index-using-a-name-field" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD"> </path> <path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD"> </path> <path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E"> </path> <path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD"> </path> <path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD"> </path> <path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD"> </path> <path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E"> </path> <path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD"> </path> </svg> <span> Java Sync </span> </a> <a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/node/current/fundamentals/indexes/#list-indexes" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 30" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:R2dt5qcmqn9:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R2dt5qcmqn9:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":R2dt5qcmqn9:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":R2dt5qcmqn9:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <span> Node.js </span> </a> <a class="leafygreen-ui-v22cck" href="https://pymongo.readthedocs.io/en/4.8.0/api/pymongo/collection.html#pymongo.collection.Collection.list_indexes" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 111.6 147" width="24" xmlns="http://www.w3.org/2000/svg"> <lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R2ht5qcmqn9:aa" x1="280.848" x2="389.865" y1="-268.463" y2="-362.257"> <stop offset="0" stop-color="#5a9fd4"> </stop> <stop offset="1" stop-color="#306998"> </stop> </lineargradient> <path d="M55.3 3.2c-4.6 0-9 .4-12.8 1.1-11.3 2-13.4 6.2-13.4 13.9v10.2h26.8v3.4H19c-7.8 0-14.6 4.7-16.8 13.6C-.3 55.6-.4 62 2.2 72.7c1.9 7.9 6.5 13.6 14.2 13.6h9.2V74c0-8.8 7.7-16.7 16.7-16.7h26.8c7.5 0 13.4-6.1 13.4-13.6V18.2c0-7.3-6.1-12.7-13.4-13.9-4.4-.8-9.2-1.1-13.8-1.1zm-14.5 8.2c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1s2.2-5.1 5-5.1z" fill="url(#:R2ht5qcmqn9:aa)"> </path> <lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R2ht5qcmqn9:bb" x1="432.011" x2="393.081" y1="-419.025" y2="-363.946"> <stop offset="0" stop-color="#ffd43b"> </stop> <stop offset="1" stop-color="#ffe873"> </stop> </lineargradient> <path d="M86 31.8v11.9c0 9.2-7.8 17-16.8 17H42.5c-7.3 0-13.4 6.3-13.4 13.6v25.5c0 7.3 6.3 11.5 13.4 13.6 8.5 2.5 16.6 2.9 26.8 0 6.8-2 13.4-5.9 13.4-13.6V89.7H55.9v-3.4h40.2c7.8 0 10.7-5.4 13.4-13.6 2.8-8.4 2.7-16.5 0-27.3-1.9-7.8-5.6-13.6-13.4-13.6H86zM71 96.5c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1-.1-2.8 2.2-5.1 5-5.1z" fill="url(#:R2ht5qcmqn9:bb)"> </path> <radialgradient cx="-2274.721" cy="144.526" gradienttransform="matrix(0 -.2399 -1.0547 0 208.637 -414.922)" gradientunits="userSpaceOnUse" id=":R2ht5qcmqn9:cc" r="29.037"> <stop offset="0" stop-color="#b8b8b8" stop-opacity=".498"> </stop> <stop offset="1" stop-color="#7f7f7f" stop-opacity="0"> </stop> </radialgradient> <path d="M92.1 130.9c0 3.8-16.1 7-35.9 7s-35.9-3.1-35.9-7c0-3.8 16.1-7 35.9-7s35.9 3.1 35.9 7z" fill="url(#:R2ht5qcmqn9:cc)" opacity=".444"> </path> </svg> <span> PyMongo </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/languages/c/c-driver/current/libmongoc/guides/manage-collection-indexes/" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59955)"> <g clip-path="url(#clip1_1351_59955)"> <path clip-rule="evenodd" d="M13.118 1.49532C13.5403 1.25103 14.0559 1.25103 14.4783 1.49532C16.5652 2.70389 22.8385 6.34889 24.9193 7.55748C25.3416 7.80172 25.6025 8.25176 25.6025 8.74672C25.6025 11.1703 25.6025 18.4539 25.6025 20.8774C25.6025 21.366 25.3416 21.8224 24.9193 22.0667C22.8385 23.2753 16.5652 26.9203 14.4783 28.1289C14.0559 28.3732 13.5403 28.3732 13.118 28.1289C11.0373 26.9139 4.76398 23.2689 2.68323 22.0603C2.26087 21.816 2 21.366 2 20.871C2 18.4474 2 11.1639 2 8.7403C2 8.25176 2.26087 7.7953 2.68323 7.55106C4.76398 6.34889 11.0373 2.70389 13.118 1.49532Z" fill="#004482" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M2.18634 21.4946C2.01863 21.2632 2 21.051 2 20.7553C2 18.351 2 11.1061 2 8.70176C2 8.21317 2.26087 7.76319 2.67702 7.51889C4.75776 6.31675 11.0062 2.69104 13.0807 1.4889C13.5031 1.24461 14.0683 1.25104 14.4907 1.49533C16.5652 2.69747 22.795 6.29104 24.8696 7.49319C25.0373 7.58963 25.1677 7.70535 25.2795 7.86606L2.18634 21.4946Z" fill="#659AD2" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M13.8011 5.8089C18.6024 5.8089 22.4968 9.83964 22.4968 14.8089C22.4968 19.7782 18.6024 23.8089 13.8011 23.8089C8.99986 23.8089 5.10547 19.7782 5.10547 14.8089C5.10547 9.83964 8.99986 5.8089 13.8011 5.8089ZM13.8011 10.3089C16.1987 10.3089 18.1489 12.3275 18.1489 14.8089C18.1489 17.2903 16.1987 19.3089 13.8011 19.3089C11.4036 19.3089 9.4533 17.2903 9.4533 14.8089C9.4533 12.3275 11.4036 10.3089 13.8011 10.3089Z" fill="white" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M25.2857 7.87247C25.6087 8.18102 25.6025 8.65034 25.6025 9.01673C25.6025 11.4596 25.5839 18.396 25.6087 20.8325C25.6087 21.0896 25.528 21.3532 25.4099 21.5589L13.5466 14.8089L25.2857 7.87247Z" fill="#00599C" fill-rule="evenodd"> </path> </g> </g> <defs> <clippath id="clip0_1351_59955"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59955"> <rect fill="white" height="27" transform="translate(2 1.30887)" width="24"> </rect> </clippath> </defs> </svg> <span> C </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongocxx.org/api/mongocxx-3.10.2/classmongocxx_1_1v__noabi_1_1collection.html#a73fb27bd4181be98989813247a6255b0" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59959)"> <g clip-path="url(#clip1_1351_59959)"> <path d="M25.4013 21.5646C25.5872 21.2353 25.7034 20.8745 25.7034 20.5373V9.08012C25.7034 8.75078 25.5872 8.38217 25.4013 8.05283L13.8516 14.8127L25.4013 21.5646Z" fill="#00599C"> </path> <path d="M14.8738 28.0657L24.6729 22.3411C24.9517 22.1764 25.2151 21.8941 25.401 21.5647L13.8513 14.8127L2.30151 21.5647C2.48743 21.8941 2.74305 22.1764 3.02967 22.3411L12.8288 28.0657C13.3865 28.3951 14.316 28.3951 14.8738 28.0657Z" fill="#004482"> </path> <path d="M25.4011 8.06086C25.2152 7.73146 24.9596 7.44915 24.673 7.2845L14.8739 1.55983C14.3084 1.23046 13.3866 1.23046 12.8211 1.55983L3.02202 7.2845C2.46429 7.61385 1.99951 8.42158 1.99951 9.08033V20.5375C1.99951 20.8669 2.11571 21.2354 2.30162 21.5647L13.8514 14.8128L25.4011 8.06086Z" fill="#659AD2"> </path> <path d="M13.8512 22.8115C9.49778 22.8115 5.94995 19.2199 5.94995 14.8127C5.94995 10.4055 9.49778 6.81387 13.8512 6.81387C16.6631 6.81387 19.2813 8.34305 20.6912 10.8133L17.2751 12.813C16.5701 11.5818 15.261 10.8133 13.8512 10.8133C11.6745 10.8133 9.90055 12.6091 9.90055 14.8127C9.90055 17.0163 11.6745 18.8121 13.8512 18.8121C15.261 18.8121 16.5701 18.0436 17.2751 16.8124L20.6912 18.8121C19.2813 21.2745 16.6631 22.8115 13.8512 22.8115Z" fill="white"> </path> <path d="M21.7524 14.3657H20.8771V13.4796H19.994V14.3657H19.1187V15.2518H19.994V16.1458H20.8771V15.2518H21.7524V14.3657Z" fill="white"> </path> <path d="M25.0446 14.3657H24.1693V13.4796H23.2862V14.3657H22.4109V15.2518H23.2862V16.1458H24.1693V15.2518H25.0446V14.3657Z" fill="white"> </path> </g> </g> <defs> <clippath id="clip0_1351_59959"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59959"> <rect fill="white" height="27" transform="translate(1.99951 1.30878)" width="24"> </rect> </clippath> </defs> </svg> <span> C++ </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://pkg.go.dev/go.mongodb.org/[email protected]/mongo#IndexView.List" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" id="Layer_1" style="fill:#00ACD7" version="1.1" viewbox="0 0 205.4 76.7" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0"> <path class="st00" d="M15.5 23.2c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h35.7c.4 0 .5.3.3.6l-1.7 2.6c-.2.3-.7.6-1 .6l-36.2-.1zM.4 32.4c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h45.6c.4 0 .6.3.5.6l-.8 2.4c-.1.4-.5.6-.9.6l-47.3.1zM24.6 41.6c-.4 0-.5-.3-.3-.6l1.4-2.5c.2-.3.6-.6 1-.6h20c.4 0 .6.3.6.7l-.2 2.4c0 .4-.4.7-.7.7l-21.8-.1z"> </path> <g id="CXHf1q_3_"> <path class="st00" d="M128.4 21.4c-6.3 1.6-10.6 2.8-16.8 4.4-1.5.4-1.6.5-2.9-1-1.5-1.7-2.6-2.8-4.7-3.8-6.3-3.1-12.4-2.2-18.1 1.5-6.8 4.4-10.3 10.9-10.2 19 .1 8 5.6 14.6 13.5 15.7 6.8.9 12.5-1.5 17-6.6.9-1.1 1.7-2.3 2.7-3.7H89.6c-2.1 0-2.6-1.3-1.9-3 1.3-3.1 3.7-8.3 5.1-10.9.3-.6 1-1.6 2.5-1.6h36.4c-.2 2.7-.2 5.4-.6 8.1-1.1 7.2-3.8 13.8-8.2 19.6-7.2 9.5-16.6 15.4-28.5 17-9.8 1.3-18.9-.6-26.9-6.6-7.4-5.6-11.6-13-12.7-22.2-1.3-10.9 1.9-20.7 8.5-29.3C70.4 8.7 79.8 2.8 91.3.7c9.4-1.7 18.4-.6 26.5 4.9 5.3 3.5 9.1 8.3 11.6 14.1.6.9.2 1.4-1 1.7z"> </path> <path class="st00" d="M161.5 76.7c-9.1-.2-17.4-2.8-24.4-8.8-5.9-5.1-9.6-11.6-10.8-19.3-1.8-11.3 1.3-21.3 8.1-30.2 7.3-9.6 16.1-14.6 28-16.7 10.2-1.8 19.8-.8 28.5 5.1 7.9 5.4 12.8 12.7 14.1 22.3 1.7 13.5-2.2 24.5-11.5 33.9-6.6 6.7-14.7 10.9-24 12.8-2.7.5-5.4.6-8 .9zm23.8-40.4c-.1-1.3-.1-2.3-.3-3.3-1.8-9.9-10.9-15.5-20.4-13.3-9.3 2.1-15.3 8-17.5 17.4-1.8 7.8 2 15.7 9.2 18.9 5.5 2.4 11 2.1 16.3-.6 7.9-4.1 12.2-10.5 12.7-19.1z"> </path> </g> </svg> <span> Go </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#listIndexes()" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD"> </path> <path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD"> </path> <path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E"> </path> <path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD"> </path> <path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD"> </path> <path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD"> </path> <path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E"> </path> <path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD"> </path> </svg> <span> Java RS </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/kotlin/coroutine/current/fundamentals/indexes/#remove-an-index-using-a-name-field" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R35t5qcmqn9:paint0_linear_211_40588)"> </path> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R35t5qcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29"> <stop offset="0.00343514" stop-color="#E44857"> </stop> <stop offset="0.4689" stop-color="#C711E1"> </stop> <stop offset="1" stop-color="#7F52FF"> </stop> </lineargradient> </defs> </svg> <span> Kotlin Coroutine </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-kotlin-sync/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/list-indexes.html?query=fun%20listIndexes():%20ListIndexesIterable%3CDocument%3E" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R39t5qcmqn9:paint0_linear_211_40588)"> </path> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R39t5qcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29"> <stop offset="0.00343514" stop-color="#E44857"> </stop> <stop offset="0.4689" stop-color="#C711E1"> </stop> <stop offset="1" stop-color="#7F52FF"> </stop> </lineargradient> </defs> </svg> <span> Kotlin Sync </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/php-library/current/indexes/#list-indexes" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 700 301" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0"> <defs> <clippath clippathunits="userSpaceOnUse" id="a"> <path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439"> </path> </clippath> <clippath clippathunits="userSpaceOnUse" id="c"> <path d="M0 324h576V0H0v324z"> </path> </clippath> <clippath clippathunits="userSpaceOnUse" id="d"> <path d="M0 324h576V0H0v324z"> </path> </clippath> <radialgradient cx="0" cy="0" fx="0" fy="0" gradienttransform="matrix(363.05789 0 0 -363.05789 177.52 256.307)" gradientunits="userSpaceOnUse" id="b" r="1" spreadmethod="pad"> <stop offset="0" stop-color="#aeb2d5"> </stop> <stop offset=".3" stop-color="#aeb2d5"> </stop> <stop offset=".75" stop-color="#484c89"> </stop> <stop offset="1" stop-color="#484c89"> </stop> </radialgradient> </defs> <g clip-path="url(#a)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439" fill="url(#b)"> </path> </g> <g clip-path="url(#c)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M288 27.36c146.729 0 265.68 60.28 265.68 134.64 0 74.36-118.951 134.641-265.68 134.641S22.32 236.36 22.32 162.001C22.32 87.64 141.271 27.358 288 27.358" fill="#777bb3"> </path> </g> <g clip-path="url(#d)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M161.734 145.307c12.065 0 21.072 2.225 26.771 6.61 5.638 4.342 9.532 11.863 11.573 22.354 1.903 9.806 1.178 16.653-2.154 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.28l-10.69-55h15.673zm-63.063-67.75a2.998 2.998 0 00-2.944 3.572l28.328 145.75a3 3 0 002.945 2.428h61.054c19.188 0 33.47-5.21 42.447-15.487 9.025-10.331 11.812-24.772 8.283-42.921-1.436-7.394-3.906-14.261-7.34-20.41-3.44-6.154-7.985-11.85-13.512-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.28-3.93-30.548-3.93h-24.722l-7.06-36.321a3 3 0 00-2.944-2.428h-31.75z"> </path> <path d="M159.224 197.307h16.808c13.42 0 18.083-2.945 19.667-4.7 2.628-2.914 3.124-9.058 1.435-17.767-1.898-9.75-5.416-16.663-10.458-20.545-5.162-3.974-13.554-5.988-24.941-5.988H149.7l9.523 49zm28.83 35H127a6 6 0 01-5.89-4.855L92.784 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.588 33.895h22.249c12.582 0 23.174 1.372 31.479 4.077 8.54 2.775 16.399 7.48 23.354 13.984 5.752 5.292 10.49 11.232 14.08 17.657 3.59 6.427 6.17 13.594 7.668 21.302 3.715 19.104.697 34.402-8.97 45.466-9.571 10.958-24.613 16.514-44.705 16.514m-45.633-90h19.313c12.8 0 22.336 2.411 28.6 7.234 6.267 4.824 10.493 12.875 12.689 24.157 2.1 10.832 1.144 18.476-2.871 22.93-4.02 4.452-12.06 6.68-24.121 6.68h-21.754l-11.856-61m45.633 84c18.367 0 31.766-4.82 40.188-14.462 8.42-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.621-3.782-29.621-3.782h-27.196l-7.531-38.75h-31.75L127 226.307h61.055" fill="#fff"> </path> <path d="M311.583 116.307c-.896 0-1.745.4-2.314 1.092a2.994 2.994 0 00-.631 2.48l12.531 64.489c1.192 6.133.898 10.535-.827 12.395-1.056 1.137-4.228 3.044-13.607 3.044h-22.702l-15.755-81.072a3 3 0 00-2.945-2.428h-31.5a2.998 2.998 0 00-2.945 3.572l28.328 145.75a3 3 0 002.945 2.428h31.5a3 3 0 002.945-3.572l-6.836-35.178h24.422c18.605 0 31.221-3.28 38.569-10.028 7.49-6.884 9.827-17.891 6.947-32.72l-13.18-67.824a3 3 0 00-2.945-2.428h-32z"> </path> <path d="M293.661 271.057h-31.5a6 6 0 01-5.89-4.855l-28.328-145.75a5.998 5.998 0 015.89-7.145h31.5a6 6 0 015.89 4.855l15.283 78.645h20.23c9.362 0 11.327-2 11.406-2.086.568-.61 1.315-3.44.082-9.78l-12.53-64.49a5.998 5.998 0 015.89-7.144h32a6 6 0 015.89 4.855l13.178 67.825c3.093 15.921.447 27.864-7.86 35.5-7.929 7.281-21.209 10.82-40.6 10.82h-20.784l6.143 31.605a6.001 6.001 0 01-5.89 7.145m0-6l-7.53-38.75h28.061c17.657 0 29.836-3.082 36.54-9.238 6.702-6.16 8.71-16.14 6.031-29.938l-13.18-67.824h-32l12.531 64.488c1.426 7.336.902 12.34-1.574 15.008-2.477 2.668-7.746 4.004-15.805 4.004H281.56l-16.226-83.5h-31.5l28.328 145.75h31.5" fill="#fff"> </path> <path d="M409.55 145.307c12.065 0 21.072 2.225 26.77 6.61 5.639 4.34 9.533 11.862 11.575 22.354 1.903 9.806 1.178 16.653-2.155 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.281l-10.69-55h15.674zm-63.062-67.75a2.999 2.999 0 00-2.945 3.572l28.328 145.75a3.002 3.002 0 002.946 2.428h61.053c19.189 0 33.47-5.21 42.448-15.487 9.025-10.33 11.81-24.771 8.283-42.921-1.438-7.394-3.907-14.261-7.342-20.41-3.44-6.154-7.984-11.85-13.511-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.281-3.93-30.548-3.93H388.24l-7.057-36.321a3.001 3.001 0 00-2.946-2.428h-31.75z"> </path> <path d="M407.04 197.307h16.807c13.421 0 18.083-2.945 19.667-4.7 2.63-2.914 3.125-9.058 1.435-17.766-1.898-9.75-5.417-16.664-10.458-20.546-5.162-3.974-13.554-5.988-24.94-5.988h-12.034l9.522 49zm28.83 35h-61.054a6 6 0 01-5.889-4.855L340.6 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.587 33.895h22.25c12.581 0 23.173 1.372 31.478 4.077 8.541 2.775 16.401 7.481 23.356 13.986 5.752 5.291 10.488 11.23 14.078 17.655 3.591 6.427 6.171 13.594 7.668 21.302 3.715 19.105.697 34.403-8.969 45.467-9.572 10.957-24.613 16.513-44.706 16.513m-45.632-90h19.312c12.801 0 22.336 2.411 28.601 7.234 6.267 4.824 10.492 12.875 12.688 24.157 2.102 10.832 1.145 18.476-2.87 22.93-4.02 4.452-12.06 6.68-24.122 6.68h-21.754l-11.855-61m45.632 84c18.367 0 31.766-4.82 40.188-14.462 8.422-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.62-3.782-29.62-3.782h-27.197l-7.53-38.75h-31.75l28.328 145.75h61.054" fill="#fff"> </path> </g> </svg> <span> PHP </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/mongoid/master/api/Mongoid/Indexable/ClassMethods.html#index_specification-instance_method" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" preserveaspectratio="xMidYMid" viewbox="0 0 300 240" width="24" xmlns="http://www.w3.org/2000/svg"> <defs> <lineargradient id=":R3ht5qcmqn9:a" x1="84.75%" x2="58.254%" y1="111.399%" y2="64.584%"> <stop offset="0%" stop-color="#FB7655"> </stop> <stop offset="0%" stop-color="#FB7655"> </stop> <stop offset="41%" stop-color="#E42B1E"> </stop> <stop offset="99%" stop-color="#900"> </stop> <stop offset="100%" stop-color="#900"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:b" x1="116.651%" x2="1.746%" y1="60.89%" y2="19.288%"> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="99%" stop-color="#911209"> </stop> <stop offset="100%" stop-color="#911209"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:c" x1="75.774%" x2="38.978%" y1="219.327%" y2="7.829%"> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="99%" stop-color="#911209"> </stop> <stop offset="100%" stop-color="#911209"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:d" x1="50.012%" x2="66.483%" y1="7.234%" y2="79.135%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="23%" stop-color="#E57252"> </stop> <stop offset="46%" stop-color="#DE3B20"> </stop> <stop offset="99%" stop-color="#A60003"> </stop> <stop offset="100%" stop-color="#A60003"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:e" x1="46.174%" x2="49.932%" y1="16.348%" y2="83.047%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="23%" stop-color="#E4714E"> </stop> <stop offset="56%" stop-color="#BE1A0D"> </stop> <stop offset="99%" stop-color="#A80D00"> </stop> <stop offset="100%" stop-color="#A80D00"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:f" x1="36.965%" x2="49.528%" y1="15.594%" y2="92.478%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="18%" stop-color="#E46342"> </stop> <stop offset="40%" stop-color="#C82410"> </stop> <stop offset="99%" stop-color="#A80D00"> </stop> <stop offset="100%" stop-color="#A80D00"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:g" x1="13.609%" x2="85.764%" y1="58.346%" y2="-46.717%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="54%" stop-color="#C81F11"> </stop> <stop offset="99%" stop-color="#BF0905"> </stop> <stop offset="100%" stop-color="#BF0905"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:h" x1="27.624%" x2="50.745%" y1="21.135%" y2="79.056%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="31%" stop-color="#DE4024"> </stop> <stop offset="99%" stop-color="#BF190B"> </stop> <stop offset="100%" stop-color="#BF190B"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:i" x1="-20.667%" x2="104.242%" y1="122.282%" y2="-6.342%"> <stop offset="0%" stop-color="#BD0012"> </stop> <stop offset="0%" stop-color="#BD0012"> </stop> <stop offset="7%" stop-color="#FFF"> </stop> <stop offset="17%" stop-color="#FFF"> </stop> <stop offset="27%" stop-color="#C82F1C"> </stop> <stop offset="33%" stop-color="#820C01"> </stop> <stop offset="46%" stop-color="#A31601"> </stop> <stop offset="72%" stop-color="#B31301"> </stop> <stop offset="99%" stop-color="#E82609"> </stop> <stop offset="100%" stop-color="#E82609"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:j" x1="58.792%" x2="11.964%" y1="65.205%" y2="50.128%"> <stop offset="0%" stop-color="#8C0C01"> </stop> <stop offset="0%" stop-color="#8C0C01"> </stop> <stop offset="54%" stop-color="#990C00"> </stop> <stop offset="99%" stop-color="#A80D0E"> </stop> <stop offset="100%" stop-color="#A80D0E"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:k" x1="79.319%" x2="23.088%" y1="62.754%" y2="17.888%"> <stop offset="0%" stop-color="#7E110B"> </stop> <stop offset="0%" stop-color="#7E110B"> </stop> <stop offset="99%" stop-color="#9E0C00"> </stop> <stop offset="100%" stop-color="#9E0C00"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:l" x1="92.88%" x2="59.841%" y1="74.122%" y2="39.704%"> <stop offset="0%" stop-color="#79130D"> </stop> <stop offset="0%" stop-color="#79130D"> </stop> <stop offset="99%" stop-color="#9E120B"> </stop> <stop offset="100%" stop-color="#9E120B"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:o" x1="56.57%" x2="3.105%" y1="101.717%" y2="11.993%"> <stop offset="0%" stop-color="#8B2114"> </stop> <stop offset="0%" stop-color="#8B2114"> </stop> <stop offset="43%" stop-color="#9E100A"> </stop> <stop offset="99%" stop-color="#B3100C"> </stop> <stop offset="100%" stop-color="#B3100C"> </stop> </lineargradient> <lineargradient id=":R3ht5qcmqn9:p" x1="30.87%" x2="92.471%" y1="35.599%" y2="100.694%"> <stop offset="0%" stop-color="#B31000"> </stop> <stop offset="0%" stop-color="#B31000"> </stop> <stop offset="44%" stop-color="#910F08"> </stop> <stop offset="99%" stop-color="#791C12"> </stop> <stop offset="100%" stop-color="#791C12"> </stop> </lineargradient> <radialgradient cx="32.001%" cy="40.21%" fx="32.001%" fy="40.21%" id=":R3ht5qcmqn9:m" r="69.573%"> <stop offset="0%" stop-color="#A80D00"> </stop> <stop offset="0%" stop-color="#A80D00"> </stop> <stop offset="99%" stop-color="#7E0E08"> </stop> <stop offset="100%" stop-color="#7E0E08"> </stop> </radialgradient> <radialgradient cx="13.549%" cy="40.86%" fx="13.549%" fy="40.86%" id=":R3ht5qcmqn9:n" r="88.386%"> <stop offset="0%" stop-color="#A30C00"> </stop> <stop offset="0%" stop-color="#A30C00"> </stop> <stop offset="99%" stop-color="#800E08"> </stop> <stop offset="100%" stop-color="#800E08"> </stop> </radialgradient> </defs> <path d="M197.467 167.764l-145.52 86.41 188.422-12.787L254.88 51.393l-57.414 116.37z" fill="url(#:R3ht5qcmqn9:a)"> </path> <path d="M240.677 241.257L224.482 129.48l-44.113 58.25 60.308 53.528z" fill="url(#:R3ht5qcmqn9:b)"> </path> <path d="M240.896 241.257l-118.646-9.313-69.674 21.986 188.32-12.673z" fill="url(#:R3ht5qcmqn9:c)"> </path> <path d="M52.744 253.955l29.64-97.1L17.16 170.8l35.583 83.154z" fill="url(#:R3ht5qcmqn9:d)"> </path> <path d="M180.358 188.05L153.085 81.226l-78.047 73.16 105.32 33.666z" fill="url(#:R3ht5qcmqn9:e)"> </path> <path d="M248.693 82.73l-73.777-60.256-20.544 66.418 94.321-6.162z" fill="url(#:R3ht5qcmqn9:f)"> </path> <path d="M214.191.99L170.8 24.97 143.424.669l70.767.322z" fill="url(#:R3ht5qcmqn9:g)"> </path> <path d="M0 203.372l18.177-33.151-14.704-39.494L0 203.372z" fill="url(#:R3ht5qcmqn9:h)"> </path> <path d="M2.496 129.48l14.794 41.963 64.283-14.422 73.39-68.207 20.712-65.787L143.063 0 87.618 20.75c-17.469 16.248-51.366 48.396-52.588 49-1.21.618-22.384 40.639-32.534 59.73z" fill="#FFF"> </path> <path d="M54.442 54.094c37.86-37.538 86.667-59.716 105.397-40.818 18.72 18.898-1.132 64.823-38.992 102.349-37.86 37.525-86.062 60.925-104.78 42.027-18.73-18.885.515-66.032 38.375-103.558z" fill="url(#:R3ht5qcmqn9:i)"> </path> <path d="M52.744 253.916l29.408-97.409 97.665 31.376c-35.312 33.113-74.587 61.106-127.073 66.033z" fill="url(#:R3ht5qcmqn9:j)"> </path> <path d="M155.092 88.622l25.073 99.313c29.498-31.016 55.972-64.36 68.938-105.603l-94.01 6.29z" fill="url(#:R3ht5qcmqn9:k)"> </path> <path d="M248.847 82.833c10.035-30.282 12.35-73.725-34.966-81.791l-38.825 21.445 73.791 60.346z" fill="url(#:R3ht5qcmqn9:l)"> </path> <path d="M0 202.935c1.39 49.979 37.448 50.724 52.808 51.162l-35.48-82.86L0 202.935z" fill="#9E1209"> </path> <path d="M155.232 88.777c22.667 13.932 68.35 41.912 69.276 42.426 1.44.81 19.695-30.784 23.838-48.64l-93.114 6.214z" fill="url(#:R3ht5qcmqn9:m)"> </path> <path d="M82.113 156.507l39.313 75.848c23.246-12.607 41.45-27.967 58.121-44.42l-97.434-31.428z" fill="url(#:R3ht5qcmqn9:n)"> </path> <path d="M17.174 171.34l-5.57 66.328c10.51 14.357 24.97 15.605 40.136 14.486-10.973-27.311-32.894-81.92-34.566-80.814z" fill="url(#:R3ht5qcmqn9:o)"> </path> <path d="M174.826 22.654l78.1 10.96c-4.169-17.662-16.969-29.06-38.787-32.623l-39.313 21.663z" fill="url(#:R3ht5qcmqn9:p)"> </path> </svg> <span> Mongoid </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://docs.rs/mongodb/3.1.0/mongodb/struct.Collection.html#method.list_indexes" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 30 30" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_5454_14623)"> <path d="M15.2561 3.08398C8.56014 3.08398 3.11035 8.53634 3.11035 15.2297C3.11035 21.9231 8.56271 27.3755 15.2561 27.3755C21.9495 27.3755 27.4019 21.9231 27.4019 15.2297C27.4019 8.53634 21.9495 3.08398 15.2561 3.08398ZM15.2381 4.16315C15.4458 4.16853 15.6432 4.25509 15.7881 4.40437C15.9331 4.55365 16.0142 4.75384 16.0141 4.96225C16.0141 5.17418 15.9299 5.37744 15.7801 5.5273C15.6302 5.67715 15.4269 5.76134 15.215 5.76134C15.0031 5.76134 14.7998 5.67715 14.65 5.5273C14.5001 5.37744 14.4159 5.17418 14.4159 4.96225C14.4159 4.85533 14.4373 4.7495 14.4789 4.65101C14.5205 4.55252 14.5814 4.46338 14.6581 4.38887C14.7347 4.31435 14.8256 4.25598 14.9252 4.21721C15.0249 4.17844 15.1313 4.16006 15.2381 4.16315ZM17.0676 5.47871C18.4704 5.74146 19.7992 6.30644 20.9617 7.13439C22.1242 7.96235 23.0926 9.03345 23.7995 10.2733L22.8565 12.4008C22.6947 12.7682 22.8617 13.1999 23.2265 13.3643L25.0406 14.1686C25.0968 14.7356 25.1037 15.3065 25.0611 15.8747H24.0513C23.9511 15.8747 23.91 15.9415 23.91 16.0391V16.5016C23.91 17.5911 23.2959 17.83 22.7563 17.8891C22.2424 17.9482 21.6746 17.6733 21.6026 17.3598C21.2994 15.6563 20.7958 15.294 19.9993 14.6645C20.9885 14.0375 22.0163 13.11 22.0163 11.8715C22.0163 10.5328 21.099 9.69002 20.4747 9.27634C19.5959 8.69822 18.6247 8.5826 18.3626 8.5826H7.93063C9.37312 6.97114 11.3066 5.88021 13.4318 5.47871L14.6626 6.76857C14.9401 7.05891 15.4 7.07176 15.6903 6.79169L17.0676 5.47871ZM5.71063 11.3936C5.91853 11.3996 6.11589 11.4864 6.26079 11.6356C6.40568 11.7849 6.48669 11.9847 6.4866 12.1927C6.4866 12.4046 6.40241 12.6079 6.25255 12.7577C6.10269 12.9076 5.89944 12.9918 5.6875 12.9918C5.47557 12.9918 5.27232 12.9076 5.12246 12.7577C4.9726 12.6079 4.88841 12.4046 4.88841 12.1927C4.88836 12.0858 4.90977 11.9799 4.95137 11.8814C4.99297 11.7829 5.0539 11.6938 5.13057 11.6193C5.20724 11.5448 5.29809 11.4864 5.39772 11.4476C5.49736 11.4089 5.60376 11.3905 5.71063 11.3936ZM24.7631 11.4295C24.971 11.4356 25.1683 11.5224 25.3132 11.6716C25.4581 11.8208 25.5391 12.0206 25.539 12.2286C25.539 12.4406 25.4548 12.6438 25.305 12.7937C25.1551 12.9435 24.9519 13.0277 24.7399 13.0277C24.528 13.0277 24.3247 12.9435 24.1749 12.7937C24.025 12.6438 23.9408 12.4406 23.9408 12.2286C23.9408 12.1217 23.9622 12.0159 24.0038 11.9174C24.0454 11.8189 24.1063 11.7298 24.183 11.6553C24.2597 11.5807 24.3505 11.5224 24.4502 11.4836C24.5498 11.4448 24.6562 11.4264 24.7631 11.4295ZM7.21632 11.558H8.60896V17.8377H5.79799C5.45083 16.6186 5.34264 15.3439 5.47938 14.0838L7.20091 13.3181C7.56834 13.1536 7.73535 12.7245 7.57091 12.3571L7.21632 11.558ZM13.0284 11.6248H16.3456C16.5177 11.6248 17.5558 11.8227 17.5558 12.6012C17.5558 13.2461 16.7592 13.4774 16.104 13.4774H13.0258L13.0284 11.6248ZM13.0284 16.1368H15.5696C15.8008 16.1368 16.8106 16.2036 17.1318 17.4934C17.232 17.8891 17.4556 19.179 17.6072 19.5927C17.7588 20.0552 18.3729 20.9802 19.0281 20.9802H23.1751C22.8972 21.3524 22.5933 21.7044 22.2656 22.0336L20.5774 21.6713C20.1843 21.5866 19.7963 21.8384 19.7115 22.2315L19.3107 24.102C18.0217 24.6859 16.622 24.9848 15.2069 24.9781C13.7919 24.9714 12.395 24.6595 11.1116 24.0635L10.7108 22.1929C10.626 21.7998 10.2406 21.548 9.84743 21.6328L8.19528 21.9874C7.88869 21.6711 7.6037 21.3346 7.34223 20.9802H15.3769C15.4668 20.9802 15.5285 20.9647 15.5285 20.88V18.0381C15.5285 17.9559 15.4668 17.9379 15.3769 17.9379H13.0258L13.0284 16.1368ZM9.3207 22.6452C9.5286 22.6512 9.72596 22.738 9.87085 22.8872C10.0157 23.0364 10.0968 23.2363 10.0967 23.4443C10.0967 23.6562 10.0125 23.8594 9.86262 24.0093C9.71276 24.1592 9.50951 24.2434 9.29757 24.2434C9.08564 24.2434 8.88239 24.1592 8.73253 24.0093C8.58267 23.8594 8.49848 23.6562 8.49848 23.4443C8.49843 23.3373 8.51984 23.2315 8.56144 23.133C8.60303 23.0345 8.66397 22.9454 8.74064 22.8709C8.81731 22.7964 8.90815 22.738 9.00779 22.6992C9.10743 22.6605 9.21383 22.6421 9.3207 22.6452ZM21.153 22.6811C21.3609 22.6872 21.5583 22.774 21.7031 22.9232C21.848 23.0724 21.929 23.2722 21.929 23.4802C21.929 23.6922 21.8448 23.8954 21.6949 24.0453C21.5451 24.1951 21.3418 24.2793 21.1299 24.2793C20.9179 24.2793 20.7147 24.1951 20.5648 24.0453C20.415 23.8954 20.3308 23.6922 20.3308 23.4802C20.3307 23.3733 20.3521 23.2675 20.3937 23.169C20.4353 23.0705 20.4963 22.9814 20.5729 22.9068C20.6496 22.8323 20.7404 22.774 20.8401 22.7352C20.9397 22.6964 21.0461 22.678 21.153 22.6811Z" fill="black"> </path> <path clip-rule="evenodd" d="M26.7232 15.2304C26.7232 18.2717 25.515 21.1885 23.3645 23.3391C21.2139 25.4896 18.2971 26.6978 15.2558 26.6978C12.2144 26.6978 9.29761 25.4896 7.14705 23.3391C4.99649 21.1885 3.78832 18.2717 3.78832 15.2304C3.78832 12.189 4.99649 9.27222 7.14705 7.12166C9.29761 4.9711 12.2144 3.76293 15.2558 3.76293C18.2971 3.76293 21.2139 4.9711 23.3645 7.12166C25.515 9.27222 26.7232 12.189 26.7232 15.2304ZM26.5073 14.1229L28.2957 15.2304L26.5073 16.3378L28.0439 17.7741L26.0757 18.5115L27.3039 20.2202L25.2252 20.5594L26.0988 22.4762L23.9944 22.4017L24.4775 24.4521L22.4271 23.969L22.5016 26.0734L20.5848 25.1998L20.2456 27.2785L18.5369 26.0503L17.7995 28.0185L16.3632 26.482L15.2558 28.2703L14.1483 26.482L12.712 28.0185L11.9746 26.0503L10.2659 27.2785L9.92672 25.1998L8.00992 26.0734L8.08443 23.969L6.03401 24.4521L6.51707 22.4017L4.4127 22.4762L5.28631 20.5594L3.20763 20.2202L4.43582 18.5115L2.46763 17.7741L4.00415 16.3378L2.21582 15.2304L4.00415 14.1229L2.46763 12.6866L4.43582 11.9492L3.20763 10.2405L5.28631 9.90133L4.4127 7.98453L6.51707 8.05904L6.03401 6.00862L8.08443 6.49168L8.00992 4.3873L9.92672 5.26092L10.2659 3.18223L11.9746 4.41043L12.712 2.44224L14.1483 3.97876L15.2558 2.19043L16.3632 3.97876L17.7995 2.44224L18.5369 4.41043L20.2456 3.18223L20.5848 5.26092L22.5016 4.3873L22.4271 6.49168L24.4775 6.00862L23.9944 8.05904L26.0988 7.98453L25.2252 9.90133L27.3039 10.2405L26.0757 11.9492L28.0439 12.6866L26.5073 14.1229Z" fill="black" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"> </path> </g> <defs> <clippath id="clip0_5454_14623"> <rect fill="black" height="30" width="30"> </rect> </clippath> </defs> </svg> <span> Rust </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/languages/scala/scala-driver/current/tutorials/indexes/#get-a-list-of-indexes-on-a-collection" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 70 70" width="24" xmlns="http://www.w3.org/2000/svg"> <defs> <lineargradient id=":R3pt5qcmqn9:aaa" x1=".006%" x2="96.837%" y1="49.998%" y2="49.998%"> <stop offset="0%" stop-color="#CD413F"> </stop> <stop offset="75.091%" stop-color="#CD4543"> </stop> <stop offset="100%" stop-color="#D04543"> </stop> </lineargradient> </defs> <g fill="none" fill-rule="nonzero"> <path d="M13 39v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 36.745 13 38.157 13 39M13 20v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 17.745 13 19.157 13 20" fill="#731818"> </path> <g fill="url(#:R3pt5qcmqn9:aaa)" transform="translate(13)"> <path d="M0 29.53v14.766c0-1.232 39-3.692 39-9.844V19.686c0 6.152-39 8.612-39 9.844M0 9.843V24.61c0-1.231 39-3.691 39-9.843V0C39 6.152 0 8.612 0 9.843M0 49.216v14.766c0-1.231 39-3.691 39-9.843V39.373c0 6.151-39 8.612-39 9.843"> </path> </g> </g> </svg> <span> Scala </span> </a> </div> <button class="leafygreen-ui-ki2t97"> Show all <svg aria-label="Chevron Down Icon" class="" fill="none" height="16" role="img" viewbox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"> <path clip-rule="evenodd" d="M1.636 5.364a1 1 0 0 0 0 1.414l4.95 4.95.707.707a1 1 0 0 0 1.414 0l.707-.707 4.95-4.95a1 1 0 0 0 0-1.414l-.707-.707a1 1 0 0 0-1.414 0L8 8.899 3.757 4.657a1 1 0 0 0-1.414 0l-.707.707Z" fill="currentColor" fill-rule="evenodd"> </path> </svg> </button> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> db.collection.getIndexes() </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.collection.getIndexes" title="Permalink to this definition"> <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="mongodb-method-db.collection.getIndexes"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Returns an array that holds a list of documents that identify and describe the existing indexes on the collection, including <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-hidden/#std-label-index-type-hidden"> hidden indexes <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> You must call <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.getIndexes" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.getIndexes() </code> </span> </a> on a collection. For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.getIndexes()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">getIndexes</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> <p class="leafygreen-ui-1kp3ins"> Change <code class="leafygreen-ui-1l06pbn"> collection </code> to the name of the collection for which to return index information. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Atlas Search Indexes <a class="headerlink leafygreen-ui-1kepx47" href="#atlas-search-indexes" 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="atlas-search-indexes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> getIndexes() </code> does not return information on <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/atlas-search-overview/#fts-indexes" target="_self"> <span> Atlas Search indexes </span> </a> . For information on Atlas Search indexes, use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/listSearchIndexes/#mongodb-pipeline-pipe.-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> $listSearchIndexes </code> . </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Client Disconnection <a class="headerlink leafygreen-ui-1kepx47" href="#client-disconnection" 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="client-disconnection"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 4.2, if the client that issued <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.getIndexes" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.getIndexes() </code> </span> </a> disconnects before the operation completes, MongoDB marks <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.getIndexes" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.getIndexes() </code> </span> </a> for termination using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/killOp/#mongodb-dbcommand-dbcmd.killOp"> <code class="leafygreen-ui-1l06pbn"> killOp </code> . </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Replica Set Member State Restriction <a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-member-state-restriction" 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="replica-set-member-state-restriction"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To run on a replica set member, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/listIndexes/#mongodb-dbcommand-dbcmd.listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> operations require the member to be in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY"> <code class="leafygreen-ui-1l06pbn"> PRIMARY </code> </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY"> <code class="leafygreen-ui-1l06pbn"> SECONDARY </code> </a> state. If the member is in another state, such as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.STARTUP2"> <code class="leafygreen-ui-1l06pbn"> STARTUP2 </code> </a> , the operation errors. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Wildcard Indexes <a class="headerlink leafygreen-ui-1kepx47" href="#wildcard-indexes" 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="wildcard-indexes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 6.3, 6.0.5, and 5.0.16, the <code class="leafygreen-ui-1l06pbn"> wildcardProjection </code> field stores the index projection in its submitted form. Earlier versions of the server may have stored the projection in a normalized form. </p> <p class="leafygreen-ui-1kp3ins"> The server uses the index the same way, but you may notice a difference in the output of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/listIndexes/#mongodb-dbcommand-dbcmd.listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.getIndexes" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.getIndexes() </code> </span> </a> commands. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Required Access <a class="headerlink leafygreen-ui-1kepx47" href="#required-access" 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="required-access"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To run <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.getIndexes" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.getIndexes() </code> </span> </a> when access control is enforced, users must have privileges to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> on the collection. </p> <p class="leafygreen-ui-1kp3ins"> The built-in role <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-read"> <code class="leafygreen-ui-1l06pbn"> read </code> </a> provides the required privileges to run <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.getIndexes" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.getIndexes() </code> </span> </a> for the collections in a database. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Output <a class="headerlink leafygreen-ui-1kepx47" href="#output" 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="output"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.getIndexes" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.getIndexes() </code> </span> </a> returns an array of documents that hold index information for the collection. For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n \"v\" : 2,\n \"key\" : {\n \"_id\" : 1\n },\n \"name\" : \"_id_\"\n },\n {\n \"v\" : 2,\n \"key\" : {\n \"status\" : 1\n },\n \"name\" : \"status_1\"\n },\n {\n \"v\" : 2,\n \"key\" : {\n \"points\" : 1\n },\n \"name\" : \"points_1\"\n }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"v"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"key"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</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"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"_id_"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"v"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"key"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"status"</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"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"status_1"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"v"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"key"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"points"</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"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"points_1"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Index information includes the keys and options used to create the index. The index option <code class="leafygreen-ui-1l06pbn"> hidden </code> is only available if the value is <code class="leafygreen-ui-1l06pbn"> true </code> . </p> <p class="leafygreen-ui-1kp3ins"> For information on the keys and index options, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex"> <code class="leafygreen-ui-1l06pbn"> db.collection.createIndex() </code> . </a> </p> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $search (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-search--aggregation-" 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="-search--aggregation-"> </div> </a> </h1> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $search </code> aggregation pipeline stage performs a full-text search of the field or fields in an Atlas collection. The fields must be covered by an <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/index-definitions/" target="_self"> <span> Atlas Search </span> </a> index. See: </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/reference/atlas-search/index-definitions/" target="_self"> <span> Index Definitions </span> </a> to learn more about creating and managing Atlas Search indexes. </p> </li> <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/reference/atlas-search/query-syntax/" target="_self"> <span> Atlas Search Aggregation Pipeline Stages </span> </a> to learn more about the <code class="leafygreen-ui-1l06pbn"> $search </code> pipeline stage syntax and usage. </p> </li> <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/reference/atlas-search/operators/" target="_self"> <span> $search Operators </span> </a> to learn more about the <code class="leafygreen-ui-1l06pbn"> $search </code> aggregation pipeline stage operators. </p> </li> </ul> </section>
https://www.mongodb.com/docs/manual/reference/command/split/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> split <a class="headerlink leafygreen-ui-1kepx47" href="#split" 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="split"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self"> <span> Command Fields </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self"> <span> Considerations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-formats" target="_self"> <span> Command Formats </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#metadata-lock-error" target="_self"> <span> Metadata Lock Error </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="dbcommand"> <dt> <code class="leafygreen-ui-1l06pbn"> split </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.split" title="Permalink to this definition"> <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="mongodb-dbcommand-dbcmd.split"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Splits a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk"> chunk </a> in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster </a> into two chunks. Shards manage and split chunks based on the chunk size statistics they maintain. </p> <p class="leafygreen-ui-1kp3ins"> For exceptional circumstances the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> command does allow administrators to manually create splits. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/split-chunks-in-sharded-cluster/"> Split Chunks in a Sharded Cluster </a> for information on these circumstances, and on the MongoDB shell commands that wrap <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> command must be run in the <code class="leafygreen-ui-1l06pbn"> admin </code> database. </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"> In <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongosh </code> </span> </a> , this command can also be run through the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.splitAt/#mongodb-method-sh.splitAt"> <code class="leafygreen-ui-1l06pbn"> sh.splitAt() </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.splitFind/#mongodb-method-sh.splitFind"> <code class="leafygreen-ui-1l06pbn"> sh.splitFind() </code> </a> helper methods <!-- --> . </p> <p class="leafygreen-ui-1kp3ins"> Helper methods are convenient for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongosh </code> </span> </a> users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command. </p> </div> </div> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This command is available in deployments hosted 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> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command is not supported in serverless instances. For more information, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self"> <span> Unsupported Commands <!-- --> . </span> </a> </p> </div> </div> <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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n split: &lt;database&gt;.&lt;collection&gt;, &lt;find|middle|bounds&gt;\n }\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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">split</span>: &lt;<!-- -->database<!-- -->&gt;<!-- -->.<!-- -->&lt;<!-- -->collection<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-xml">&lt;find|middle|bounds&gt;</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-xml"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-xml">)</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Command Fields <a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" 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="command-fields"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command takes the following fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> split </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The name of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-collection"> collection </a> where the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk"> chunk </a> exists. Specify the collection's full <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace"> namespace </a> , including the database name. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> find </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> An query statement that specifies an equality match on the shard key. The match selects the chunk that contains the specified document. You must specify only one of the following: <code class="leafygreen-ui-1l06pbn"> find </code> , <code class="leafygreen-ui-1l06pbn"> bounds </code> , or <code class="leafygreen-ui-1l06pbn"> middle </code> . </p> <p class="leafygreen-ui-1kp3ins"> You cannot use the <code class="leafygreen-ui-1l06pbn"> find </code> option on an empty collection. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> bounds </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> array </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> bounds </code> applies to chunks in collections partitioned using a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-hashed-shard-key"> hashed shard key </a> . The parameter's array must consist of two documents specifying the lower and upper shard-key values of the chunk. The values must match the minimum and maximum values of an existing chunk. Specify only one of the following: <code class="leafygreen-ui-1l06pbn"> find </code> , <code class="leafygreen-ui-1l06pbn"> bounds </code> , or <code class="leafygreen-ui-1l06pbn"> middle </code> . </p> <p class="leafygreen-ui-1kp3ins"> You cannot use the <code class="leafygreen-ui-1l06pbn"> bounds </code> option on an empty collection. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> middle </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The document to use as the split point to create two chunks. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> requires one of the following options: <code class="leafygreen-ui-1l06pbn"> find </code> , <code class="leafygreen-ui-1l06pbn"> bounds </code> , or <code class="leafygreen-ui-1l06pbn"> middle </code> . </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> When used with either the <code class="leafygreen-ui-1l06pbn"> find </code> or the <code class="leafygreen-ui-1l06pbn"> bounds </code> option, the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> command splits the chunk along the median. As such, the command cannot use the <code class="leafygreen-ui-1l06pbn"> find </code> or the <code class="leafygreen-ui-1l06pbn"> bounds </code> option to split an empty chunk since an empty chunk has no median. </p> <p class="leafygreen-ui-1kp3ins"> To create splits in empty chunks, use either the <code class="leafygreen-ui-1l06pbn"> middle </code> option with the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> command or use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.splitAt/#mongodb-method-sh.splitAt"> <code class="leafygreen-ui-1l06pbn"> sh.splitAt() </code> </a> command. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Command Formats <a class="headerlink leafygreen-ui-1kepx47" href="#command-formats" 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="command-formats"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To create a chunk split, 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> instance, and issue the following command to the <code class="leafygreen-ui-1l06pbn"> admin </code> database: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { split: &lt;database&gt;.&lt;collection&gt;,\n find: &lt;document&gt; } )","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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">split</span>: &lt;<!-- -->database<!-- -->&gt;<!-- -->.<!-- -->&lt;<!-- -->collection<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">find</span>: &lt;<span class="lg-highlight-variable lg-highlight-language">document</span>&gt; <!-- -->} )</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"> Or: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { split: &lt;database&gt;.&lt;collection&gt;,\n middle: &lt;document&gt; } )","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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">split</span>: &lt;<!-- -->database<!-- -->&gt;<!-- -->.<!-- -->&lt;<!-- -->collection<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">middle</span>: &lt;<span class="lg-highlight-variable lg-highlight-language">document</span>&gt; <!-- -->} )</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"> Or: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { split: &lt;database&gt;.&lt;collection&gt;,\n bounds: [ &lt;lower&gt;, &lt;upper&gt; ] } )","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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">split</span>: &lt;<!-- -->database<!-- -->&gt;<!-- -->.<!-- -->&lt;<!-- -->collection<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bounds</span>: <!-- -->[ &lt;<!-- -->lower<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->upper<!-- -->&gt; <!-- -->] } )</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 create a split for a collection that uses a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-hashed-shard-key"> hashed shard key </a> , use the <code class="leafygreen-ui-1l06pbn"> bounds </code> parameter. Do <em> not </em> use the <code class="leafygreen-ui-1l06pbn"> middle </code> parameter for this purpose. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Be careful when splitting data in a sharded collection to create new chunks. When you shard a collection that has existing data, MongoDB automatically creates chunks to evenly distribute the collection. To split data effectively in a sharded cluster you must consider the number of documents in a chunk and the average document size to create a uniform chunk size. When chunks have irregular sizes, shards may have an equal number of chunks but have very different data sizes. Avoid creating splits that lead to a collection with differently sized chunks. </p> </div> </div> <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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveChunk/#mongodb-dbcommand-dbcmd.moveChunk"> <code class="leafygreen-ui-1l06pbn"> moveChunk </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveRange/#mongodb-dbcommand-dbcmd.moveRange"> <code class="leafygreen-ui-1l06pbn"> moveRange </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.moveChunk/#mongodb-method-sh.moveChunk"> <code class="leafygreen-ui-1l06pbn"> sh.moveChunk() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.splitAt/#mongodb-method-sh.splitAt"> <code class="leafygreen-ui-1l06pbn"> sh.splitAt() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.splitFind/#mongodb-method-sh.splitFind"> <code class="leafygreen-ui-1l06pbn"> sh.splitFind() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> </p> </li> </ul> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following sections provide examples of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> command. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Split a Chunk in Half <a class="headerlink leafygreen-ui-1kepx47" href="#split-a-chunk-in-half" 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="split-a-chunk-in-half"> </div> </a> </h3> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { split : \"test.people\", find : { _id : 99 } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <!-- -->split <!-- -->: <span class="lg-highlight-string">"test.people"</span>, <!-- -->find <!-- -->: <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">99</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> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> command identifies the chunk in the <code class="leafygreen-ui-1l06pbn"> people </code> collection of the <code class="leafygreen-ui-1l06pbn"> test </code> database, that holds documents that match <code class="leafygreen-ui-1l06pbn"> { _id : 99 } </code> . <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> does not require that a match exist, in order to identify the appropriate chunk. Then the command splits it into two chunks of equal size. </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"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> creates two equal chunks by range as opposed to size, and does not use the selected point as a boundary for the new chunks. </p> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Define an Arbitrary Split Point <a class="headerlink leafygreen-ui-1kepx47" href="#define-an-arbitrary-split-point" 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="define-an-arbitrary-split-point"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To define an arbitrary split point, use the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { split : \"test.people\", middle : { _id : 99 } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <!-- -->split <!-- -->: <span class="lg-highlight-string">"test.people"</span>, <!-- -->middle <!-- -->: <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">99</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> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> command identifies the chunk in the <code class="leafygreen-ui-1l06pbn"> people </code> collection of the <code class="leafygreen-ui-1l06pbn"> test </code> database, that would hold documents matching the query <code class="leafygreen-ui-1l06pbn"> { _id : 99 } </code> . <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> does not require that a match exist, in order to identify the appropriate chunk. Then the command splits it into two chunks, with the matching document as the lower bound of one of the split chunks. </p> <p class="leafygreen-ui-1kp3ins"> This form is typically used when <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-pre-splitting"> pre-splitting </a> data in a collection. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Split a Chunk Using Values of a Hashed Shard Key <a class="headerlink leafygreen-ui-1kepx47" href="#split-a-chunk-using-values-of-a-hashed-shard-key" 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="split-a-chunk-using-values-of-a-hashed-shard-key"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> This example uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-hashed-shard-key"> hashed shard key </a> <code class="leafygreen-ui-1l06pbn"> userid </code> in a <code class="leafygreen-ui-1l06pbn"> people </code> collection of a <code class="leafygreen-ui-1l06pbn"> test </code> database. The following command uses an array holding two single-field documents to represent the minimum and maximum values of the hashed shard key to split the chunk: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { split: \"test.people\",\n bounds : [ { userid: NumberLong(\"-5838464104018346494\") },\n { userid: NumberLong(\"-5557153028469814163\") }\n ] } )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">split</span>: <span class="lg-highlight-string">"test.people"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->bounds <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"-5838464104018346494"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">userid</span>: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"-5557153028469814163"</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 class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> MongoDB uses the 64-bit <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-long" target="_self"> <span> NumberLong </span> </a> type to represent the hashed value. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.status/#mongodb-method-sh.status"> <code class="leafygreen-ui-1l06pbn"> sh.status() </code> </a> to see the existing bounds of the shard keys. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Metadata Lock Error <a class="headerlink leafygreen-ui-1kepx47" href="#metadata-lock-error" 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="metadata-lock-error"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> If another process, such as a balancer process, changes metadata while <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> is running, you may see a <code class="leafygreen-ui-1l06pbn"> metadata lock error </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"errmsg: \"The collection's metadata lock is already taken.\""} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">errmsg: "The collection's metadata lock is already taken."</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"> This message indicates that the split has failed with no side effects. Retry the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.split" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> split </code> </span> </a> command. </p> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/db.collection.findOneAndUpdate/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> db.collection.findOneAndUpdate() <a class="headerlink leafygreen-ui-1kepx47" href="#db.collection.findoneandupdate--" 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="db.collection.findoneandupdate--"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <div class="leafygreen-ui-147elvs"> <p class="leafygreen-ui-1ronz74"> MongoDB with drivers </p> <div class="leafygreen-ui-18k5rfm"> <p class="leafygreen-ui-1kp3ins"> This page documents a <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> method. To see the equivalent method in a MongoDB driver, see the corresponding page for your programming language: </p> </div> <div class="leafygreen-ui-zgrwqu notranslate"> <a class="leafygreen-ui-v22cck" href="https://mongodb.github.io/mongo-csharp-driver/2.29.0/api/MongoDB.Driver/MongoDB.Driver.MongoCollectionBase-1.FindOneAndUpdate.html" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59964)"> <g clip-path="url(#clip1_1351_59964)"> <path d="M25.7709 9.2495C25.7709 8.79827 25.678 8.39408 25.4827 8.04627C25.2874 7.70785 25.0084 7.42586 24.627 7.20025C21.465 5.35781 18.2937 3.51538 15.1317 1.67295C14.2761 1.17474 13.4484 1.19354 12.6021 1.70115C11.3466 2.45316 5.04112 6.10042 3.15321 7.20025C2.3813 7.65142 2 8.34705 2 9.24005C2 12.9531 2 16.6568 2 20.3698C2 20.8117 2.093 21.2064 2.279 21.5449C2.4743 21.8927 2.7626 22.1841 3.15321 22.4191C5.03182 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2761 28.4446 15.1317 27.9463C18.2937 26.1039 21.465 24.2615 24.627 22.4191C25.0177 22.1935 25.306 21.9021 25.5012 21.5449C25.6873 21.2064 25.7803 20.8117 25.7803 20.3698C25.7709 20.3698 25.7709 12.9531 25.7709 9.2495Z" fill="#A179DC"> </path> <path d="M13.9227 14.7673L2.27905 21.5449C2.47435 21.8927 2.76265 22.1841 3.15326 22.4191C5.03187 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2762 28.4445 15.1317 27.9463C18.2938 26.1039 21.4651 24.2615 24.6271 22.4191C25.0177 22.1935 25.306 21.9021 25.5013 21.5449L13.9227 14.7673Z" fill="#280068"> </path> <path d="M25.7711 9.24949C25.7711 8.79827 25.6781 8.39408 25.4828 8.04626L13.9229 14.7768L25.4921 21.5543C25.6781 21.2159 25.7711 20.8211 25.7711 20.3793C25.7711 20.3699 25.7711 12.9531 25.7711 9.24949Z" fill="#390091"> </path> <path d="M20.7771 12.2387V13.5078H22.0325V12.2387H22.6557V13.5078H23.9111V14.1376H22.6557V15.4066H23.9111V16.0364H22.6557V17.3054H22.0325V16.0364H20.7771V17.3054H20.1539V16.0364H18.8984V15.4066H20.1539V14.1376H18.8984V13.5078H20.1539V12.2387H20.7771ZM22.0325 14.1376H20.7771V15.4066H22.0325V14.1376Z" fill="white"> </path> <path d="M13.9508 5.87482C17.2151 5.87482 20.0702 7.67022 21.6047 10.3399L21.5861 10.3117L17.7452 12.5489C16.9919 11.2517 15.5969 10.3775 14.0066 10.3587H13.9601C11.5328 10.3587 9.56116 12.3515 9.56116 14.805C9.56116 15.604 9.77503 16.3654 10.1377 17.014C10.9004 18.3488 12.3232 19.2512 13.9601 19.2512C15.6062 19.2512 17.0384 18.3394 17.7917 16.9858L17.7731 17.014L21.614 19.2606C20.0981 21.9021 17.2895 23.6975 14.0531 23.7257H13.9508C10.6679 23.7257 7.81274 21.9209 6.28753 19.2418C5.54353 17.9352 5.11572 16.4124 5.11572 14.7956C5.11572 9.87931 9.06825 5.87482 13.9508 5.87482Z" fill="white"> </path> </g> </g> <defs> <clippath id="clip0_1351_59964"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59964"> <rect fill="white" height="27" transform="translate(2 1.30966)" width="24"> </rect> </clippath> </defs> </svg> <span> C# </span> </a> <a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/java/sync/current/fundamentals/crud/compound-operations/#find-and-update" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD"> </path> <path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD"> </path> <path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E"> </path> <path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD"> </path> <path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD"> </path> <path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD"> </path> <path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E"> </path> <path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD"> </path> </svg> <span> Java Sync </span> </a> <a class="leafygreen-ui-v22cck" href="https://mongodb.github.io/node-mongodb-native/6.9/classes/Collection.html#findOneAndUpdate" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 30" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:R2dtlqcmqn9:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R2dtlqcmqn9:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":R2dtlqcmqn9:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":R2dtlqcmqn9:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <span> Node.js </span> </a> <a class="leafygreen-ui-v22cck" href="https://pymongo.readthedocs.io/en/stable/api/pymongo/collection.html#pymongo.collection.Collection.find_one_and_update" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 111.6 147" width="24" xmlns="http://www.w3.org/2000/svg"> <lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R2htlqcmqn9:aa" x1="280.848" x2="389.865" y1="-268.463" y2="-362.257"> <stop offset="0" stop-color="#5a9fd4"> </stop> <stop offset="1" stop-color="#306998"> </stop> </lineargradient> <path d="M55.3 3.2c-4.6 0-9 .4-12.8 1.1-11.3 2-13.4 6.2-13.4 13.9v10.2h26.8v3.4H19c-7.8 0-14.6 4.7-16.8 13.6C-.3 55.6-.4 62 2.2 72.7c1.9 7.9 6.5 13.6 14.2 13.6h9.2V74c0-8.8 7.7-16.7 16.7-16.7h26.8c7.5 0 13.4-6.1 13.4-13.6V18.2c0-7.3-6.1-12.7-13.4-13.9-4.4-.8-9.2-1.1-13.8-1.1zm-14.5 8.2c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1s2.2-5.1 5-5.1z" fill="url(#:R2htlqcmqn9:aa)"> </path> <lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R2htlqcmqn9:bb" x1="432.011" x2="393.081" y1="-419.025" y2="-363.946"> <stop offset="0" stop-color="#ffd43b"> </stop> <stop offset="1" stop-color="#ffe873"> </stop> </lineargradient> <path d="M86 31.8v11.9c0 9.2-7.8 17-16.8 17H42.5c-7.3 0-13.4 6.3-13.4 13.6v25.5c0 7.3 6.3 11.5 13.4 13.6 8.5 2.5 16.6 2.9 26.8 0 6.8-2 13.4-5.9 13.4-13.6V89.7H55.9v-3.4h40.2c7.8 0 10.7-5.4 13.4-13.6 2.8-8.4 2.7-16.5 0-27.3-1.9-7.8-5.6-13.6-13.4-13.6H86zM71 96.5c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1-.1-2.8 2.2-5.1 5-5.1z" fill="url(#:R2htlqcmqn9:bb)"> </path> <radialgradient cx="-2274.721" cy="144.526" gradienttransform="matrix(0 -.2399 -1.0547 0 208.637 -414.922)" gradientunits="userSpaceOnUse" id=":R2htlqcmqn9:cc" r="29.037"> <stop offset="0" stop-color="#b8b8b8" stop-opacity=".498"> </stop> <stop offset="1" stop-color="#7f7f7f" stop-opacity="0"> </stop> </radialgradient> <path d="M92.1 130.9c0 3.8-16.1 7-35.9 7s-35.9-3.1-35.9-7c0-3.8 16.1-7 35.9-7s35.9 3.1 35.9 7z" fill="url(#:R2htlqcmqn9:cc)" opacity=".444"> </path> </svg> <span> PyMongo </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongoc.org/libmongoc/current/mongoc_collection_update_one.html" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59955)"> <g clip-path="url(#clip1_1351_59955)"> <path clip-rule="evenodd" d="M13.118 1.49532C13.5403 1.25103 14.0559 1.25103 14.4783 1.49532C16.5652 2.70389 22.8385 6.34889 24.9193 7.55748C25.3416 7.80172 25.6025 8.25176 25.6025 8.74672C25.6025 11.1703 25.6025 18.4539 25.6025 20.8774C25.6025 21.366 25.3416 21.8224 24.9193 22.0667C22.8385 23.2753 16.5652 26.9203 14.4783 28.1289C14.0559 28.3732 13.5403 28.3732 13.118 28.1289C11.0373 26.9139 4.76398 23.2689 2.68323 22.0603C2.26087 21.816 2 21.366 2 20.871C2 18.4474 2 11.1639 2 8.7403C2 8.25176 2.26087 7.7953 2.68323 7.55106C4.76398 6.34889 11.0373 2.70389 13.118 1.49532Z" fill="#004482" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M2.18634 21.4946C2.01863 21.2632 2 21.051 2 20.7553C2 18.351 2 11.1061 2 8.70176C2 8.21317 2.26087 7.76319 2.67702 7.51889C4.75776 6.31675 11.0062 2.69104 13.0807 1.4889C13.5031 1.24461 14.0683 1.25104 14.4907 1.49533C16.5652 2.69747 22.795 6.29104 24.8696 7.49319C25.0373 7.58963 25.1677 7.70535 25.2795 7.86606L2.18634 21.4946Z" fill="#659AD2" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M13.8011 5.8089C18.6024 5.8089 22.4968 9.83964 22.4968 14.8089C22.4968 19.7782 18.6024 23.8089 13.8011 23.8089C8.99986 23.8089 5.10547 19.7782 5.10547 14.8089C5.10547 9.83964 8.99986 5.8089 13.8011 5.8089ZM13.8011 10.3089C16.1987 10.3089 18.1489 12.3275 18.1489 14.8089C18.1489 17.2903 16.1987 19.3089 13.8011 19.3089C11.4036 19.3089 9.4533 17.2903 9.4533 14.8089C9.4533 12.3275 11.4036 10.3089 13.8011 10.3089Z" fill="white" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M25.2857 7.87247C25.6087 8.18102 25.6025 8.65034 25.6025 9.01673C25.6025 11.4596 25.5839 18.396 25.6087 20.8325C25.6087 21.0896 25.528 21.3532 25.4099 21.5589L13.5466 14.8089L25.2857 7.87247Z" fill="#00599C" fill-rule="evenodd"> </path> </g> </g> <defs> <clippath id="clip0_1351_59955"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59955"> <rect fill="white" height="27" transform="translate(2 1.30887)" width="24"> </rect> </clippath> </defs> </svg> <span> C </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongocxx.org/api/current/classmongocxx_1_1v__noabi_1_1collection.html#ab3cae2a4458d1b47fe0155a9409fdef1" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_1351_59959)"> <g clip-path="url(#clip1_1351_59959)"> <path d="M25.4013 21.5646C25.5872 21.2353 25.7034 20.8745 25.7034 20.5373V9.08012C25.7034 8.75078 25.5872 8.38217 25.4013 8.05283L13.8516 14.8127L25.4013 21.5646Z" fill="#00599C"> </path> <path d="M14.8738 28.0657L24.6729 22.3411C24.9517 22.1764 25.2151 21.8941 25.401 21.5647L13.8513 14.8127L2.30151 21.5647C2.48743 21.8941 2.74305 22.1764 3.02967 22.3411L12.8288 28.0657C13.3865 28.3951 14.316 28.3951 14.8738 28.0657Z" fill="#004482"> </path> <path d="M25.4011 8.06086C25.2152 7.73146 24.9596 7.44915 24.673 7.2845L14.8739 1.55983C14.3084 1.23046 13.3866 1.23046 12.8211 1.55983L3.02202 7.2845C2.46429 7.61385 1.99951 8.42158 1.99951 9.08033V20.5375C1.99951 20.8669 2.11571 21.2354 2.30162 21.5647L13.8514 14.8128L25.4011 8.06086Z" fill="#659AD2"> </path> <path d="M13.8512 22.8115C9.49778 22.8115 5.94995 19.2199 5.94995 14.8127C5.94995 10.4055 9.49778 6.81387 13.8512 6.81387C16.6631 6.81387 19.2813 8.34305 20.6912 10.8133L17.2751 12.813C16.5701 11.5818 15.261 10.8133 13.8512 10.8133C11.6745 10.8133 9.90055 12.6091 9.90055 14.8127C9.90055 17.0163 11.6745 18.8121 13.8512 18.8121C15.261 18.8121 16.5701 18.0436 17.2751 16.8124L20.6912 18.8121C19.2813 21.2745 16.6631 22.8115 13.8512 22.8115Z" fill="white"> </path> <path d="M21.7524 14.3657H20.8771V13.4796H19.994V14.3657H19.1187V15.2518H19.994V16.1458H20.8771V15.2518H21.7524V14.3657Z" fill="white"> </path> <path d="M25.0446 14.3657H24.1693V13.4796H23.2862V14.3657H22.4109V15.2518H23.2862V16.1458H24.1693V15.2518H25.0446V14.3657Z" fill="white"> </path> </g> </g> <defs> <clippath id="clip0_1351_59959"> <rect fill="white" height="28" transform="translate(0 0.809265)" width="28"> </rect> </clippath> <clippath id="clip1_1351_59959"> <rect fill="white" height="27" transform="translate(1.99951 1.30878)" width="24"> </rect> </clippath> </defs> </svg> <span> C++ </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/go/current/fundamentals/crud/compound-operations/#find-and-update" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" id="Layer_1" style="fill:#00ACD7" version="1.1" viewbox="0 0 205.4 76.7" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0"> <path class="st00" d="M15.5 23.2c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h35.7c.4 0 .5.3.3.6l-1.7 2.6c-.2.3-.7.6-1 .6l-36.2-.1zM.4 32.4c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h45.6c.4 0 .6.3.5.6l-.8 2.4c-.1.4-.5.6-.9.6l-47.3.1zM24.6 41.6c-.4 0-.5-.3-.3-.6l1.4-2.5c.2-.3.6-.6 1-.6h20c.4 0 .6.3.6.7l-.2 2.4c0 .4-.4.7-.7.7l-21.8-.1z"> </path> <g id="CXHf1q_3_"> <path class="st00" d="M128.4 21.4c-6.3 1.6-10.6 2.8-16.8 4.4-1.5.4-1.6.5-2.9-1-1.5-1.7-2.6-2.8-4.7-3.8-6.3-3.1-12.4-2.2-18.1 1.5-6.8 4.4-10.3 10.9-10.2 19 .1 8 5.6 14.6 13.5 15.7 6.8.9 12.5-1.5 17-6.6.9-1.1 1.7-2.3 2.7-3.7H89.6c-2.1 0-2.6-1.3-1.9-3 1.3-3.1 3.7-8.3 5.1-10.9.3-.6 1-1.6 2.5-1.6h36.4c-.2 2.7-.2 5.4-.6 8.1-1.1 7.2-3.8 13.8-8.2 19.6-7.2 9.5-16.6 15.4-28.5 17-9.8 1.3-18.9-.6-26.9-6.6-7.4-5.6-11.6-13-12.7-22.2-1.3-10.9 1.9-20.7 8.5-29.3C70.4 8.7 79.8 2.8 91.3.7c9.4-1.7 18.4-.6 26.5 4.9 5.3 3.5 9.1 8.3 11.6 14.1.6.9.2 1.4-1 1.7z"> </path> <path class="st00" d="M161.5 76.7c-9.1-.2-17.4-2.8-24.4-8.8-5.9-5.1-9.6-11.6-10.8-19.3-1.8-11.3 1.3-21.3 8.1-30.2 7.3-9.6 16.1-14.6 28-16.7 10.2-1.8 19.8-.8 28.5 5.1 7.9 5.4 12.8 12.7 14.1 22.3 1.7 13.5-2.2 24.5-11.5 33.9-6.6 6.7-14.7 10.9-24 12.8-2.7.5-5.4.6-8 .9zm23.8-40.4c-.1-1.3-.1-2.3-.3-3.3-1.8-9.9-10.9-15.5-20.4-13.3-9.3 2.1-15.3 8-17.5 17.4-1.8 7.8 2 15.7 9.2 18.9 5.5 2.4 11 2.1 16.3-.6 7.9-4.1 12.2-10.5 12.7-19.1z"> </path> </g> </svg> <span> Go </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#findOneAndUpdate(org.bson.conversions.Bson,org.bson.conversions.Bson)" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD"> </path> <path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD"> </path> <path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E"> </path> <path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD"> </path> <path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD"> </path> <path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD"> </path> <path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E"> </path> <path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD"> </path> </svg> <span> Java RS </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/kotlin/coroutine/current/fundamentals/crud/compound-operations/#find-and-update" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R35tlqcmqn9:paint0_linear_211_40588)"> </path> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R35tlqcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29"> <stop offset="0.00343514" stop-color="#E44857"> </stop> <stop offset="0.4689" stop-color="#C711E1"> </stop> <stop offset="1" stop-color="#7F52FF"> </stop> </lineargradient> </defs> </svg> <span> Kotlin Coroutine </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-kotlin-sync/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/find-one-and-update.html?query=fun%20findOneAndUpdate(clientSession:%20ClientSession,%20filter:%20Bson,%20update:%20Bson,%20options:%20FindOneAndUpdateOptions%20=%20FindOneAndUpdateOptions()):%20T?" target="_self"> <svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg"> <path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R39tlqcmqn9:paint0_linear_211_40588)"> </path> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":R39tlqcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29"> <stop offset="0.00343514" stop-color="#E44857"> </stop> <stop offset="0.4689" stop-color="#C711E1"> </stop> <stop offset="1" stop-color="#7F52FF"> </stop> </lineargradient> </defs> </svg> <span> Kotlin Sync </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/php-library/current/reference/method/MongoDBCollection-findOneAndUpdate/" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 700 301" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0"> <defs> <clippath clippathunits="userSpaceOnUse" id="a"> <path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439"> </path> </clippath> <clippath clippathunits="userSpaceOnUse" id="c"> <path d="M0 324h576V0H0v324z"> </path> </clippath> <clippath clippathunits="userSpaceOnUse" id="d"> <path d="M0 324h576V0H0v324z"> </path> </clippath> <radialgradient cx="0" cy="0" fx="0" fy="0" gradienttransform="matrix(363.05789 0 0 -363.05789 177.52 256.307)" gradientunits="userSpaceOnUse" id="b" r="1" spreadmethod="pad"> <stop offset="0" stop-color="#aeb2d5"> </stop> <stop offset=".3" stop-color="#aeb2d5"> </stop> <stop offset=".75" stop-color="#484c89"> </stop> <stop offset="1" stop-color="#484c89"> </stop> </radialgradient> </defs> <g clip-path="url(#a)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439" fill="url(#b)"> </path> </g> <g clip-path="url(#c)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M288 27.36c146.729 0 265.68 60.28 265.68 134.64 0 74.36-118.951 134.641-265.68 134.641S22.32 236.36 22.32 162.001C22.32 87.64 141.271 27.358 288 27.358" fill="#777bb3"> </path> </g> <g clip-path="url(#d)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)"> <path d="M161.734 145.307c12.065 0 21.072 2.225 26.771 6.61 5.638 4.342 9.532 11.863 11.573 22.354 1.903 9.806 1.178 16.653-2.154 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.28l-10.69-55h15.673zm-63.063-67.75a2.998 2.998 0 00-2.944 3.572l28.328 145.75a3 3 0 002.945 2.428h61.054c19.188 0 33.47-5.21 42.447-15.487 9.025-10.331 11.812-24.772 8.283-42.921-1.436-7.394-3.906-14.261-7.34-20.41-3.44-6.154-7.985-11.85-13.512-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.28-3.93-30.548-3.93h-24.722l-7.06-36.321a3 3 0 00-2.944-2.428h-31.75z"> </path> <path d="M159.224 197.307h16.808c13.42 0 18.083-2.945 19.667-4.7 2.628-2.914 3.124-9.058 1.435-17.767-1.898-9.75-5.416-16.663-10.458-20.545-5.162-3.974-13.554-5.988-24.941-5.988H149.7l9.523 49zm28.83 35H127a6 6 0 01-5.89-4.855L92.784 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.588 33.895h22.249c12.582 0 23.174 1.372 31.479 4.077 8.54 2.775 16.399 7.48 23.354 13.984 5.752 5.292 10.49 11.232 14.08 17.657 3.59 6.427 6.17 13.594 7.668 21.302 3.715 19.104.697 34.402-8.97 45.466-9.571 10.958-24.613 16.514-44.705 16.514m-45.633-90h19.313c12.8 0 22.336 2.411 28.6 7.234 6.267 4.824 10.493 12.875 12.689 24.157 2.1 10.832 1.144 18.476-2.871 22.93-4.02 4.452-12.06 6.68-24.121 6.68h-21.754l-11.856-61m45.633 84c18.367 0 31.766-4.82 40.188-14.462 8.42-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.621-3.782-29.621-3.782h-27.196l-7.531-38.75h-31.75L127 226.307h61.055" fill="#fff"> </path> <path d="M311.583 116.307c-.896 0-1.745.4-2.314 1.092a2.994 2.994 0 00-.631 2.48l12.531 64.489c1.192 6.133.898 10.535-.827 12.395-1.056 1.137-4.228 3.044-13.607 3.044h-22.702l-15.755-81.072a3 3 0 00-2.945-2.428h-31.5a2.998 2.998 0 00-2.945 3.572l28.328 145.75a3 3 0 002.945 2.428h31.5a3 3 0 002.945-3.572l-6.836-35.178h24.422c18.605 0 31.221-3.28 38.569-10.028 7.49-6.884 9.827-17.891 6.947-32.72l-13.18-67.824a3 3 0 00-2.945-2.428h-32z"> </path> <path d="M293.661 271.057h-31.5a6 6 0 01-5.89-4.855l-28.328-145.75a5.998 5.998 0 015.89-7.145h31.5a6 6 0 015.89 4.855l15.283 78.645h20.23c9.362 0 11.327-2 11.406-2.086.568-.61 1.315-3.44.082-9.78l-12.53-64.49a5.998 5.998 0 015.89-7.144h32a6 6 0 015.89 4.855l13.178 67.825c3.093 15.921.447 27.864-7.86 35.5-7.929 7.281-21.209 10.82-40.6 10.82h-20.784l6.143 31.605a6.001 6.001 0 01-5.89 7.145m0-6l-7.53-38.75h28.061c17.657 0 29.836-3.082 36.54-9.238 6.702-6.16 8.71-16.14 6.031-29.938l-13.18-67.824h-32l12.531 64.488c1.426 7.336.902 12.34-1.574 15.008-2.477 2.668-7.746 4.004-15.805 4.004H281.56l-16.226-83.5h-31.5l28.328 145.75h31.5" fill="#fff"> </path> <path d="M409.55 145.307c12.065 0 21.072 2.225 26.77 6.61 5.639 4.34 9.533 11.862 11.575 22.354 1.903 9.806 1.178 16.653-2.155 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.281l-10.69-55h15.674zm-63.062-67.75a2.999 2.999 0 00-2.945 3.572l28.328 145.75a3.002 3.002 0 002.946 2.428h61.053c19.189 0 33.47-5.21 42.448-15.487 9.025-10.33 11.81-24.771 8.283-42.921-1.438-7.394-3.907-14.261-7.342-20.41-3.44-6.154-7.984-11.85-13.511-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.281-3.93-30.548-3.93H388.24l-7.057-36.321a3.001 3.001 0 00-2.946-2.428h-31.75z"> </path> <path d="M407.04 197.307h16.807c13.421 0 18.083-2.945 19.667-4.7 2.63-2.914 3.125-9.058 1.435-17.766-1.898-9.75-5.417-16.664-10.458-20.546-5.162-3.974-13.554-5.988-24.94-5.988h-12.034l9.522 49zm28.83 35h-61.054a6 6 0 01-5.889-4.855L340.6 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.587 33.895h22.25c12.581 0 23.173 1.372 31.478 4.077 8.541 2.775 16.401 7.481 23.356 13.986 5.752 5.291 10.488 11.23 14.078 17.655 3.591 6.427 6.171 13.594 7.668 21.302 3.715 19.105.697 34.403-8.969 45.467-9.572 10.957-24.613 16.513-44.706 16.513m-45.632-90h19.312c12.801 0 22.336 2.411 28.601 7.234 6.267 4.824 10.492 12.875 12.688 24.157 2.102 10.832 1.145 18.476-2.87 22.93-4.02 4.452-12.06 6.68-24.122 6.68h-21.754l-11.855-61m45.632 84c18.367 0 31.766-4.82 40.188-14.462 8.422-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.62-3.782-29.62-3.782h-27.197l-7.53-38.75h-31.75l28.328 145.75h61.054" fill="#fff"> </path> </g> </svg> <span> PHP </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.rubydoc.info/github/mongoid/mongoid/Mongoid/Contextual/Mongo:find_one_and_update" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" preserveaspectratio="xMidYMid" viewbox="0 0 300 240" width="24" xmlns="http://www.w3.org/2000/svg"> <defs> <lineargradient id=":R3htlqcmqn9:a" x1="84.75%" x2="58.254%" y1="111.399%" y2="64.584%"> <stop offset="0%" stop-color="#FB7655"> </stop> <stop offset="0%" stop-color="#FB7655"> </stop> <stop offset="41%" stop-color="#E42B1E"> </stop> <stop offset="99%" stop-color="#900"> </stop> <stop offset="100%" stop-color="#900"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:b" x1="116.651%" x2="1.746%" y1="60.89%" y2="19.288%"> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="99%" stop-color="#911209"> </stop> <stop offset="100%" stop-color="#911209"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:c" x1="75.774%" x2="38.978%" y1="219.327%" y2="7.829%"> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="0%" stop-color="#871101"> </stop> <stop offset="99%" stop-color="#911209"> </stop> <stop offset="100%" stop-color="#911209"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:d" x1="50.012%" x2="66.483%" y1="7.234%" y2="79.135%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="23%" stop-color="#E57252"> </stop> <stop offset="46%" stop-color="#DE3B20"> </stop> <stop offset="99%" stop-color="#A60003"> </stop> <stop offset="100%" stop-color="#A60003"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:e" x1="46.174%" x2="49.932%" y1="16.348%" y2="83.047%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="23%" stop-color="#E4714E"> </stop> <stop offset="56%" stop-color="#BE1A0D"> </stop> <stop offset="99%" stop-color="#A80D00"> </stop> <stop offset="100%" stop-color="#A80D00"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:f" x1="36.965%" x2="49.528%" y1="15.594%" y2="92.478%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="18%" stop-color="#E46342"> </stop> <stop offset="40%" stop-color="#C82410"> </stop> <stop offset="99%" stop-color="#A80D00"> </stop> <stop offset="100%" stop-color="#A80D00"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:g" x1="13.609%" x2="85.764%" y1="58.346%" y2="-46.717%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="54%" stop-color="#C81F11"> </stop> <stop offset="99%" stop-color="#BF0905"> </stop> <stop offset="100%" stop-color="#BF0905"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:h" x1="27.624%" x2="50.745%" y1="21.135%" y2="79.056%"> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="0%" stop-color="#FFF"> </stop> <stop offset="31%" stop-color="#DE4024"> </stop> <stop offset="99%" stop-color="#BF190B"> </stop> <stop offset="100%" stop-color="#BF190B"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:i" x1="-20.667%" x2="104.242%" y1="122.282%" y2="-6.342%"> <stop offset="0%" stop-color="#BD0012"> </stop> <stop offset="0%" stop-color="#BD0012"> </stop> <stop offset="7%" stop-color="#FFF"> </stop> <stop offset="17%" stop-color="#FFF"> </stop> <stop offset="27%" stop-color="#C82F1C"> </stop> <stop offset="33%" stop-color="#820C01"> </stop> <stop offset="46%" stop-color="#A31601"> </stop> <stop offset="72%" stop-color="#B31301"> </stop> <stop offset="99%" stop-color="#E82609"> </stop> <stop offset="100%" stop-color="#E82609"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:j" x1="58.792%" x2="11.964%" y1="65.205%" y2="50.128%"> <stop offset="0%" stop-color="#8C0C01"> </stop> <stop offset="0%" stop-color="#8C0C01"> </stop> <stop offset="54%" stop-color="#990C00"> </stop> <stop offset="99%" stop-color="#A80D0E"> </stop> <stop offset="100%" stop-color="#A80D0E"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:k" x1="79.319%" x2="23.088%" y1="62.754%" y2="17.888%"> <stop offset="0%" stop-color="#7E110B"> </stop> <stop offset="0%" stop-color="#7E110B"> </stop> <stop offset="99%" stop-color="#9E0C00"> </stop> <stop offset="100%" stop-color="#9E0C00"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:l" x1="92.88%" x2="59.841%" y1="74.122%" y2="39.704%"> <stop offset="0%" stop-color="#79130D"> </stop> <stop offset="0%" stop-color="#79130D"> </stop> <stop offset="99%" stop-color="#9E120B"> </stop> <stop offset="100%" stop-color="#9E120B"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:o" x1="56.57%" x2="3.105%" y1="101.717%" y2="11.993%"> <stop offset="0%" stop-color="#8B2114"> </stop> <stop offset="0%" stop-color="#8B2114"> </stop> <stop offset="43%" stop-color="#9E100A"> </stop> <stop offset="99%" stop-color="#B3100C"> </stop> <stop offset="100%" stop-color="#B3100C"> </stop> </lineargradient> <lineargradient id=":R3htlqcmqn9:p" x1="30.87%" x2="92.471%" y1="35.599%" y2="100.694%"> <stop offset="0%" stop-color="#B31000"> </stop> <stop offset="0%" stop-color="#B31000"> </stop> <stop offset="44%" stop-color="#910F08"> </stop> <stop offset="99%" stop-color="#791C12"> </stop> <stop offset="100%" stop-color="#791C12"> </stop> </lineargradient> <radialgradient cx="32.001%" cy="40.21%" fx="32.001%" fy="40.21%" id=":R3htlqcmqn9:m" r="69.573%"> <stop offset="0%" stop-color="#A80D00"> </stop> <stop offset="0%" stop-color="#A80D00"> </stop> <stop offset="99%" stop-color="#7E0E08"> </stop> <stop offset="100%" stop-color="#7E0E08"> </stop> </radialgradient> <radialgradient cx="13.549%" cy="40.86%" fx="13.549%" fy="40.86%" id=":R3htlqcmqn9:n" r="88.386%"> <stop offset="0%" stop-color="#A30C00"> </stop> <stop offset="0%" stop-color="#A30C00"> </stop> <stop offset="99%" stop-color="#800E08"> </stop> <stop offset="100%" stop-color="#800E08"> </stop> </radialgradient> </defs> <path d="M197.467 167.764l-145.52 86.41 188.422-12.787L254.88 51.393l-57.414 116.37z" fill="url(#:R3htlqcmqn9:a)"> </path> <path d="M240.677 241.257L224.482 129.48l-44.113 58.25 60.308 53.528z" fill="url(#:R3htlqcmqn9:b)"> </path> <path d="M240.896 241.257l-118.646-9.313-69.674 21.986 188.32-12.673z" fill="url(#:R3htlqcmqn9:c)"> </path> <path d="M52.744 253.955l29.64-97.1L17.16 170.8l35.583 83.154z" fill="url(#:R3htlqcmqn9:d)"> </path> <path d="M180.358 188.05L153.085 81.226l-78.047 73.16 105.32 33.666z" fill="url(#:R3htlqcmqn9:e)"> </path> <path d="M248.693 82.73l-73.777-60.256-20.544 66.418 94.321-6.162z" fill="url(#:R3htlqcmqn9:f)"> </path> <path d="M214.191.99L170.8 24.97 143.424.669l70.767.322z" fill="url(#:R3htlqcmqn9:g)"> </path> <path d="M0 203.372l18.177-33.151-14.704-39.494L0 203.372z" fill="url(#:R3htlqcmqn9:h)"> </path> <path d="M2.496 129.48l14.794 41.963 64.283-14.422 73.39-68.207 20.712-65.787L143.063 0 87.618 20.75c-17.469 16.248-51.366 48.396-52.588 49-1.21.618-22.384 40.639-32.534 59.73z" fill="#FFF"> </path> <path d="M54.442 54.094c37.86-37.538 86.667-59.716 105.397-40.818 18.72 18.898-1.132 64.823-38.992 102.349-37.86 37.525-86.062 60.925-104.78 42.027-18.73-18.885.515-66.032 38.375-103.558z" fill="url(#:R3htlqcmqn9:i)"> </path> <path d="M52.744 253.916l29.408-97.409 97.665 31.376c-35.312 33.113-74.587 61.106-127.073 66.033z" fill="url(#:R3htlqcmqn9:j)"> </path> <path d="M155.092 88.622l25.073 99.313c29.498-31.016 55.972-64.36 68.938-105.603l-94.01 6.29z" fill="url(#:R3htlqcmqn9:k)"> </path> <path d="M248.847 82.833c10.035-30.282 12.35-73.725-34.966-81.791l-38.825 21.445 73.791 60.346z" fill="url(#:R3htlqcmqn9:l)"> </path> <path d="M0 202.935c1.39 49.979 37.448 50.724 52.808 51.162l-35.48-82.86L0 202.935z" fill="#9E1209"> </path> <path d="M155.232 88.777c22.667 13.932 68.35 41.912 69.276 42.426 1.44.81 19.695-30.784 23.838-48.64l-93.114 6.214z" fill="url(#:R3htlqcmqn9:m)"> </path> <path d="M82.113 156.507l39.313 75.848c23.246-12.607 41.45-27.967 58.121-44.42l-97.434-31.428z" fill="url(#:R3htlqcmqn9:n)"> </path> <path d="M17.174 171.34l-5.57 66.328c10.51 14.357 24.97 15.605 40.136 14.486-10.973-27.311-32.894-81.92-34.566-80.814z" fill="url(#:R3htlqcmqn9:o)"> </path> <path d="M174.826 22.654l78.1 10.96c-4.169-17.662-16.969-29.06-38.787-32.623l-39.313 21.663z" fill="url(#:R3htlqcmqn9:p)"> </path> </svg> <span> Mongoid </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/rust/current/fundamentals/crud/compound-operations/#find-and-update-a-document" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 30 30" width="24" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_5454_14623)"> <path d="M15.2561 3.08398C8.56014 3.08398 3.11035 8.53634 3.11035 15.2297C3.11035 21.9231 8.56271 27.3755 15.2561 27.3755C21.9495 27.3755 27.4019 21.9231 27.4019 15.2297C27.4019 8.53634 21.9495 3.08398 15.2561 3.08398ZM15.2381 4.16315C15.4458 4.16853 15.6432 4.25509 15.7881 4.40437C15.9331 4.55365 16.0142 4.75384 16.0141 4.96225C16.0141 5.17418 15.9299 5.37744 15.7801 5.5273C15.6302 5.67715 15.4269 5.76134 15.215 5.76134C15.0031 5.76134 14.7998 5.67715 14.65 5.5273C14.5001 5.37744 14.4159 5.17418 14.4159 4.96225C14.4159 4.85533 14.4373 4.7495 14.4789 4.65101C14.5205 4.55252 14.5814 4.46338 14.6581 4.38887C14.7347 4.31435 14.8256 4.25598 14.9252 4.21721C15.0249 4.17844 15.1313 4.16006 15.2381 4.16315ZM17.0676 5.47871C18.4704 5.74146 19.7992 6.30644 20.9617 7.13439C22.1242 7.96235 23.0926 9.03345 23.7995 10.2733L22.8565 12.4008C22.6947 12.7682 22.8617 13.1999 23.2265 13.3643L25.0406 14.1686C25.0968 14.7356 25.1037 15.3065 25.0611 15.8747H24.0513C23.9511 15.8747 23.91 15.9415 23.91 16.0391V16.5016C23.91 17.5911 23.2959 17.83 22.7563 17.8891C22.2424 17.9482 21.6746 17.6733 21.6026 17.3598C21.2994 15.6563 20.7958 15.294 19.9993 14.6645C20.9885 14.0375 22.0163 13.11 22.0163 11.8715C22.0163 10.5328 21.099 9.69002 20.4747 9.27634C19.5959 8.69822 18.6247 8.5826 18.3626 8.5826H7.93063C9.37312 6.97114 11.3066 5.88021 13.4318 5.47871L14.6626 6.76857C14.9401 7.05891 15.4 7.07176 15.6903 6.79169L17.0676 5.47871ZM5.71063 11.3936C5.91853 11.3996 6.11589 11.4864 6.26079 11.6356C6.40568 11.7849 6.48669 11.9847 6.4866 12.1927C6.4866 12.4046 6.40241 12.6079 6.25255 12.7577C6.10269 12.9076 5.89944 12.9918 5.6875 12.9918C5.47557 12.9918 5.27232 12.9076 5.12246 12.7577C4.9726 12.6079 4.88841 12.4046 4.88841 12.1927C4.88836 12.0858 4.90977 11.9799 4.95137 11.8814C4.99297 11.7829 5.0539 11.6938 5.13057 11.6193C5.20724 11.5448 5.29809 11.4864 5.39772 11.4476C5.49736 11.4089 5.60376 11.3905 5.71063 11.3936ZM24.7631 11.4295C24.971 11.4356 25.1683 11.5224 25.3132 11.6716C25.4581 11.8208 25.5391 12.0206 25.539 12.2286C25.539 12.4406 25.4548 12.6438 25.305 12.7937C25.1551 12.9435 24.9519 13.0277 24.7399 13.0277C24.528 13.0277 24.3247 12.9435 24.1749 12.7937C24.025 12.6438 23.9408 12.4406 23.9408 12.2286C23.9408 12.1217 23.9622 12.0159 24.0038 11.9174C24.0454 11.8189 24.1063 11.7298 24.183 11.6553C24.2597 11.5807 24.3505 11.5224 24.4502 11.4836C24.5498 11.4448 24.6562 11.4264 24.7631 11.4295ZM7.21632 11.558H8.60896V17.8377H5.79799C5.45083 16.6186 5.34264 15.3439 5.47938 14.0838L7.20091 13.3181C7.56834 13.1536 7.73535 12.7245 7.57091 12.3571L7.21632 11.558ZM13.0284 11.6248H16.3456C16.5177 11.6248 17.5558 11.8227 17.5558 12.6012C17.5558 13.2461 16.7592 13.4774 16.104 13.4774H13.0258L13.0284 11.6248ZM13.0284 16.1368H15.5696C15.8008 16.1368 16.8106 16.2036 17.1318 17.4934C17.232 17.8891 17.4556 19.179 17.6072 19.5927C17.7588 20.0552 18.3729 20.9802 19.0281 20.9802H23.1751C22.8972 21.3524 22.5933 21.7044 22.2656 22.0336L20.5774 21.6713C20.1843 21.5866 19.7963 21.8384 19.7115 22.2315L19.3107 24.102C18.0217 24.6859 16.622 24.9848 15.2069 24.9781C13.7919 24.9714 12.395 24.6595 11.1116 24.0635L10.7108 22.1929C10.626 21.7998 10.2406 21.548 9.84743 21.6328L8.19528 21.9874C7.88869 21.6711 7.6037 21.3346 7.34223 20.9802H15.3769C15.4668 20.9802 15.5285 20.9647 15.5285 20.88V18.0381C15.5285 17.9559 15.4668 17.9379 15.3769 17.9379H13.0258L13.0284 16.1368ZM9.3207 22.6452C9.5286 22.6512 9.72596 22.738 9.87085 22.8872C10.0157 23.0364 10.0968 23.2363 10.0967 23.4443C10.0967 23.6562 10.0125 23.8594 9.86262 24.0093C9.71276 24.1592 9.50951 24.2434 9.29757 24.2434C9.08564 24.2434 8.88239 24.1592 8.73253 24.0093C8.58267 23.8594 8.49848 23.6562 8.49848 23.4443C8.49843 23.3373 8.51984 23.2315 8.56144 23.133C8.60303 23.0345 8.66397 22.9454 8.74064 22.8709C8.81731 22.7964 8.90815 22.738 9.00779 22.6992C9.10743 22.6605 9.21383 22.6421 9.3207 22.6452ZM21.153 22.6811C21.3609 22.6872 21.5583 22.774 21.7031 22.9232C21.848 23.0724 21.929 23.2722 21.929 23.4802C21.929 23.6922 21.8448 23.8954 21.6949 24.0453C21.5451 24.1951 21.3418 24.2793 21.1299 24.2793C20.9179 24.2793 20.7147 24.1951 20.5648 24.0453C20.415 23.8954 20.3308 23.6922 20.3308 23.4802C20.3307 23.3733 20.3521 23.2675 20.3937 23.169C20.4353 23.0705 20.4963 22.9814 20.5729 22.9068C20.6496 22.8323 20.7404 22.774 20.8401 22.7352C20.9397 22.6964 21.0461 22.678 21.153 22.6811Z" fill="black"> </path> <path clip-rule="evenodd" d="M26.7232 15.2304C26.7232 18.2717 25.515 21.1885 23.3645 23.3391C21.2139 25.4896 18.2971 26.6978 15.2558 26.6978C12.2144 26.6978 9.29761 25.4896 7.14705 23.3391C4.99649 21.1885 3.78832 18.2717 3.78832 15.2304C3.78832 12.189 4.99649 9.27222 7.14705 7.12166C9.29761 4.9711 12.2144 3.76293 15.2558 3.76293C18.2971 3.76293 21.2139 4.9711 23.3645 7.12166C25.515 9.27222 26.7232 12.189 26.7232 15.2304ZM26.5073 14.1229L28.2957 15.2304L26.5073 16.3378L28.0439 17.7741L26.0757 18.5115L27.3039 20.2202L25.2252 20.5594L26.0988 22.4762L23.9944 22.4017L24.4775 24.4521L22.4271 23.969L22.5016 26.0734L20.5848 25.1998L20.2456 27.2785L18.5369 26.0503L17.7995 28.0185L16.3632 26.482L15.2558 28.2703L14.1483 26.482L12.712 28.0185L11.9746 26.0503L10.2659 27.2785L9.92672 25.1998L8.00992 26.0734L8.08443 23.969L6.03401 24.4521L6.51707 22.4017L4.4127 22.4762L5.28631 20.5594L3.20763 20.2202L4.43582 18.5115L2.46763 17.7741L4.00415 16.3378L2.21582 15.2304L4.00415 14.1229L2.46763 12.6866L4.43582 11.9492L3.20763 10.2405L5.28631 9.90133L4.4127 7.98453L6.51707 8.05904L6.03401 6.00862L8.08443 6.49168L8.00992 4.3873L9.92672 5.26092L10.2659 3.18223L11.9746 4.41043L12.712 2.44224L14.1483 3.97876L15.2558 2.19043L16.3632 3.97876L17.7995 2.44224L18.5369 4.41043L20.2456 3.18223L20.5848 5.26092L22.5016 4.3873L22.4271 6.49168L24.4775 6.00862L23.9944 8.05904L26.0988 7.98453L25.2252 9.90133L27.3039 10.2405L26.0757 11.9492L28.0439 12.6866L26.5073 14.1229Z" fill="black" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"> </path> </g> <defs> <clippath id="clip0_5454_14623"> <rect fill="black" height="30" width="30"> </rect> </clippath> </defs> </svg> <span> Rust </span> </a> <a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongo-scala-driver/org/mongodb/scala/MongoCollection.html#findOneAndUpdate(clientSession:org.mongodb.scala.ClientSession,filter:org.mongodb.scala.bson.conversions.Bson,update:Seq[org.mongodb.scala.bson.conversions.Bson],options:org.mongodb.scala.model.FindOneAndUpdateOptions):org.mongodb.scala.SingleObservable[TResult]" target="_self"> <svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 70 70" width="24" xmlns="http://www.w3.org/2000/svg"> <defs> <lineargradient id=":R3ptlqcmqn9:aaa" x1=".006%" x2="96.837%" y1="49.998%" y2="49.998%"> <stop offset="0%" stop-color="#CD413F"> </stop> <stop offset="75.091%" stop-color="#CD4543"> </stop> <stop offset="100%" stop-color="#D04543"> </stop> </lineargradient> </defs> <g fill="none" fill-rule="nonzero"> <path d="M13 39v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 36.745 13 38.157 13 39M13 20v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 17.745 13 19.157 13 20" fill="#731818"> </path> <g fill="url(#:R3ptlqcmqn9:aaa)" transform="translate(13)"> <path d="M0 29.53v14.766c0-1.232 39-3.692 39-9.844V19.686c0 6.152-39 8.612-39 9.844M0 9.843V24.61c0-1.231 39-3.691 39-9.843V0C39 6.152 0 8.612 0 9.843M0 49.216v14.766c0-1.231 39-3.691 39-9.843V39.373c0 6.151-39 8.612-39 9.843"> </path> </g> </g> </svg> <span> Scala </span> </a> </div> <button class="leafygreen-ui-ki2t97"> Show all <svg aria-label="Chevron Down Icon" class="" fill="none" height="16" role="img" viewbox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"> <path clip-rule="evenodd" d="M1.636 5.364a1 1 0 0 0 0 1.414l4.95 4.95.707.707a1 1 0 0 0 1.414 0l.707-.707 4.95-4.95a1 1 0 0 0 0-1.414l-.707-.707a1 1 0 0 0-1.414 0L8 8.899 3.757 4.657a1 1 0 0 0-1.414 0l-.707.707Z" fill="currentColor" fill-rule="evenodd"> </path> </svg> </button> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate( filter, update, options ) </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.collection.findOneAndUpdate" title="Permalink to this definition"> <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="mongodb-method-db.collection.findOneAndUpdate"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Updates a single document based on the <code class="leafygreen-ui-1l06pbn"> filter </code> and <code class="leafygreen-ui-1l06pbn"> sort </code> criteria. </p> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <div> <p> <em> New <!-- --> in version <!-- --> 8.0 </em> : <!-- --> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne"> <code class="leafygreen-ui-1l06pbn"> updateOne() </code> </a> method includes a <code class="leafygreen-ui-1l06pbn"> sort </code> option to update the first document in a user specified sort order. </p> </div> </div> </div> <table class="css-11h39yh e1nex8bq0"> <colgroup> <col class="field-name"/> <col class="field-body"/> </colgroup> <tbody> <tr class="css-x8snli"> <th> Returns <!-- --> : </th> <td> Returns the original document by default. Returns the updated document if <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-findOneUpdate-returnNewDocument" target="_self"> <span> returnNewDocument </span> </a> is set to <code class="leafygreen-ui-1l06pbn"> true </code> or <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-findOneUpdate-returnDocument" target="_self"> <span> returnDocument </span> </a> is set to <code class="leafygreen-ui-1l06pbn"> after </code> . </td> </tr> </tbody> </table> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> You can use <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> for deployments hosted 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> </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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findOneAndUpdate() </code> </span> </a> method has the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.findOneAndUpdate(\n &lt;filter&gt;,\n &lt;update&gt;,\n {\n writeConcern: &lt;document&gt;,\n projection: &lt;document&gt;,\n sort: &lt;document&gt;,\n maxTimeMS: &lt;number&gt;,\n upsert: &lt;boolean&gt;,\n returnDocument: &lt;string&gt;,\n returnNewDocument: &lt;boolean&gt;,\n collation: &lt;document&gt;,\n arrayFilters: [ &lt;filterdocument1&gt;, ... ]\n }\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">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndUpdate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> &lt;<!-- -->filter<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->&lt;update document or aggregation pipeline&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> writeConcern: &lt;document&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> projection: &lt;document&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> sort: &lt;document&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> maxTimeMS: &lt;number&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> upsert: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> returnDocument: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> returnNewDocument: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> collation: &lt;document&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> arrayFilters: [ &lt;filterdocument1&gt;, ... ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findOneAndUpdate() </code> </span> </a> method takes the following parameters: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Parameter </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> filter </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> The selection criteria for the update. The same <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/#std-label-query-selectors"> query selectors </a> as in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find"> <code class="leafygreen-ui-1l06pbn"> find() </code> </a> method are available. </p> <p class="leafygreen-ui-1kp3ins"> To update the first document returned in the collection, specify an empty document <code class="leafygreen-ui-1l06pbn"> { } </code> . </p> <p class="leafygreen-ui-1kp3ins"> If unspecified, defaults to an empty document. </p> <p class="leafygreen-ui-1kp3ins"> If the query field is not a document, the operation returns an error. </p> <p class="leafygreen-ui-1kp3ins"> If no document matches the <code class="leafygreen-ui-1l06pbn"> filter </code> , no document is updated. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> update </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document or array </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> The update document or an <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline <!-- --> . </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If passed a document with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/#std-label-update-operators"> update operator expressions </a> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> </span> </a> performs the specified modification. </p> <p class="leafygreen-ui-1kp3ins"> The document must contain only <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/#std-label-update-operators-top-level"> update operators </a> . You cannot specify a replacement document <code class="leafygreen-ui-1l06pbn"> { &lt;field1&gt;: &lt;value1&gt;, ...} </code> . To use a replacement document, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndReplace/#mongodb-method-db.collection.findOneAndReplace"> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndReplace() </code> </a> instead. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If passed an <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline </a> <code class="leafygreen-ui-1l06pbn"> [ &lt;stage1&gt;, &lt;stage2&gt;, ... ] </code> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> </span> </a> modifies the document per the pipeline. The pipeline can consist of the following stages: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceRoot/#mongodb-pipeline-pipe.-replaceRoot"> <code class="leafygreen-ui-1l06pbn"> $replaceRoot </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith"> <code class="leafygreen-ui-1l06pbn"> $replaceWith </code> . </a> </p> </li> </ul> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> writeConcern </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A document expressing the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern"> write concern </a> . Omit to use the default write concern. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ w: &lt;value&gt;, j: &lt;boolean&gt;, wtimeout: &lt;number&gt; }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">w</span>: &lt;<!-- -->value<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">j</span>: &lt;<!-- -->boolean<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">wtimeout</span>: &lt;<!-- -->number<!-- -->&gt; <!-- -->}</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"> Do not explicitly set the write concern for the operation if run in a transaction. To use write concern with transactions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern"> Transactions and Write Concern <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> projection </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A subset of fields to return. </p> <p class="leafygreen-ui-1kp3ins"> To return all fields in the returned document, omit this parameter. </p> <p class="leafygreen-ui-1kp3ins"> If the projection argument is not a document, the operation errors. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> sort </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. Specifies a sorting order for the documents matched by the <code class="leafygreen-ui-1l06pbn"> filter </code> . </p> <p class="leafygreen-ui-1kp3ins"> If the sort argument is not a document, the operation errors. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#mongodb-method-cursor.sort"> <code class="leafygreen-ui-1l06pbn"> cursor.sort() </code> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> maxTimeMS </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> number </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Optional. Specifies a time limit in milliseconds within which the operation must complete within. Throws an error if the limit is exceeded. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> upsert </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. When <code class="leafygreen-ui-1l06pbn"> true </code> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> findOneAndUpdate() </code> </span> </a> either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Creates a new document if no documents match the <code class="leafygreen-ui-1l06pbn"> filter </code> . For more details see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.update/#std-label-upsert-behavior"> upsert behavior </a> . Returns <code class="leafygreen-ui-1l06pbn"> null </code> after inserting the new document, unless <code class="leafygreen-ui-1l06pbn"> returnNewDocument </code> is <code class="leafygreen-ui-1l06pbn"> true </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Updates a single document that matches the <code class="leafygreen-ui-1l06pbn"> filter </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> To avoid multiple <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert"> upserts </a> , ensure that the <code class="leafygreen-ui-1l06pbn"> filter </code> field(s) are <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique"> uniquely indexed <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Defaults to <code class="leafygreen-ui-1l06pbn"> false </code> , which does <em> not </em> insert a new document when no match is found. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> returnDocument </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneUpdate-returnDocument"> </span> <p class="leafygreen-ui-1kp3ins"> Optional. Starting in <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> 0.13.2, <code class="leafygreen-ui-1l06pbn"> returnDocument </code> is an alternative for <code class="leafygreen-ui-1l06pbn"> returnNewDocument </code> . If both options are set, <code class="leafygreen-ui-1l06pbn"> returnDocument </code> takes precedence. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> returnDocument: "before" </code> returns the original document. <code class="leafygreen-ui-1l06pbn"> returnDocument: "after" </code> returns the updated document. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> returnNewDocument </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneUpdate-returnNewDocument"> </span> <p class="leafygreen-ui-1kp3ins"> Optional. When <code class="leafygreen-ui-1l06pbn"> true </code> , returns the updated document instead of the original document. </p> <p class="leafygreen-ui-1kp3ins"> Defaults to <code class="leafygreen-ui-1l06pbn"> false </code> . </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> collation </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. </p> <p class="leafygreen-ui-1kp3ins"> Specifies the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> collation </a> to use for the operation. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> Collation </a> allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks. </p> <p class="leafygreen-ui-1kp3ins"> The collation option has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"collation: {\n locale: &lt;string&gt;,\n caseLevel: &lt;boolean&gt;,\n caseFirst: &lt;string&gt;,\n strength: &lt;int&gt;,\n numericOrdering: &lt;boolean&gt;,\n alternate: &lt;string&gt;,\n maxVariable: &lt;string&gt;,\n backwards: &lt;boolean&gt;\n}"} </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">collation: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> locale: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> caseLevel: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> caseFirst: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> strength: &lt;int&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> numericOrdering: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> alternate: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> maxVariable: &lt;string&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> backwards: &lt;boolean&gt;</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> <p class="leafygreen-ui-1kp3ins"> When specifying collation, the <code class="leafygreen-ui-1l06pbn"> locale </code> field is mandatory; all other collation fields are optional. For descriptions of the fields, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation-document-fields"> Collation Document <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> If the collation is unspecified but the collection has a default collation (see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.createCollection/#mongodb-method-db.createCollection"> <code class="leafygreen-ui-1l06pbn"> db.createCollection() </code> </a> ), the operation uses the collation specified for the collection. </p> <p class="leafygreen-ui-1kp3ins"> If no collation is specified for the collection or for the operations, MongoDB uses the simple binary comparison used in prior versions for string comparisons. </p> <p class="leafygreen-ui-1kp3ins"> You cannot specify multiple collations for an operation. For example, you cannot specify different collations per field, or if performing a find with a sort, you cannot use one collation for the find and another for the sort. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> array </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. An array of filter documents that determine which array elements to modify for an update operation on an array field. </p> <p class="leafygreen-ui-1kp3ins"> In the update document, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/positional-filtered/#mongodb-update-up.---identifier--"> <code class="leafygreen-ui-1l06pbn"> $[&lt;identifier&gt;] </code> </a> filtered positional operator to define an identifier, which you then reference in the array filter documents. You cannot have an array filter document for an identifier if the identifier is not included in the update document. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> &lt;identifier&gt; </code> must begin with a lowercase letter and contain only alphanumeric characters. </p> <p class="leafygreen-ui-1kp3ins"> You can include the same identifier multiple times in the update document; however, for each distinct identifier ( <code class="leafygreen-ui-1l06pbn"> $[identifier] </code> ) in the update document, you must specify <strong> exactly one </strong> corresponding array filter document. That is, you cannot specify multiple array filter documents for the same identifier. For example, if the update statement includes the identifier <code class="leafygreen-ui-1l06pbn"> x </code> (possibly multiple times), you cannot specify the following for <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> that includes 2 separate filter documents for <code class="leafygreen-ui-1l06pbn"> x </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// INVALID\n\n[\n { \"x.a\": { $gt: 85 } },\n { \"x.b\": { $gt: 80 } }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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"><span class="lg-highlight-comment">// INVALID</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"x.a"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"x.b"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> However, you can specify compound conditions on the same identifier in a single filter document, such as in the following examples: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// Example 1\n[\n { $or: [{\"x.a\": {$gt: 85}}, {\"x.b\": {$gt: 80}}] }\n]\n// Example 2\n[\n { $and: [{\"x.a\": {$gt: 85}}, {\"x.b\": {$gt: 80}}] }\n]\n// Example 3\n[\n { \"x.a\": { $gt: 85 }, \"x.b\": { $gt: 80 } }\n]","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// Example 1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$or</span>: <!-- -->[<!-- -->{<span class="lg-highlight-string">"x.a"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span>}}<!-- -->, <!-- -->{<span class="lg-highlight-string">"x.b"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</span>}}] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// Example 2</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$and</span>: <!-- -->[<!-- -->{<span class="lg-highlight-string">"x.a"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span>}}<!-- -->, <!-- -->{<span class="lg-highlight-string">"x.b"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</span>}}] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// Example 3</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"x.a"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span> }<!-- -->, <span class="lg-highlight-string">"x.b"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</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> <p class="leafygreen-ui-1kp3ins"> For examples, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-findOneAndUpdate-arrayFilters" target="_self"> <span> Array Update Operations with <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> is not available for updates that use an aggregation pipeline. </p> </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Performance <a class="headerlink leafygreen-ui-1kepx47" href="#performance" 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="performance"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Retryable writes require the <code class="leafygreen-ui-1l06pbn"> findOneAndUpdate() </code> method to copy the entire document into a special side collection for each node in a replica set before it performs the update. This can make <code class="leafygreen-ui-1l06pbn"> findOneAndUpdate() </code> an expensive operation when dealing with large documents or large replica sets. </p> <div> <p> <em> New <!-- --> in version <!-- --> 8.0 </em> : <!-- --> To update the first document in a user-defined ordering with better performance, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne"> <code class="leafygreen-ui-1l06pbn"> db.collection.updateOne() </code> </a> method with the <code class="leafygreen-ui-1l06pbn"> sort </code> option. </p> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Document Match <a class="headerlink leafygreen-ui-1kepx47" href="#document-match" 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="document-match"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> </span> </a> updates the first matching document in the collection that matches the <code class="leafygreen-ui-1l06pbn"> filter </code> . If no document matches the <code class="leafygreen-ui-1l06pbn"> filter </code> , no document is updated. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> sort </code> parameter can be used to influence which document is updated. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Projection <a class="headerlink leafygreen-ui-1kepx47" href="#projection" 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="projection"> </div> </a> </h3> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Language Consistency </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> As part of making <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find"> <code class="leafygreen-ui-1l06pbn"> find() </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify"> <code class="leafygreen-ui-1l06pbn"> findAndModify() </code> </a> projection consistent with aggregation's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> stage, </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find"> <code class="leafygreen-ui-1l06pbn"> find() </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify"> <code class="leafygreen-ui-1l06pbn"> findAndModify() </code> </a> projection can accept <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> aggregation expressions and syntax <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> MongoDB enforces additional restrictions with regards to projections. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#mongodb-limit-Projection-Restrictions"> Projection Restrictions </a> for details. </p> </li> </ul> </div> </div> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> projection </code> parameter takes a document in the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ field1 : &lt;value&gt;, field2 : &lt;value&gt; ... }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <!-- -->field1 <!-- -->: &lt;<!-- -->value<!-- -->&gt;<!-- -->,<!-- --> <!-- -->field2 <!-- -->: &lt;<!-- -->value<!-- -->&gt; <!-- -->...<!-- --> }</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 class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:40%"/> <col style="width:60%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Projection </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> &lt;field&gt;: &lt;1 or true&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Specifies the inclusion of a field. If you specify a non-zero integer for the projection value, the operation treats the value as <code class="leafygreen-ui-1l06pbn"> true </code> . </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> &lt;field&gt;: &lt;0 or false&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Specifies the exclusion of a field. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> "&lt;field&gt;.$": &lt;1 or true&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/positional/#mongodb-projection-proj.-"> <code class="leafygreen-ui-1l06pbn"> $ </code> </a> array projection operator to return the first element that matches the query condition on the array field. If you specify a non-zero integer for the projection value, the operation treats the value as <code class="leafygreen-ui-1l06pbn"> true </code> . </p> <p class="leafygreen-ui-1kp3ins"> Not available for <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page"> views <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> &lt;field&gt;: &lt;array projection&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Uses the array projection operators ( <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/elemMatch/#mongodb-projection-proj.-elemMatch"> <code class="leafygreen-ui-1l06pbn"> $elemMatch </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/slice/#mongodb-projection-proj.-slice"> <code class="leafygreen-ui-1l06pbn"> $slice </code> </a> ) to specify the array elements to include. </p> <p class="leafygreen-ui-1kp3ins"> Not available for <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page"> views <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> &lt;field&gt;: &lt;aggregation expression&gt; </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Specifies the value of the projected field. </p> <p class="leafygreen-ui-1kp3ins"> With the use of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> aggregation expressions and syntax </a> , including the use of literals and aggregation variables, you can project new fields or project existing fields with new values. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If you specify a non-numeric, non-boolean literal (such as a literal string or an array or an operator expression) for the projection value, the field is projected with the new value, for example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: [ 1, 2, 3, "$someExistingField" ] } </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: "New String Value" } </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: { status: "Active", total: { $sum: "$existingArray" } } } </code> </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To project a literal value for a field, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal"> <code class="leafygreen-ui-1l06pbn"> $literal </code> </a> aggregation expression, for example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: { $literal: 5 } } </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: { $literal: true } } </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { field: { $literal: { fieldWithValue0: 0, fieldWithValue1: 1 } } } </code> </p> </li> </ul> </li> </ul> </div> </div> </td> </tr> </tbody> </table> </div> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Embedded Field Specification <a class="headerlink leafygreen-ui-1kepx47" href="#embedded-field-specification" 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="embedded-field-specification"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> For fields in an embedded documents, you can specify the field using either: </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/document/#std-label-document-dot-notation-embedded-fields"> dot notation </a> , for example <code class="leafygreen-ui-1l06pbn"> "field.nestedfield": &lt;value&gt; </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> nested form, for example <code class="leafygreen-ui-1l06pbn"> { field: { nestedfield: &lt;value&gt; } } </code> </p> </li> </ul> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> <code class="leafygreen-ui-1l06pbn"> _id </code> Field Projection <a class="headerlink leafygreen-ui-1kepx47" href="#_id-field-projection" 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="_id-field-projection"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> _id </code> field is included in the returned documents by default unless you explicitly specify <code class="leafygreen-ui-1l06pbn"> _id: 0 </code> in the projection to suppress the field. </p> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Inclusion or Exclusion <a class="headerlink leafygreen-ui-1kepx47" href="#inclusion-or-exclusion" 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="inclusion-or-exclusion"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> projection </code> <em> cannot </em> contain <em> both </em> include and exclude specifications, with the exception of the <code class="leafygreen-ui-1l06pbn"> _id </code> field: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> In projections that <em> explicitly include </em> fields, the <code class="leafygreen-ui-1l06pbn"> _id </code> field is the only field that you can <em> explicitly exclude </em> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> In projections that <em> explicitly excludes </em> fields, the <code class="leafygreen-ui-1l06pbn"> _id </code> field is the only field that you can <em> explicitly include </em> ; however, the <code class="leafygreen-ui-1l06pbn"> _id </code> field is included by default. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For more information on projection, see also: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/project-fields-from-query-results/#std-label-read-operations-projection"> Project Fields to Return from Query </a> </p> </li> </ul> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Sharded Collections <a class="headerlink leafygreen-ui-1kepx47" href="#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-collections"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> </span> </a> on a sharded collection, the query filter must include an equality condition on the shard key. </p> <p class="leafygreen-ui-1kp3ins"> Documents in a sharded collection can be <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key-missing"> missing the shard key fields </a> . To target a document that is missing the shard key, you can use the <code class="leafygreen-ui-1l06pbn"> null </code> equality match <strong class="css-4dei7l"> in conjunction with </strong> another filter condition (such as on the <code class="leafygreen-ui-1l06pbn"> _id </code> field). For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: &lt;value&gt;, &lt;shardkeyfield&gt;: null } // _id of the document missing shard key","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: &lt;<!-- -->value<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->shardkeyfield<!-- -->&gt;<!-- -->: <span class="lg-highlight-literal">null</span> } <span class="lg-highlight-comment">// _id of</span><span class="lg-highlight-comment"> the document missing </span><span class="lg-highlight-comment">shard key</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndUpdate-shard-key-modification"> </span> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Shard Key Modification <a class="headerlink leafygreen-ui-1kepx47" href="#shard-key-modification" 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-modification"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can update a document's shard key value unless the shard key field is the immutable <code class="leafygreen-ui-1l06pbn"> _id </code> field. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Documents in sharded collections can be missing the shard key fields. Take precaution to avoid accidentally removing the shard key when changing a document's shard key value. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> To modify the <strong> existing </strong> shard key value with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> : </span> </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> run on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> . Do <strong class="css-4dei7l"> not </strong> issue the operation directly on the shard. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> run either in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/"> transaction </a> or as a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/retryable-writes/"> retryable write <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> include an equality filter on the full shard key. </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndUpdate-missing-shard-key"> </span> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Missing Shard Key <a class="headerlink leafygreen-ui-1kepx47" href="#missing-shard-key" 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="missing-shard-key"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Documents in a sharded collection can be <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key-missing"> missing the shard key fields </a> . To use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> </span> </a> to set the document's <strong> missing </strong> shard key, </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> run on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> . Do <strong class="css-4dei7l"> not </strong> issue the operation directly on the shard. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> run either in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/"> transaction </a> or as a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/retryable-writes/"> retryable write </a> if the new shard key value is not <code class="leafygreen-ui-1l06pbn"> null </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong class="css-4dei7l"> must </strong> include an equality filter on the full shard key. </p> </li> </ul> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Since a missing key value is returned as part of a null equality match, to avoid updating a null-valued key, include additional query conditions (such as on the <code class="leafygreen-ui-1l06pbn"> _id </code> field) as appropriate. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> See also: </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/sharding-shard-key/#std-label-shard-key-missing"> Missing Shard Key Fields </a> </p> </li> </ul> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" 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> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> </span> </a> can be used inside <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> distributed transactions <!-- --> . </a> </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> In most cases, a distributed transaction incurs a greater performance cost over single document writes, and the availability of distributed transactions should not be a replacement for effective schema design. For many scenarios, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding"> denormalized data model (embedded documents and arrays) </a> will continue to be optimal for your data and use cases. That is, for many scenarios, modeling your data appropriately will minimize the need for distributed transactions. </p> <p class="leafygreen-ui-1kp3ins"> For additional transactions usage considerations (such as runtime limit and oplog size limit), see also <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-production-consideration/#std-label-production-considerations"> Production Considerations <!-- --> . </a> </p> </div> </div> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Upsert within Transactions <a class="headerlink leafygreen-ui-1kepx47" href="#upsert-within-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="upsert-within-transactions"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can create collections and indexes inside a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-create-collections-indexes"> distributed transaction </a> if the transaction is <strong class="css-4dei7l"> not </strong> a cross-shard write transaction. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> </span> </a> with <code class="leafygreen-ui-1l06pbn"> upsert: true </code> can be run on an existing collection or a non-existing collection. If run on a non-existing collection, the operation creates the collection. </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/transactions/#std-label-transactions-create-collections-indexes"> Create Collections and Indexes in a Transaction </a> </p> </div> </div> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Write Concerns and Transactions <a class="headerlink leafygreen-ui-1kepx47" href="#write-concerns-and-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="write-concerns-and-transactions"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Do not explicitly set the write concern for the operation if run in a transaction. To use write concern with transactions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern"> Transactions and Write Concern <!-- --> . </a> </p> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Oplog Entries <a class="headerlink leafygreen-ui-1kepx47" href="#oplog-entries" 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="oplog-entries"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If a <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> operation successfully updates a document, the operation adds an entry on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> (operations log). If the operation fails or does not find a document to update, the operation does not add an entry on the oplog. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndUpdate-examples"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndUpdate-example-replace-document"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Update A Document <a class="headerlink leafygreen-ui-1kepx47" href="#update-a-document" 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="update-a-document"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> grades </code> collection contains documents similar to the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 6305, name : \"A. MacDyver\", \"assignment\" : 5, \"points\" : 24 },\n{ _id: 6308, name : \"B. Batlock\", \"assignment\" : 3, \"points\" : 22 },\n{ _id: 6312, name : \"M. Tagnum\", \"assignment\" : 5, \"points\" : 30 },\n{ _id: 6319, name : \"R. Stiles\", \"assignment\" : 2, \"points\" : 12 },\n{ _id: 6322, name : \"A. MacDyver\", \"assignment\" : 2, \"points\" : 14 },\n{ _id: 6234, name : \"R. Stiles\", \"assignment\" : 1, \"points\" : 10 }","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6305</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">24</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6308</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"B. Batlock"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">22</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6312</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"M. Tagnum"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">30</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6319</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"R. Stiles"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">12</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6322</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">14</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6234</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"R. Stiles"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">10</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> <p class="leafygreen-ui-1kp3ins"> The following operation finds the first document where <code class="leafygreen-ui-1l06pbn"> name : R. Stiles </code> and increments the score by <code class="leafygreen-ui-1l06pbn"> 5 </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.grades.findOneAndUpdate(\n { \"name\" : \"R. Stiles\" },\n { $inc: { \"points\" : 5 } }\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">db.<span class="lg-highlight-property">grades</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndUpdate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"R. Stiles"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">5</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the <em> original </em> document before the update: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 6319, name: \"R. Stiles\", \"assignment\" : 2, \"points\" : 12 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6319</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"R. Stiles"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">12</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> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> returnNewDocument </code> was true, the operation would return the updated document instead. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndUpdate-example-sort-and-replace-document"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Sort And Update A Document <a class="headerlink leafygreen-ui-1kepx47" href="#sort-and-update-a-document" 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="sort-and-update-a-document"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> grades </code> collection contains documents similar to the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 6305, name : \"A. MacDyver\", \"assignment\" : 5, \"points\" : 24 },\n{ _id: 6308, name : \"B. Batlock\", \"assignment\" : 3, \"points\" : 22 },\n{ _id: 6312, name : \"M. Tagnum\", \"assignment\" : 5, \"points\" : 30 },\n{ _id: 6319, name : \"R. Stiles\", \"assignment\" : 2, \"points\" : 12 },\n{ _id: 6322, name : \"A. MacDyver\", \"assignment\" : 2, \"points\" : 14 },\n{ _id: 6234, name : \"R. Stiles\", \"assignment\" : 1, \"points\" : 10 }","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6305</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">24</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6308</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"B. Batlock"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">22</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6312</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"M. Tagnum"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">30</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6319</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"R. Stiles"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">12</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6322</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">14</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6234</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"R. Stiles"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">10</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> <p class="leafygreen-ui-1kp3ins"> The following operation updates a document where <code class="leafygreen-ui-1l06pbn"> name : "A. MacDyver" </code> . The operation sorts the matching documents by <code class="leafygreen-ui-1l06pbn"> points </code> ascending to update the matching document with the least points. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.grades.findOneAndUpdate(\n { \"name\" : \"A. MacDyver\" },\n { $inc : { \"points\" : 5 } },\n { sort : { \"points\" : 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">db.<span class="lg-highlight-property">grades</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndUpdate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$inc<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">5</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->sort <!-- -->: <!-- -->{ <span class="lg-highlight-string">"points"</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the <em> original </em> document before the update: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 6322, name: \"A. MacDyver\", \"assignment\" : 2, \"points\" : 14 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6322</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"A. MacDyver"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">14</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndUpdate-example-project-returned-document"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Project the Returned Document <a class="headerlink leafygreen-ui-1kepx47" href="#project-the-returned-document" 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="project-the-returned-document"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following operation uses projection to only display the <code class="leafygreen-ui-1l06pbn"> _id </code> , <code class="leafygreen-ui-1l06pbn"> points </code> , and <code class="leafygreen-ui-1l06pbn"> assignment </code> fields in the returned document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.grades.findOneAndUpdate(\n { \"name\" : \"A. MacDyver\" },\n { $inc : { \"points\" : 5 } },\n { sort : { \"points\" : 1 }, projection: { \"assignment\" : 1, \"points\" : 1 } }\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">grades</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndUpdate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$inc<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">5</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->sort <!-- -->: <!-- -->{ <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-attr">projection</span>: <!-- -->{ <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"points"</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the <em> original </em> document with only the fields specified in the <code class="leafygreen-ui-1l06pbn"> projection </code> document and the <code class="leafygreen-ui-1l06pbn"> _id </code> field as it was not explicitly suppressed ( <code class="leafygreen-ui-1l06pbn"> _id: 0 </code> ) in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/project-fields-from-query-results/#std-label-projections"> projection document <!-- --> . </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 6322, \"assignment\" : 2, \"points\" : 14 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6322</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">14</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndUpdate-example-replace-with-time-limit"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Update Document with Time Limit <a class="headerlink leafygreen-ui-1kepx47" href="#update-document-with-time-limit" 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="update-document-with-time-limit"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following operation sets a 5ms time limit to complete the update: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"try {\n db.grades.findOneAndUpdate(\n { \"name\" : \"A. MacDyver\" },\n { $inc : { \"points\" : 5 } },\n { sort: { \"points\" : 1 }, maxTimeMS : 5 };\n );\n}\ncatch(e){\n print(e);\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"><span class="lg-highlight-keyword">try</span> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->db.<span class="lg-highlight-property">grades</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndUpdate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"A. MacDyver"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$inc<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">5</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">sort</span>: <!-- -->{ <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <!-- -->maxTimeMS <!-- -->: <span class="lg-highlight-number">5</span> }<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">catch</span>(<!-- -->e)<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">print</span>(<!-- -->e)<!-- -->;</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> <p class="leafygreen-ui-1kp3ins"> If the operation exceeds the time limit, it returns: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Error: findAndModifyFailed failed: { \"ok\" : 0, \"errmsg\" : \"operation exceeded time limit\", \"code\" : 50 }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Error</span>: <!-- -->findAndModifyFailed <span class="lg-highlight-attr">failed</span>: <!-- -->{ <span class="lg-highlight-string">"ok"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"errmsg"</span> <!-- -->: <span class="lg-highlight-string">"operation exceeded time limit"</span>, <span class="lg-highlight-string">"code"</span> <!-- -->: <span class="lg-highlight-number">50</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndUpdate-example-replace-with-upsert"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Update Document with Upsert <a class="headerlink leafygreen-ui-1kepx47" href="#update-document-with-upsert" 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="update-document-with-upsert"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following operation uses the <code class="leafygreen-ui-1l06pbn"> upsert </code> field to insert the update document if nothing matches the <code class="leafygreen-ui-1l06pbn"> filter </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"try {\ndb.grades.findOneAndUpdate(\n { \"name\" : \"A.B. Abracus\" },\n { $set: { \"name\" : \"A.B. Abracus\", \"assignment\" : 5}, $inc : { \"points\" : 5 } },\n { sort: { \"points\" : 1 }, upsert:true, returnNewDocument : true }\n);\n}\ncatch (e){\n print(e);\n}","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">try</span> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">grades</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndUpdate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"A.B. Abracus"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"A.B. Abracus"</span>, <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>}<!-- -->, <!-- -->$inc<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">5</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">sort</span>: <!-- -->{ <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-attr">upsert</span>:<span class="lg-highlight-literal">true</span>, <!-- -->returnNewDocument <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">catch</span> <!-- -->(<!-- -->e)<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">print</span>(<!-- -->e)<!-- -->;</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5789249f1c49e39a8adc479a\"),\n \"name\" : \"A.B. Abracus\",\n \"assignment\" : 5,\n \"points\" : 5\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5789249f1c49e39a8adc479a"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"A.B. Abracus"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"assignment"</span> <!-- -->: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"points"</span> <!-- -->: <span class="lg-highlight-number">5</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> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> returnNewDocument </code> was false, the operation would return <code class="leafygreen-ui-1l06pbn"> null </code> as there is no original document to return. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Specify Collation <a class="headerlink leafygreen-ui-1kepx47" href="#specify-collation" 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="specify-collation"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> Collation </a> allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks. </p> <p class="leafygreen-ui-1kp3ins"> A collection <code class="leafygreen-ui-1l06pbn"> myColl </code> has the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 1, category: \"café\", status: \"A\" }\n{ _id: 2, category: \"cafe\", status: \"a\" }\n{ _id: 3, category: \"cafE\", status: \"a\" }","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">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"café"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"A"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafe"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"a"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafE"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"a"</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> <p class="leafygreen-ui-1kp3ins"> The following operation includes the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation"> collation </a> option: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.myColl.findOneAndUpdate(\n { category: \"cafe\" },\n { $set: { status: \"Updated\" } },\n { collation: { locale: \"fr\", strength: 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">db.<span class="lg-highlight-property">myColl</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndUpdate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafe"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"Updated"</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">collation</span>: <!-- -->{ <span class="lg-highlight-attr">locale</span>: <span class="lg-highlight-string">"fr"</span>, <span class="lg-highlight-attr">strength</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"category\" : \"café\", \"status\" : \"A\" }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"category"</span> <!-- -->: <span class="lg-highlight-string">"café"</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndUpdate-arrayFilters"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Array Update Operations with <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> <a class="headerlink leafygreen-ui-1kepx47" href="#array-update-operations-with-arrayfilters" 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="array-update-operations-with-arrayfilters"> </div> </a> </h3> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> is not available for updates that use an aggregation pipeline. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> When updating an array field, you can specify <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> that determine which array elements to update. </p> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Update Elements Match <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> Criteria <a class="headerlink leafygreen-ui-1kepx47" href="#update-elements-match-arrayfilters-criteria" 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="update-elements-match-arrayfilters-criteria"> </div> </a> </h4> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> is not available for updates that use an aggregation pipeline. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Create a collection <code class="leafygreen-ui-1l06pbn"> students </code> with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.insertMany( [\n { \"_id\" : 1, \"grades\" : [ 95, 92, 90 ] },\n { \"_id\" : 2, \"grades\" : [ 98, 100, 102 ] },\n { \"_id\" : 3, \"grades\" : [ 95, 110, 100 ] }\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">db.<span class="lg-highlight-property">students</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">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">92</span>, <span class="lg-highlight-number">90</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">98</span>, <span class="lg-highlight-number">100</span>, <span class="lg-highlight-number">102</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">110</span>, <span class="lg-highlight-number">100</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> <p class="leafygreen-ui-1kp3ins"> To modify all elements that are greater than or equal to <code class="leafygreen-ui-1l06pbn"> 100 </code> in the <code class="leafygreen-ui-1l06pbn"> grades </code> array, use the filtered positional operator <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/positional-filtered/#mongodb-update-up.---identifier--"> <code class="leafygreen-ui-1l06pbn"> $[&lt;identifier&gt;] </code> </a> with the <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> option in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> </span> </a> method: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.findOneAndUpdate(\n { grades: { $gte: 100 } },\n { $set: { \"grades.$[element]\" : 100 } },\n { arrayFilters: [ { \"element\": { $gte: 100 } } ] }\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">db.<span class="lg-highlight-property">students</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndUpdate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">grades</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-number">100</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"grades.$[element]"</span> <!-- -->: <span class="lg-highlight-number">100</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">arrayFilters</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"element"</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-number">100</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> <p class="leafygreen-ui-1kp3ins"> The operation updates the <code class="leafygreen-ui-1l06pbn"> grades </code> field for a single document, and after the operation, the collection has the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"grades\" : [ 95, 92, 90 ] }\n{ \"_id\" : 2, \"grades\" : [ 98, 100, 100 ] }\n{ \"_id\" : 3, \"grades\" : [ 95, 110, 100 ] }","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">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">92</span>, <span class="lg-highlight-number">90</span> ] }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">98</span>, <span class="lg-highlight-number">100</span>, <span class="lg-highlight-number">100</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">110</span>, <span class="lg-highlight-number">100</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> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Update Specific Elements of an Array of Documents <a class="headerlink leafygreen-ui-1kepx47" href="#update-specific-elements-of-an-array-of-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="update-specific-elements-of-an-array-of-documents"> </div> </a> </h4> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> is not available for updates that use an aggregation pipeline. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Create a collection <code class="leafygreen-ui-1l06pbn"> students2 </code> with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.insertMany( [\n {\n \"_id\" : 1,\n \"grades\" : [\n { \"grade\" : 80, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 85, \"mean\" : 90, \"std\" : 4 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 6 }\n ]\n },\n {\n \"_id\" : 2,\n \"grades\" : [\n { \"grade\" : 90, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 87, \"mean\" : 90, \"std\" : 3 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 4 }\n ]\n }\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">db.<span class="lg-highlight-property">students2</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">87</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The following operation finds a document where the <code class="leafygreen-ui-1l06pbn"> _id </code> field equals <code class="leafygreen-ui-1l06pbn"> 1 </code> and uses the filtered positional operator <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/positional-filtered/#mongodb-update-up.---identifier--"> <code class="leafygreen-ui-1l06pbn"> $[&lt;identifier&gt;] </code> </a> with the <code class="leafygreen-ui-1l06pbn"> arrayFilters </code> to modify the <code class="leafygreen-ui-1l06pbn"> mean </code> for all elements in the <code class="leafygreen-ui-1l06pbn"> grades </code> array where the grade is greater than or equal to <code class="leafygreen-ui-1l06pbn"> 85 </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.findOneAndUpdate(\n { _id : 1 },\n { $set: { \"grades.$[elem].mean\" : 100 } },\n { arrayFilters: [ { \"elem.grade\": { $gte: 85 } } ] }\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">db.<span class="lg-highlight-property">students2</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndUpdate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"grades.$[elem].mean"</span> <!-- -->: <span class="lg-highlight-number">100</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">arrayFilters</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"elem.grade"</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-number">85</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> <p class="leafygreen-ui-1kp3ins"> The operation updates the <code class="leafygreen-ui-1l06pbn"> grades </code> field for a single document, and after the operation, the collection has the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n \"grades\" : [\n { \"grade\" : 80, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 85, \"mean\" : 100, \"std\" : 4 },\n { \"grade\" : 85, \"mean\" : 100, \"std\" : 6 }\n ]\n}\n{\n \"_id\" : 2,\n \"grades\" : [\n { \"grade\" : 90, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 87, \"mean\" : 90, \"std\" : 3 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 4 }\n ]\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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">100</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">100</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">87</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-findOneAndUpdate-agg-pipeline"> </span> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Use an Aggregation Pipeline for Updates <a class="headerlink leafygreen-ui-1kepx47" href="#use-an-aggregation-pipeline-for-updates" 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="use-an-aggregation-pipeline-for-updates"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findOneAndUpdate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> db.collection.findOneAndUpdate() </code> </span> </a> can accept an aggregation pipeline for the update. The pipeline can consist of the following stages: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceRoot/#mongodb-pipeline-pipe.-replaceRoot"> <code class="leafygreen-ui-1l06pbn"> $replaceRoot </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith"> <code class="leafygreen-ui-1l06pbn"> $replaceWith </code> . </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Using the aggregation pipeline allows for a more expressive update statement, such as expressing conditional updates based on current field values or updating one field using the value of another field(s). </p> <p class="leafygreen-ui-1kp3ins"> For example, create a collection <code class="leafygreen-ui-1l06pbn"> students2 </code> with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.insertMany( [\n {\n \"_id\" : 1,\n \"grades\" : [\n { \"grade\" : 80, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 85, \"mean\" : 90, \"std\" : 4 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 6 }\n ]\n },\n {\n \"_id\" : 2,\n \"grades\" : [\n { \"grade\" : 90, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 87, \"mean\" : 90, \"std\" : 3 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 4 }\n ]\n }\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">db.<span class="lg-highlight-property">students2</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">87</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The following operation finds a document where the <code class="leafygreen-ui-1l06pbn"> _id </code> field equals <code class="leafygreen-ui-1l06pbn"> 1 </code> and uses an aggregation pipeline to calculate a new field <code class="leafygreen-ui-1l06pbn"> total </code> from the <code class="leafygreen-ui-1l06pbn"> grades </code> field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.findOneAndUpdate(\n { _id : 1 },\n [ { $set: { \"total\" : { $sum: \"$grades.grade\" } } } ], // The $set stage is an alias for ``$addFields`` stage\n { returnNewDocument: true }\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students2</span>.<span class="lg-highlight-title lg-highlight-function">findOneAndUpdate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"total"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$grades.grade"</span> } } } ]<!-- -->, <span class="lg-highlight-comment">// The $set stage is an alias for ``$addFields`` stage</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">returnNewDocument</span>: <span class="lg-highlight-literal">true</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 class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $set </code> used in the pipeline refers to the aggregation stage <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> and not the update operator <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/set/#mongodb-update-up.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> . </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> The operation returns the <em> updated </em> document : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n \"grades\" : [ { \"grade\" : 80, \"mean\" : 75, \"std\" : 6 }, { \"grade\" : 85, \"mean\" : 90, \"std\" : 4 }, { \"grade\" : 85, \"mean\" :85, \"std\" : 6 } ],\n \"total\" : 250\n}","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->:<span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> } ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">250</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> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/aggregation-variables/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Variables in Aggregation Expressions <a class="headerlink leafygreen-ui-1kepx47" href="#variables-in-aggregation-expressions" 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="variables-in-aggregation-expressions"> </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="#user-variables" target="_self"> <span> User Variables </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#system-variables" target="_self"> <span> System Variables </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> Aggregation expressions </a> can use both user-defined and system variables. </p> <p class="leafygreen-ui-1kp3ins"> Variables can hold any <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types"> BSON type data </a> . To access the value of the variable, prefix the variable name with double dollar signs ( <code class="leafygreen-ui-1l06pbn"> $$ </code> ); i.e. <code class="leafygreen-ui-1l06pbn"> "$$&lt;variable&gt;" </code> . </p> <p class="leafygreen-ui-1kp3ins"> If the variable references an object, to access a specific field in the object, use the dot notation; i.e. <code class="leafygreen-ui-1l06pbn"> "$$&lt;variable&gt;.&lt;field&gt;" </code> . </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-agg-user-variables"> </span> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> User Variables <a class="headerlink leafygreen-ui-1kepx47" href="#user-variables" 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="user-variables"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> User variable names can contain the ascii characters <code class="leafygreen-ui-1l06pbn"> [_a-zA-Z0-9] </code> and any non-ascii character. </p> <p class="leafygreen-ui-1kp3ins"> User variable names must begin with a lowercase ascii letter <code class="leafygreen-ui-1l06pbn"> [a-z] </code> or a non-ascii character. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-agg-system-variables"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> System Variables <a class="headerlink leafygreen-ui-1kepx47" href="#system-variables" 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="system-variables"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB offers the following system variables: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:15%"/> <col style="width:50%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Variable </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="variable"> <dt> <code class="leafygreen-ui-1l06pbn"> NOW </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.NOW" title="Permalink to this definition"> <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="mongodb-variable-variable.NOW"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> A variable that returns the current datetime value. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.NOW" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> NOW </code> </span> </a> returns the same value for all members of the deployment and remains the same throughout all stages of the aggregation pipeline. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="variable"> <dt> <code class="leafygreen-ui-1l06pbn"> CLUSTER_TIME </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.CLUSTER_TIME" title="Permalink to this definition"> <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="mongodb-variable-variable.CLUSTER_TIME"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> A variable that returns the current timestamp value. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.CLUSTER_TIME" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> CLUSTER_TIME </code> </span> </a> is only available on replica sets and sharded clusters. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.CLUSTER_TIME" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> CLUSTER_TIME </code> </span> </a> returns the same value for all members of the deployment and remains the same throughout all stages of the pipeline. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="variable"> <dt> <code class="leafygreen-ui-1l06pbn"> ROOT </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.ROOT" title="Permalink to this definition"> <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="mongodb-variable-variable.ROOT"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> References the root document, i.e. the top-level document, currently being processed in the aggregation pipeline stage. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="variable"> <dt> <code class="leafygreen-ui-1l06pbn"> CURRENT </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.CURRENT" title="Permalink to this definition"> <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="mongodb-variable-variable.CURRENT"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> References the start of the field path being processed in the aggregation pipeline stage. Unless documented otherwise, all stages start with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.CURRENT" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> CURRENT </code> </span> </a> the same as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.ROOT" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> ROOT </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.CURRENT" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> CURRENT </code> </span> </a> is modifiable. However, since <code class="leafygreen-ui-1l06pbn"> $&lt;field&gt; </code> is equivalent to <code class="leafygreen-ui-1l06pbn"> $$CURRENT.&lt;field&gt; </code> , rebinding <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.CURRENT" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> CURRENT </code> </span> </a> changes the meaning of <code class="leafygreen-ui-1l06pbn"> $ </code> accesses. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="variable"> <dt> <code class="leafygreen-ui-1l06pbn"> REMOVE </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.REMOVE" title="Permalink to this definition"> <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="mongodb-variable-variable.REMOVE"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> A variable which evaluates to the missing value. Allows for the exclusion of fields in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> stages. </p> <p class="leafygreen-ui-1kp3ins"> For examples that use <code class="leafygreen-ui-1l06pbn"> $$REMOVE </code> , see: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#std-label-addFields-remove-example"> Remove Fields </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#std-label-remove-example"> Conditionally Exclude Fields </a> </p> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="variable"> <dt> <code class="leafygreen-ui-1l06pbn"> DESCEND </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.DESCEND" title="Permalink to this definition"> <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="mongodb-variable-variable.DESCEND"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> One of the allowed results of a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/redact/#mongodb-pipeline-pipe.-redact"> <code class="leafygreen-ui-1l06pbn"> $redact </code> </a> expression. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="variable"> <dt> <code class="leafygreen-ui-1l06pbn"> PRUNE </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.PRUNE" title="Permalink to this definition"> <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="mongodb-variable-variable.PRUNE"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> One of the allowed results of a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/redact/#mongodb-pipeline-pipe.-redact"> <code class="leafygreen-ui-1l06pbn"> $redact </code> </a> expression. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="variable"> <dt> <code class="leafygreen-ui-1l06pbn"> KEEP </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.KEEP" title="Permalink to this definition"> <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="mongodb-variable-variable.KEEP"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> One of the allowed results of a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/redact/#mongodb-pipeline-pipe.-redact"> <code class="leafygreen-ui-1l06pbn"> $redact </code> </a> expression. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="variable"> <dt> <code class="leafygreen-ui-1l06pbn"> SEARCH_META </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.SEARCH_META" title="Permalink to this definition"> <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="mongodb-variable-variable.SEARCH_META"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> A variable that stores the metadata results of an <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self"> <span> Atlas Search </span> </a> query. In all supported aggregation pipeline stages, a field set to the variable <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.SEARCH_META" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $$SEARCH_META </code> </span> </a> returns the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/query-syntax/#metadata-result-types" target="_self"> <span> metadata results </span> </a> for the query. </p> <p class="leafygreen-ui-1kp3ins"> For an example of its usage, see Atlas Search <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/facet/#search_meta-aggregation-variable" target="_self"> <span> facet </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/counting/#search_meta-aggregation-variable" target="_self"> <span> count <!-- --> . </span> </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="variable"> <dt> <code class="leafygreen-ui-1l06pbn"> USER_ROLES </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.USER_ROLES" title="Permalink to this definition"> <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="mongodb-variable-variable.USER_ROLES"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-roles"> roles </a> assigned to the current user. </p> <p class="leafygreen-ui-1kp3ins"> For use cases that include <code class="leafygreen-ui-1l06pbn"> USER_ROLES </code> , see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#std-label-find-user-roles-system-variable-example"> find </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setIntersection/#std-label-setIntersection-user-roles-system-variable-example"> aggregation </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/create-view/#std-label-create-view-user-roles-system-variable-example"> view </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#std-label-updateOne-example-user-roles-system-variable"> updateOne </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#std-label-updateMany-example-user-roles-system-variable"> updateMany </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#std-label-findAndModify-example-user-roles-system-variable"> findAndModify </a> examples. </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> </div> </div> </td> </tr> </tbody> </table> </div> <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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/let/#mongodb-expression-exp.-let"> <code class="leafygreen-ui-1l06pbn"> $let </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/redact/#mongodb-pipeline-pipe.-redact"> <code class="leafygreen-ui-1l06pbn"> $redact </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/map/#mongodb-expression-exp.-map"> <code class="leafygreen-ui-1l06pbn"> $map </code> </a> </p> </li> </ul> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $map (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-map--aggregation-" 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="-map--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#add-to-each-element-of-an-array" target="_self"> <span> Add to Each Element of an Array </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#truncate-each-array-element" target="_self"> <span> Truncate Each Array Element </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#convert-celsius-temperatures-to-fahrenheit" target="_self"> <span> Convert Celsius Temperatures to Fahrenheit </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="expression"> <dt> <code class="leafygreen-ui-1l06pbn"> $map </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-map" title="Permalink to this definition"> <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="mongodb-expression-exp.-map"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Applies an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> expression </a> to each item in an array and returns an array with the applied results. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> You can use <code class="leafygreen-ui-1l06pbn"> $map </code> for deployments hosted 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> </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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-map" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $map </code> </span> </a> expression has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $map: { input: &lt;expression&gt;, as: &lt;string&gt;, in: &lt;expression&gt; } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$map</span>: <!-- -->{ <span class="lg-highlight-attr">input</span>: &lt;<!-- -->expression<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">as</span>: &lt;<!-- -->string<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">in</span>: &lt;<!-- -->expression<!-- -->&gt; <!-- -->} }</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 class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Specification </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> input </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> An <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> expression </a> that resolves to an array. </p> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> input </code> resolves to <code class="leafygreen-ui-1l06pbn"> null </code> or refers to a missing field, <code class="leafygreen-ui-1l06pbn"> $map </code> returns <code class="leafygreen-ui-1l06pbn"> null </code> . </p> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> input </code> resolves to a non-array, non-null value, the pipeline errors. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> as </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Optional. A name for the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/"> variable </a> that represents each individual element of the <code class="leafygreen-ui-1l06pbn"> input </code> array. If no name is specified, the variable name defaults to <code class="leafygreen-ui-1l06pbn"> this </code> . </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> in </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> expression </a> that is applied to each element of the <code class="leafygreen-ui-1l06pbn"> input </code> array. The expression references each element individually with the variable name specified in <code class="leafygreen-ui-1l06pbn"> as </code> . </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> For more information on expressions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> Expression Operators <!-- --> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Add to Each Element of an Array <a class="headerlink leafygreen-ui-1kepx47" href="#add-to-each-element-of-an-array" 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="add-to-each-element-of-an-array"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> In <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> , create a sample collection named <code class="leafygreen-ui-1l06pbn"> grades </code> with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.grades.insertMany( [\n { quizzes: [ 5, 6, 7 ] },\n { quizzes: [ ] },\n { quizzes: [ 3, 8, 9 ] }\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">db.<span class="lg-highlight-property">grades</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">quizzes</span>: <!-- -->[ <span class="lg-highlight-number">5</span>, <span class="lg-highlight-number">6</span>, <span class="lg-highlight-number">7</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">quizzes</span>: <!-- -->[ <!-- -->] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">quizzes</span>: <!-- -->[ <span class="lg-highlight-number">3</span>, <span class="lg-highlight-number">8</span>, <span class="lg-highlight-number">9</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation uses <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-map" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $map </code> </span> </a> with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/add/#mongodb-expression-exp.-add"> <code class="leafygreen-ui-1l06pbn"> $add </code> </a> expression to increment each element in the <code class="leafygreen-ui-1l06pbn"> quizzes </code> array by <code class="leafygreen-ui-1l06pbn"> 2 </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.grades.aggregate( [\n {\n $project: {\n adjustedGrades: {\n $map: {\n input: \"$quizzes\",\n as: \"grade\",\n in: { $add: [ \"$$grade\", 2 ] }\n }\n }\n }\n }\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">db.<span class="lg-highlight-property">grades</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">adjustedGrades</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$map</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$quizzes"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">as</span>: <span class="lg-highlight-string">"grade"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">in</span>: <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$$grade"</span>, <span class="lg-highlight-number">2</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> This operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: ObjectId(\"6390b8f7237da390c6869a62\"),\n adjustedGrades: [ 7, 8, 9 ]\n },\n {\n _id: ObjectId(\"6390b8f7237da390c6869a63\"),\n adjustedGrades: []\n },\n {\n _id: ObjectId(\"6390b8f7237da390c6869a64\"),\n adjustedGrades: [ 5, 10, 11 ]\n }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6390b8f7237da390c6869a62"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">adjustedGrades</span>: <!-- -->[ <span class="lg-highlight-number">7</span>, <span class="lg-highlight-number">8</span>, <span class="lg-highlight-number">9</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6390b8f7237da390c6869a63"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">adjustedGrades</span>: <!-- -->[<!-- -->]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6390b8f7237da390c6869a64"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">adjustedGrades</span>: <!-- -->[ <span class="lg-highlight-number">5</span>, <span class="lg-highlight-number">10</span>, <span class="lg-highlight-number">11</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Truncate Each Array Element <a class="headerlink leafygreen-ui-1kepx47" href="#truncate-each-array-element" 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="truncate-each-array-element"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> In <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> , create a sample collection named <code class="leafygreen-ui-1l06pbn"> deliveries </code> with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.deliveries.insertMany( [\n {\n \"city\" : \"Bakersfield\",\n \"distances\" : [ 34.57, 81.96, 44.24 ]\n },\n {\n \"city\" : \"Barstow\",\n \"distances\" : [ 73.28, 9.67, 124.36 ]\n },\n {\n \"city\" : \"San Bernadino\",\n \"distances\" : [ 16.04, 3.25, 6.82 ]\n }\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">db.<span class="lg-highlight-property">deliveries</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"city"</span> <!-- -->: <span class="lg-highlight-string">"Bakersfield"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"distances"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">34.57</span>, <span class="lg-highlight-number">81.96</span>, <span class="lg-highlight-number">44.24</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"city"</span> <!-- -->: <span class="lg-highlight-string">"Barstow"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"distances"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">73.28</span>, <span class="lg-highlight-number">9.67</span>, <span class="lg-highlight-number">124.36</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"city"</span> <!-- -->: <span class="lg-highlight-string">"San Bernadino"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"distances"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">16.04</span>, <span class="lg-highlight-number">3.25</span>, <span class="lg-highlight-number">6.82</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation uses <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-map" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $map </code> </span> </a> to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/trunc/#mongodb-expression-exp.-trunc"> <code class="leafygreen-ui-1l06pbn"> truncate </code> </a> each element in the <code class="leafygreen-ui-1l06pbn"> distances </code> array to its integer. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.deliveries.aggregate( [\n {\n $project: {\n city: \"$city\",\n integerValues: {\n $map: {\n input: \"$distances\",\n as: \"decimalValue\",\n in: { $trunc: \"$$decimalValue\" }\n }\n }\n }\n }\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">db.<span class="lg-highlight-property">deliveries</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-string">"$city"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">integerValues</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$map</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$distances"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">as</span>: <span class="lg-highlight-string">"decimalValue"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">in</span>: <!-- -->{ <span class="lg-highlight-attr">$trunc</span>: <span class="lg-highlight-string">"$$decimalValue"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> This operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: ObjectId(\"6390b9b1237da390c6869a65\"),\n city: 'Bakersfield',\n integerValues: [ 34, 81, 44 ]\n },\n {\n _id: ObjectId(\"6390b9b1237da390c6869a66\"),\n city: 'Barstow',\n integerValues: [ 73, 9, 124 ]\n },\n {\n _id: ObjectId(\"6390b9b1237da390c6869a67\"),\n city: 'San Bernadino',\n integerValues: [ 16, 3, 6 ]\n }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6390b9b1237da390c6869a65"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-string">'Bakersfield'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">integerValues</span>: <!-- -->[ <span class="lg-highlight-number">34</span>, <span class="lg-highlight-number">81</span>, <span class="lg-highlight-number">44</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6390b9b1237da390c6869a66"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-string">'Barstow'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">integerValues</span>: <!-- -->[ <span class="lg-highlight-number">73</span>, <span class="lg-highlight-number">9</span>, <span class="lg-highlight-number">124</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6390b9b1237da390c6869a67"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-string">'San Bernadino'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">integerValues</span>: <!-- -->[ <span class="lg-highlight-number">16</span>, <span class="lg-highlight-number">3</span>, <span class="lg-highlight-number">6</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Convert Celsius Temperatures to Fahrenheit <a class="headerlink leafygreen-ui-1kepx47" href="#convert-celsius-temperatures-to-fahrenheit" 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="convert-celsius-temperatures-to-fahrenheit"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> In <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> , create a sample collection named <code class="leafygreen-ui-1l06pbn"> temperatures </code> with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.temperatures.insertMany( [\n {\n \"date\" : ISODate(\"2019-06-23\"),\n \"tempsC\" : [ 4, 12, 17 ]\n },\n {\n \"date\" : ISODate(\"2019-07-07\"),\n \"tempsC\" : [ 14, 24, 11 ]\n },\n {\n \"date\" : ISODate(\"2019-10-30\"),\n \"tempsC\" : [ 18, 6, 8 ]\n }\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">db.<span class="lg-highlight-property">temperatures</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-06-23"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tempsC"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">4</span>, <span class="lg-highlight-number">12</span>, <span class="lg-highlight-number">17</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-07-07"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tempsC"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">14</span>, <span class="lg-highlight-number">24</span>, <span class="lg-highlight-number">11</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-10-30"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tempsC"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">18</span>, <span class="lg-highlight-number">6</span>, <span class="lg-highlight-number">8</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> stage to add a new field to the documents called <code class="leafygreen-ui-1l06pbn"> tempsF </code> which contains Fahrenheit equivalents of the elements in the <code class="leafygreen-ui-1l06pbn"> tempsC </code> array. To convert from Celsius to Fahrenheit, the operation uses <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-map" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $map </code> </span> </a> to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/multiply/#mongodb-expression-exp.-multiply"> <code class="leafygreen-ui-1l06pbn"> $multiply </code> </a> the Celsius values by <code class="leafygreen-ui-1l06pbn"> 9/5 </code> and then <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/add/#mongodb-expression-exp.-add"> <code class="leafygreen-ui-1l06pbn"> $add </code> </a> <code class="leafygreen-ui-1l06pbn"> 32 </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":" db.temperatures.aggregate( [\n {\n $addFields: {\n \"tempsF\": {\n $map: {\n input: \"$tempsC\",\n as: \"tempInCelsius\",\n in: {\n $add: [ { $multiply: [ \"$$tempInCelsius\", 9/5 ] }, 32 ]\n }\n }\n }\n }\n }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"> db.<span class="lg-highlight-property">temperatures</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$addFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tempsF"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$map</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$tempsC"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">as</span>: <span class="lg-highlight-string">"tempInCelsius"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">in</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$add</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$multiply</span>: <!-- -->[ <span class="lg-highlight-string">"$$tempInCelsius"</span>, <span class="lg-highlight-number">9</span>/<span class="lg-highlight-number">5</span> ] }<!-- -->, <span class="lg-highlight-number">32</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> This operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: ObjectId(\"6390ba11237da390c6869a68\"),\n date: ISODate(\"2019-06-23T00:00:00.000Z\"),\n tempsC: [ 4, 12, 17 ],\n tempsF: [ 39.2, 53.6, 62.6 ]\n },\n {\n _id: ObjectId(\"6390ba11237da390c6869a69\"),\n date: ISODate(\"2019-07-07T00:00:00.000Z\"),\n tempsC: [ 14, 24, 11 ],\n tempsF: [ 57.2, 75.2, 51.8 ]\n },\n {\n _id: ObjectId(\"6390ba11237da390c6869a6a\"),\n date: ISODate(\"2019-10-30T00:00:00.000Z\"),\n tempsC: [ 18, 6, 8 ],\n tempsF: [ 64.4, 42.8, 46.4 ]\n }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6390ba11237da390c6869a68"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-06-23T00:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tempsC</span>: <!-- -->[ <span class="lg-highlight-number">4</span>, <span class="lg-highlight-number">12</span>, <span class="lg-highlight-number">17</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tempsF</span>: <!-- -->[ <span class="lg-highlight-number">39.2</span>, <span class="lg-highlight-number">53.6</span>, <span class="lg-highlight-number">62.6</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6390ba11237da390c6869a69"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-07-07T00:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tempsC</span>: <!-- -->[ <span class="lg-highlight-number">14</span>, <span class="lg-highlight-number">24</span>, <span class="lg-highlight-number">11</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tempsF</span>: <!-- -->[ <span class="lg-highlight-number">57.2</span>, <span class="lg-highlight-number">75.2</span>, <span class="lg-highlight-number">51.8</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6390ba11237da390c6869a6a"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-10-30T00:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tempsC</span>: <!-- -->[ <span class="lg-highlight-number">18</span>, <span class="lg-highlight-number">6</span>, <span class="lg-highlight-number">8</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tempsF</span>: <!-- -->[ <span class="lg-highlight-number">64.4</span>, <span class="lg-highlight-number">42.8</span>, <span class="lg-highlight-number">46.4</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> </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> <p class="leafygreen-ui-1kp3ins"> To learn more about expressions used in the previous examples, see: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/add/#mongodb-expression-exp.-add"> <code class="leafygreen-ui-1l06pbn"> $add </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/let/#mongodb-expression-exp.-let"> <code class="leafygreen-ui-1l06pbn"> $let </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/multiply/#mongodb-expression-exp.-multiply"> <code class="leafygreen-ui-1l06pbn"> $multiply </code> </a> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $lastN <a class="headerlink leafygreen-ui-1kepx47" href="#-lastn" 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="-lastn"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#aggregation-accumulator" target="_self"> <span> Aggregation Accumulator </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#restrictions" target="_self"> <span> Restrictions </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#examples" target="_self"> <span> Examples </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#array-operator" target="_self"> <span> Array Operator </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#syntax-1" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#behavior-1" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <div> <p> <em> New <!-- --> in version <!-- --> 5.2 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $lastN </code> can be used as an aggregation accumulator or array operator. As an aggregation accumulator, it an aggregation of the last <code class="leafygreen-ui-1l06pbn"> n </code> elements within a group. As an array operator, it returns the specified number of elements from the end of an array. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Aggregation Accumulator <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-accumulator" 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="aggregation-accumulator"> </div> </a> </h2> <dl class="group"> <dt> <code class="leafygreen-ui-1l06pbn"> $lastN </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-group-grp.-lastN" title="Permalink to this definition"> <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="mongodb-group-grp.-lastN"> </div> </a> </dt> <dd> </dd> </dl> <p class="leafygreen-ui-1kp3ins"> When <code class="leafygreen-ui-1l06pbn"> $lasttN </code> is used as an aggregation accumulator, the elements returned are meaningful only if they are in a specified sort order. If the group contains fewer than <code class="leafygreen-ui-1l06pbn"> n </code> elements, <code class="leafygreen-ui-1l06pbn"> $lastN </code> returns all elements in the group. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h3> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n $lastN:\n {\n input: &lt;expression&gt;,\n n: &lt;expression&gt;\n }\n}"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> $lastN:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> input: &lt;expression&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> n: &lt;expression&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> input </code> specifies the field(s) from the document to take the last <code class="leafygreen-ui-1l06pbn"> n </code> of. Input can be any expression. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> n </code> has to be a positive integral expression that is either a constant or depends on the <code class="leafygreen-ui-1l06pbn"> _id </code> value for <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> . For details see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-last-n-with-group-key" target="_self"> <span> group key example <!-- --> . </span> </a> </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h3> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Null and Missing Values <a class="headerlink leafygreen-ui-1kepx47" href="#null-and-missing-values" 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="null-and-missing-values"> </div> </a> </h4> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $lastN </code> does not filter out null values. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $lastN </code> converts missing values to null. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Consider the following aggregation that returns the last five documents from a group: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.aggregate( [\n {\n $documents: [\n { playerId: \"PlayerA\", gameId: \"G1\", score: 1 },\n { playerId: \"PlayerB\", gameId: \"G1\", score: 2 },\n { playerId: \"PlayerC\", gameId: \"G1\", score: 3 },\n { playerId: \"PlayerD\", gameId: \"G1\"},\n { playerId: \"PlayerE\", gameId: \"G1\", score: null }\n ]\n },\n {\n $group:\n {\n _id: \"$gameId\",\n lastFiveScores:\n {\n $lastN:\n {\n input: \"$score\",\n n: 5\n }\n }\n }\n }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$documents</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerA"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G1"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerB"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G1"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerC"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G1"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerD"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G1"</span>}<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerE"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G1"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-literal">null</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$group</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$gameId"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastFiveScores</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$lastN</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$score"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-number">5</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> In this example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/documents/#mongodb-pipeline-pipe.-documents"> <code class="leafygreen-ui-1l06pbn"> $documents </code> </a> creates the literal documents that contain player scores. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> groups the documents by <code class="leafygreen-ui-1l06pbn"> gameId </code> . This example has only one <code class="leafygreen-ui-1l06pbn"> gameId </code> , <code class="leafygreen-ui-1l06pbn"> G1 </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> PlayerD </code> has a missing score and <code class="leafygreen-ui-1l06pbn"> PlayerE </code> has a null <code class="leafygreen-ui-1l06pbn"> score </code> . These values are both considered as null. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> lastFiveScores </code> field is specified using <code class="leafygreen-ui-1l06pbn"> input : "$score" </code> and returned as an array. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Since there is no sort criteria the last 5 <code class="leafygreen-ui-1l06pbn"> score </code> fields are returned. </p> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: \"G1\",\n lastFiveScores: [ 1, 2, 3, null, null ]\n }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"G1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastFiveScores</span>: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>, <span class="lg-highlight-number">3</span>, <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-literal">null</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Comparison of <code class="leafygreen-ui-1l06pbn"> $lastN </code> and <code class="leafygreen-ui-1l06pbn"> $bottomN </code> <a class="headerlink leafygreen-ui-1kepx47" href="#comparison-of--lastn-and--bottomn" 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="comparison-of--lastn-and--bottomn"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Both <code class="leafygreen-ui-1l06pbn"> $lastN </code> and <code class="leafygreen-ui-1l06pbn"> $bottomN </code> accumulators can accomplish similar results. </p> <p class="leafygreen-ui-1kp3ins"> In general: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the documents coming into <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> are already ordered, you should use <code class="leafygreen-ui-1l06pbn"> $lastN </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If you're sorting and selecting the bottom <code class="leafygreen-ui-1l06pbn"> n </code> elements then you can use <code class="leafygreen-ui-1l06pbn"> $bottomN </code> to accomplish both tasks with one accumulator. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $lastN </code> can be used as an aggregation expression, <code class="leafygreen-ui-1l06pbn"> $bottomN </code> cannot. </p> </li> </ul> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Restrictions <a class="headerlink leafygreen-ui-1kepx47" href="#restrictions" 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="restrictions"> </div> </a> </h3> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Window Function and Aggregation Expression Support <a class="headerlink leafygreen-ui-1kepx47" href="#window-function-and-aggregation-expression-support" 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="window-function-and-aggregation-expression-support"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $lastN </code> is supported as an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> aggregation expression <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $lastN </code> is supported as a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> window operator </code> . </a> </p> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Consider a <code class="leafygreen-ui-1l06pbn"> gamescores </code> collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.gamescores.insertMany([\n { playerId: \"PlayerA\", gameId: \"G1\", score: 31 },\n { playerId: \"PlayerB\", gameId: \"G1\", score: 33 },\n { playerId: \"PlayerC\", gameId: \"G1\", score: 99 },\n { playerId: \"PlayerD\", gameId: \"G1\", score: 1 },\n { playerId: \"PlayerA\", gameId: \"G2\", score: 10 },\n { playerId: \"PlayerB\", gameId: \"G2\", score: 14 },\n { playerId: \"PlayerC\", gameId: \"G2\", score: 66 },\n { playerId: \"PlayerD\", gameId: \"G2\", score: 80 }\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">db.<span class="lg-highlight-property">gamescores</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerA"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G1"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">31</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerB"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G1"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">33</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerC"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G1"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">99</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerD"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G1"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerA"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G2"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerB"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G2"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">14</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerC"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G2"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">66</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">playerId</span>: <span class="lg-highlight-string">"PlayerD"</span>, <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G2"</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">80</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> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Find the Last Three Player Scores for a Single Game <a class="headerlink leafygreen-ui-1kepx47" href="#find-the-last-three-player-scores-for-a-single-game" 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="find-the-last-three-player-scores-for-a-single-game"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can use the <code class="leafygreen-ui-1l06pbn"> $lastN </code> accumulator to find the last three scores in a single game. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.gamescores.aggregate( [\n {\n $match : { gameId : \"G1\" }\n },\n {\n $group:\n {\n _id: \"$gameId\",\n lastThreeScores:\n {\n $lastN:\n {\n input: [\"$playerId\", \"$score\"],\n n:3\n }\n }\n }\n }\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">db.<span class="lg-highlight-property">gamescores</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->$match<!-- --> <!-- -->: <!-- -->{ <!-- -->gameId <!-- -->: <span class="lg-highlight-string">"G1"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$group</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$gameId"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastThreeScores</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$lastN</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <!-- -->[<span class="lg-highlight-string">"$playerId"</span>, <span class="lg-highlight-string">"$score"</span>]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">n</span>:<span class="lg-highlight-number">3</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The example pipeline: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> to filter the results on a single <code class="leafygreen-ui-1l06pbn"> gameId </code> . In this case, <code class="leafygreen-ui-1l06pbn"> G1 </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> to group the results by <code class="leafygreen-ui-1l06pbn"> gameId </code> . In this case, <code class="leafygreen-ui-1l06pbn"> G1 </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specifies the fields that are output from <code class="leafygreen-ui-1l06pbn"> $lastN </code> with <code class="leafygreen-ui-1l06pbn"> output : ["$playerId"," $score"] </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Uses <code class="leafygreen-ui-1l06pbn"> $lastN </code> to return the last three documents for the <code class="leafygreen-ui-1l06pbn"> G1 </code> game with <code class="leafygreen-ui-1l06pbn"> n : 3 </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: \"G1\",\n lastThreeScores: [ [ \"PlayerB\", 33 ], [ \"PlayerC\", 99 ], [ \"PlayerD\", 1 ] ]\n }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"G1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastThreeScores</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"PlayerB"</span>, <span class="lg-highlight-number">33</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">"PlayerC"</span>, <span class="lg-highlight-number">99</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">"PlayerD"</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">]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Finding the Last Three Player Scores Across Multiple Games <a class="headerlink leafygreen-ui-1kepx47" href="#finding-the-last-three-player-scores-across-multiple-games" 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="finding-the-last-three-player-scores-across-multiple-games"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can use the <code class="leafygreen-ui-1l06pbn"> $lastN </code> accumulator to find the last <code class="leafygreen-ui-1l06pbn"> n </code> input fields in each game. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.gamescores.aggregate( [\n {\n $group:\n {\n _id: \"$gameId\", playerId:\n {\n $lastN:\n {\n input: [ \"$playerId\",\"$score\" ],\n n: 3\n }\n }\n }\n }\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">db.<span class="lg-highlight-property">gamescores</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$group</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$gameId"</span>, <span class="lg-highlight-attr">playerId</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$lastN</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <!-- -->[ <span class="lg-highlight-string">"$playerId"</span>,<span class="lg-highlight-string">"$score"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-number">3</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The example pipeline: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Uses <code class="leafygreen-ui-1l06pbn"> $group </code> to group the results by <code class="leafygreen-ui-1l06pbn"> gameId </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Uses <code class="leafygreen-ui-1l06pbn"> $lastN </code> to return the last three documents for each game with <code class="leafygreen-ui-1l06pbn"> n: 3 </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specifies the fields that are input for <code class="leafygreen-ui-1l06pbn"> $lastN </code> with <code class="leafygreen-ui-1l06pbn"> input : ["$playerId", "$score"] </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: 'G2',\n playerId: [ [ 'PlayerB', 14 ], [ 'PlayerC', 66 ], [ 'PlayerD', 80 ] ]\n },\n {\n _id: 'G1',\n playerId: [ [ 'PlayerB', 33 ], [ 'PlayerC', 99 ], [ 'PlayerD', 1 ] ]\n }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'G2'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">playerId</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">'PlayerB'</span>, <span class="lg-highlight-number">14</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">'PlayerC'</span>, <span class="lg-highlight-number">66</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">'PlayerD'</span>, <span class="lg-highlight-number">80</span> ] ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'G1'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">playerId</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">'PlayerB'</span>, <span class="lg-highlight-number">33</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">'PlayerC'</span>, <span class="lg-highlight-number">99</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">'PlayerD'</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">]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Using <code class="leafygreen-ui-1l06pbn"> $sort </code> With <code class="leafygreen-ui-1l06pbn"> $lastN </code> <a class="headerlink leafygreen-ui-1kepx47" href="#using--sort-with--lastn" 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="using--sort-with--lastn"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Using a <code class="leafygreen-ui-1l06pbn"> $sort </code> stage earlier in the pipeline can influence the results of the <code class="leafygreen-ui-1l06pbn"> $lastN </code> accumulator. </p> <p class="leafygreen-ui-1kp3ins"> In this example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> {$sort : { score : -1 } } </code> sorts the highest scores to the back of each group. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> lastN </code> returns the three lowest scores from the back of each group. </p> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.gamescores.aggregate( [\n { $sort : { score : -1 } },\n {\n\n $group:\n { _id: \"$gameId\", playerId:\n {\n $lastN:\n {\n input: [ \"$playerId\",\"$score\" ],\n n: 3\n }\n }\n }\n }\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">db.<span class="lg-highlight-property">gamescores</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$sort<!-- --> <!-- -->: <!-- -->{ <!-- -->score <!-- -->: <!-- -->-<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"> <span class="lg-highlight-attr">$group</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$gameId"</span>, <span class="lg-highlight-attr">playerId</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$lastN</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <!-- -->[ <span class="lg-highlight-string">"$playerId"</span>,<span class="lg-highlight-string">"$score"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-number">3</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: 'G2',\n playerId: [ [ 'PlayerC', 66 ], [ 'PlayerB', 14 ], [ 'PlayerA', 10 ] ]\n },\n {\n _id: 'G1',\n playerId: [ [ 'PlayerB', 33 ], [ 'PlayerA', 31 ], [ 'PlayerD', 1 ] ]\n }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'G2'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">playerId</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">'PlayerC'</span>, <span class="lg-highlight-number">66</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">'PlayerB'</span>, <span class="lg-highlight-number">14</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">'PlayerA'</span>, <span class="lg-highlight-number">10</span> ] ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'G1'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">playerId</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">'PlayerB'</span>, <span class="lg-highlight-number">33</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">'PlayerA'</span>, <span class="lg-highlight-number">31</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">'PlayerD'</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">]</td></tr></tbody></table></code></pre> </div> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-last-n-with-group-key"> </span> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Computing <code class="leafygreen-ui-1l06pbn"> n </code> Based on the Group Key for <code class="leafygreen-ui-1l06pbn"> $group </code> <a class="headerlink leafygreen-ui-1kepx47" href="#computing-n-based-on-the-group-key-for--group" 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="computing-n-based-on-the-group-key-for--group"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can also assign the value of <code class="leafygreen-ui-1l06pbn"> n </code> dynamically. In this example, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/cond/#mongodb-expression-exp.-cond"> <code class="leafygreen-ui-1l06pbn"> $cond </code> </a> expression is used on the <code class="leafygreen-ui-1l06pbn"> gameId </code> field. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.gamescores.aggregate([\n {\n $group:\n {\n _id: {\"gameId\": \"$gameId\"},\n gamescores:\n {\n $lastN:\n {\n input: \"$score\",\n n: { $cond: { if: {$eq: [\"$gameId\",\"G2\"] }, then: 1, else: 3 } }\n }\n }\n }\n }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">gamescores</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$group</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <!-- -->{<span class="lg-highlight-string">"gameId"</span>: <span class="lg-highlight-string">"$gameId"</span>}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">gamescores</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$lastN</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$score"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">n</span>: <!-- -->{ <span class="lg-highlight-attr">$cond</span>: <!-- -->{ <span class="lg-highlight-attr">if</span>: <!-- -->{<span class="lg-highlight-attr">$eq</span>: <!-- -->[<span class="lg-highlight-string">"$gameId"</span>,<span class="lg-highlight-string">"G2"</span>] }<!-- -->, <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">else</span>: <span class="lg-highlight-number">3</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The example pipeline: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Uses <code class="leafygreen-ui-1l06pbn"> $group </code> to group the results by <code class="leafygreen-ui-1l06pbn"> gameId </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specifies the fields that input for <code class="leafygreen-ui-1l06pbn"> $lastN </code> with <code class="leafygreen-ui-1l06pbn"> input : "$score" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the <code class="leafygreen-ui-1l06pbn"> gameId </code> is <code class="leafygreen-ui-1l06pbn"> G2 </code> then <code class="leafygreen-ui-1l06pbn"> n </code> is 1, otherwise <code class="leafygreen-ui-1l06pbn"> n </code> is 3. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: { gameId: \"G1\" }, gamescores: [ 33, 99, 1 ] },\n { _id: { gameId: \"G2\" }, gamescores: [ 80 ] }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G1"</span> }<!-- -->, <span class="lg-highlight-attr">gamescores</span>: <!-- -->[ <span class="lg-highlight-number">33</span>, <span class="lg-highlight-number">99</span>, <span class="lg-highlight-number">1</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">gameId</span>: <span class="lg-highlight-string">"G2"</span> }<!-- -->, <span class="lg-highlight-attr">gamescores</span>: <!-- -->[ <span class="lg-highlight-number">80</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-lastN-aggregation-expression"> </span> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Using <code class="leafygreen-ui-1l06pbn"> $lastN </code> as an Aggregation Expression <a class="headerlink leafygreen-ui-1kepx47" href="#using--lastn-as-an-aggregation-expression" 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="using--lastn-as-an-aggregation-expression"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can also use <code class="leafygreen-ui-1l06pbn"> $lastN </code> as an aggregation expression. </p> <p class="leafygreen-ui-1kp3ins"> In this example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/documents/#mongodb-pipeline-pipe.-documents"> <code class="leafygreen-ui-1l06pbn"> $documents </code> </a> creates the literal document that contains an array of values. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $project </code> is used to return the output of <code class="leafygreen-ui-1l06pbn"> $lastN </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> _id </code> is omited from the output with <code class="leafygreen-ui-1l06pbn"> _id : 0 </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $lastN </code> uses the input array of <code class="leafygreen-ui-1l06pbn"> [10, 20, 30, 40] </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The last three elements of the array are returned for the input document. </p> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.aggregate( [\n {\n $documents: [\n { array: [10, 20, 30, 40] } ]\n },\n { $project: {\n lastThreeElements:{\n $lastN:\n {\n input: \"$array\",\n n: 3\n }\n }\n }\n }\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">db.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$documents</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">array</span>: <!-- -->[<span class="lg-highlight-number">10</span>, <span class="lg-highlight-number">20</span>, <span class="lg-highlight-number">30</span>, <span class="lg-highlight-number">40</span>] } ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastThreeElements</span>:<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$lastN</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$array"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-number">3</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ { lastThreeElements: [ 20, 30, 40 ] } ]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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">[ <!-- -->{ <span class="lg-highlight-attr">lastThreeElements</span>: <!-- -->[ <span class="lg-highlight-number">20</span>, <span class="lg-highlight-number">30</span>, <span class="lg-highlight-number">40</span> ] } ]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Array Operator <a class="headerlink leafygreen-ui-1kepx47" href="#array-operator" 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="array-operator"> </div> </a> </h2> <dl class="expression"> <dt> <code class="leafygreen-ui-1l06pbn"> $lastN </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-lastN" title="Permalink to this definition"> <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="mongodb-expression-exp.-lastN"> </div> </a> </dt> <dd> </dd> </dl> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax-1" 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="syntax-1"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-lastN" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $lastN </code> </span> </a> has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $lastN: { n: &lt;expression&gt;, input: &lt;expression&gt; } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$lastN</span>: <!-- -->{ <span class="lg-highlight-attr">n</span>: &lt;<!-- -->expression<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">input</span>: &lt;<!-- -->expression<!-- -->&gt; <!-- -->} }</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 class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> n </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> expression </a> that resolves to a positive integer. The integer specifies the number of array elements that <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-lastN" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $lastN </code> </span> </a> returns. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> input </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> expression </a> that resolves to the array from which to return <code class="leafygreen-ui-1l06pbn"> n </code> elements. </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior-1" 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="behavior-1"> </div> </a> </h3> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-lastN" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $lastN </code> </span> </a> returns elements in the same order they appear in the input array. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-lastN" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $lastN </code> </span> </a> does not filter out <code class="leafygreen-ui-1l06pbn"> null </code> values in the input array. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You cannot specify a value of <code class="leafygreen-ui-1l06pbn"> n </code> less than <code class="leafygreen-ui-1l06pbn"> 1 </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the specified <code class="leafygreen-ui-1l06pbn"> n </code> is greater than or equal to the number of elements in the <code class="leafygreen-ui-1l06pbn"> input </code> array, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-lastN" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $lastN </code> </span> </a> returns the <code class="leafygreen-ui-1l06pbn"> input </code> array. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> input </code> resolves to a non-array value, the aggregation operation errors. </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The collection <code class="leafygreen-ui-1l06pbn"> games </code> has the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.games.insertMany([\n { \"playerId\" : 1, \"score\" : [ 1, 2, 3 ] },\n { \"playerId\" : 2, \"score\" : [ 12, 90, 7, 89, 8 ] },\n { \"playerId\" : 3, \"score\" : [ null ] },\n { \"playerId\" : 4, \"score\" : [ ] },\n { \"playerId\" : 5, \"score\" : [ 1293, null, 3489, 9 ]},\n { \"playerId\" : 6, \"score\" : [ \"12.1\", 2, NumberLong(\"2090845886852\"), 23 ]}\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">games</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">"playerId"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>, <span class="lg-highlight-number">3</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"playerId"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">12</span>, <span class="lg-highlight-number">90</span>, <span class="lg-highlight-number">7</span>, <span class="lg-highlight-number">89</span>, <span class="lg-highlight-number">8</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"playerId"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-literal">null</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"playerId"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <!-- -->[ <!-- -->] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"playerId"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">1293</span>, <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-number">3489</span>, <span class="lg-highlight-number">9</span> ]}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"playerId"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"12.1"</span>, <span class="lg-highlight-number">2</span>, <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"2090845886852"</span>)<!-- -->, <span class="lg-highlight-number">23</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> <p class="leafygreen-ui-1kp3ins"> The following example uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-lastN" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $lastN </code> </span> </a> operator to retrieve the last three scores for each player. The scores are returned in the new field <code class="leafygreen-ui-1l06pbn"> lastScores </code> created by <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> . </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.games.aggregate([\n { $addFields: { lastScores: { $lastN: { n: 3, input: \"$score\" } } } }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">games</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">$addFields</span>: <!-- -->{ <span class="lg-highlight-attr">lastScores</span>: <!-- -->{ <span class="lg-highlight-attr">$lastN</span>: <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$score"</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[{\n \"playerId\": 1,\n \"score\": [ 1, 2, 3 ],\n \"lastScores\": [ 1, 2, 3 ]\n},\n{\n \"playerId\": 2,\n \"score\": [ 12, 90, 7, 89, 8 ],\n \"lastScores\": [ 7, 89, 8 ]\n},\n{\n \"playerId\": 3,\n \"score\": [ null ],\n \"lastScores\": [ null ]\n},\n{\n \"playerId\": 4,\n \"score\": [ ],\n \"lastScores\": [ ]\n},\n{\n \"playerId\": 5,\n \"score\": [ 1293, null, 3489, 9 ],\n \"lastScores\": [ null, 3489, 9 ]\n},\n{\n \"playerId\": 6,\n \"score\": [ \"12.1\", 2, NumberLong(\"2090845886852\"), 23 ],\n \"lastScores\": [ 2, NumberLong(\"2090845886852\"), 23 ]\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">[<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"playerId"</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>, <span class="lg-highlight-number">3</span> ]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastScores"</span>: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>, <span class="lg-highlight-number">3</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"playerId"</span>: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <!-- -->[ <span class="lg-highlight-number">12</span>, <span class="lg-highlight-number">90</span>, <span class="lg-highlight-number">7</span>, <span class="lg-highlight-number">89</span>, <span class="lg-highlight-number">8</span> ]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastScores"</span>: <!-- -->[ <span class="lg-highlight-number">7</span>, <span class="lg-highlight-number">89</span>, <span class="lg-highlight-number">8</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"playerId"</span>: <span class="lg-highlight-number">3</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <!-- -->[ <span class="lg-highlight-literal">null</span> ]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastScores"</span>: <!-- -->[ <span class="lg-highlight-literal">null</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"playerId"</span>: <span class="lg-highlight-number">4</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <!-- -->[ <!-- -->]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastScores"</span>: <!-- -->[ <!-- -->]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"playerId"</span>: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <!-- -->[ <span class="lg-highlight-number">1293</span>, <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-number">3489</span>, <span class="lg-highlight-number">9</span> ]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastScores"</span>: <!-- -->[ <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-number">3489</span>, <span class="lg-highlight-number">9</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"playerId"</span>: <span class="lg-highlight-number">6</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <!-- -->[ <span class="lg-highlight-string">"12.1"</span>, <span class="lg-highlight-number">2</span>, <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"2090845886852"</span>)<!-- -->, <span class="lg-highlight-number">23</span> ]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lastScores"</span>: <!-- -->[ <span class="lg-highlight-number">2</span>, <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"2090845886852"</span>)<!-- -->, <span class="lg-highlight-number">23</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 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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/firstN/#mongodb-expression-exp.-firstN"> <code class="leafygreen-ui-1l06pbn"> $firstN </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sortArray/#mongodb-expression-exp.-sortArray"> <code class="leafygreen-ui-1l06pbn"> $sortArray </code> </a> </p> </li> </ul> </div> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $tan (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-tan--aggregation-" 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="-tan--aggregation-"> </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="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <dl class="expression"> <dt> <code class="leafygreen-ui-1l06pbn"> $tan </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-tan" title="Permalink to this definition"> <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="mongodb-expression-exp.-tan"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Returns the tangent of a value that is measured in radians. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-tan" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $tan </code> </span> </a> has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $tan: &lt;expression&gt; }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$tan</span>: &lt;<!-- -->expression<!-- -->&gt; <!-- -->}</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"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-tan" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $tan </code> </span> </a> takes any valid <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> expression </a> that resolves to a number. If the expression returns a value in degrees, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/degreesToRadians/#mongodb-expression-exp.-degreesToRadians"> <code class="leafygreen-ui-1l06pbn"> $degreesToRadians </code> </a> operator to convert the result to radians. </p> <p class="leafygreen-ui-1kp3ins"> By default <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-tan" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $tan </code> </span> </a> returns values as a <code class="leafygreen-ui-1l06pbn"> double </code> . <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-tan" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $tan </code> </span> </a> can also return values as a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self"> <span> 128-bit decimal </span> </a> as long as the <code class="leafygreen-ui-1l06pbn"> &lt;expression&gt; </code> resolves to a 128-bit decimal value. </p> <p class="leafygreen-ui-1kp3ins"> For more information on expressions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> Expression Operators <!-- --> . </a> </p> </dd> </dl> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> null </code> , <code class="leafygreen-ui-1l06pbn"> NaN </code> , and <code class="leafygreen-ui-1l06pbn"> +/- Infinity </code> <a class="headerlink leafygreen-ui-1kepx47" href="#null--nan--and-----infinity" 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="null--nan--and-----infinity"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If the argument resolves to a value of <code class="leafygreen-ui-1l06pbn"> null </code> or refers to a field that is missing, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-tan" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $tan </code> </span> </a> returns <code class="leafygreen-ui-1l06pbn"> null </code> . If the argument resolves to <code class="leafygreen-ui-1l06pbn"> NaN </code> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-tan" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $tan </code> </span> </a> returns <code class="leafygreen-ui-1l06pbn"> NaN </code> . If the argument resolves to negative or positive infinity, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-tan" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $tan </code> </span> </a> throws an error. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:85%"/> <col style="width:15%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Example </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Results </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { $tan: NaN } </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> NaN </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { $tan: null } </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> null </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { $tan : Infinity} </code> </p> <p class="leafygreen-ui-1kp3ins"> <em> or </em> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { $tan : -Infinity } </code> </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Throws an error message resembling the following formatted output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"errmsg\" :\n \"Failed to optimize pipeline :: caused by :: cannot\n apply $tan to -inf, value must in (-inf,inf)\"","programmingLanguage":"Bash"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"errmsg"</span> :</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Failed to optimize pipeline :: caused by :: cannot</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> apply </span><span class="lg-highlight-variable lg-highlight-string">$tan</span><span class="lg-highlight-string"> to -inf, value must in (-inf,inf)"</span></td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-8"> <div aria-label="Tabs to describe usage of degrees/radians" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_1hc2wt2cy" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_uawhece2e" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Tangent of Value in Degrees </div> </button> <button aria-controls="_ypjsaxls5" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_yb7yhemt6" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Tangent of Value in Radians </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="_adwoixqas" class="" id="_xqdc1e0er" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> trigonometry </code> collection contains a document that stores one side and one angle in a right-angle triangle: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"angle_a\" : NumberDecimal(\"53.13010235415597870314438744090659\"),\n \"side_a\" : NumberDecimal(\"3\")\n}","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"53.13010235415597870314438744090659"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-tan" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $tan </code> </span> </a> expression to calculate the side opposite to <code class="leafygreen-ui-1l06pbn"> angle_a </code> and add it to the input document using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> pipeline stage. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trigonometry.aggregate([\n {\n $addFields : {\n \"side_b\" : {\n $multiply : [\n { $tan : {$degreesToRadians : \"$angle_a\"} },\n \"$side_a\"\n ]\n }\n }\n }\n])","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.trigonometry.aggregate([</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$addFields</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$multiply</span> : [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-variable">$tan</span> : {<span class="lg-highlight-variable">$degreesToRadians</span> : <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$angle_a</span><span class="lg-highlight-string">"</span>} },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$side_a</span><span class="lg-highlight-string">"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/degreesToRadians/#mongodb-expression-exp.-degreesToRadians"> <code class="leafygreen-ui-1l06pbn"> $degreesToRadians </code> </a> expression converts the degree value of <code class="leafygreen-ui-1l06pbn"> angle_a </code> to the equivalent value in radians. </p> <p class="leafygreen-ui-1kp3ins"> The command returns the following output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"angle_a\" : NumberDecimal(\"53.13010235415597870314438744090659\"),\n \"side_a\" : NumberDecimal(\"3\")\n \"side_b\" : NumberDecimal(4.000000000000000000000000000000000\")\n}","programmingLanguage":"Bash"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"53.13010235415597870314438744090659"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : NumberDecimal(4.000000000000000000000000000000000<span class="lg-highlight-string">")</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">}</span></td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Since <code class="leafygreen-ui-1l06pbn"> angle_a </code> and <code class="leafygreen-ui-1l06pbn"> side_a </code> are stored as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self"> <span> 128-bit decimals </span> </a> , the output of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-tan" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $tan </code> </span> </a> is a 128-bit decimal. </p> </div> </div> </div> <div> <div aria-labelledby="_zo3j44zq9" class="leafygreen-ui-38lglc" id="_qxlmtk2ab" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> trigonometry </code> collection contains a document that stores the hypotenuse and one angle in a right-angle triangle: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"angle_a\" : NumberDecimal(\"0.9272952180016122324285124629224288\"),\n \"side_a\" : NumberDecimal(\"3\")\n}","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"0.9272952180016122324285124629224288"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-tan" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $tan </code> </span> </a> expression to calculate the side adjacent to <code class="leafygreen-ui-1l06pbn"> angle_a </code> and add it to the input document using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> pipeline stage. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trigonometry.aggregate([\n {\n $addFields : {\n \"side_b\" : {\n $multiply : [\n { $tan : \"$angle_a\" },\n \"$side_a\"\n ]\n }\n }\n }\n])","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.trigonometry.aggregate([</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$addFields</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$multiply</span> : [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-variable">$tan</span> : <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$angle_a</span><span class="lg-highlight-string">"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$side_a</span><span class="lg-highlight-string">"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The command returns the following output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"angle_a\" : NumberDecimal(\"0.9272952180016122324285124629224288\"),\n \"side_a\" : NumberDecimal(\"3\")\n \"side_b\" : NumberDecimal(\"3.999999999999999999999999999999999\")\n}","programmingLanguage":"Bash"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"0.9272952180016122324285124629224288"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : NumberDecimal(<span class="lg-highlight-string">"3.999999999999999999999999999999999"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Since <code class="leafygreen-ui-1l06pbn"> angle_a </code> and <code class="leafygreen-ui-1l06pbn"> side_a </code> are stored as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self"> <span> 128-bit decimals </span> </a> , the output of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-tan" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $tan </code> </span> </a> is a 128-bit decimal. </p> </div> </div> </div> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $cos (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-cos--aggregation-" 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="-cos--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="expression"> <dt> <code class="leafygreen-ui-1l06pbn"> $cos </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-cos" title="Permalink to this definition"> <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="mongodb-expression-exp.-cos"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Returns the cosine of a value that is measured in radians. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-cos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $cos </code> </span> </a> has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $cos: &lt;expression&gt; }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$cos</span>: &lt;<!-- -->expression<!-- -->&gt; <!-- -->}</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"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-cos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $cos </code> </span> </a> takes any valid <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> expression </a> that resolves to a number. If the expression returns a value in degrees, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/degreesToRadians/#mongodb-expression-exp.-degreesToRadians"> <code class="leafygreen-ui-1l06pbn"> $degreesToRadians </code> </a> operator to convert the result to radians. </p> <p class="leafygreen-ui-1kp3ins"> By default <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-cos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $cos </code> </span> </a> returns values as a <code class="leafygreen-ui-1l06pbn"> double </code> . <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-cos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $cos </code> </span> </a> can also return values as a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self"> <span> 128-bit decimal </span> </a> as long as the <code class="leafygreen-ui-1l06pbn"> &lt;expression&gt; </code> resolves to a 128-bit decimal value. </p> <p class="leafygreen-ui-1kp3ins"> For more information on expressions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> Expression Operators <!-- --> . </a> </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> null </code> , <code class="leafygreen-ui-1l06pbn"> NaN </code> , and <code class="leafygreen-ui-1l06pbn"> +/- Infinity </code> <a class="headerlink leafygreen-ui-1kepx47" href="#null--nan--and-----infinity" 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="null--nan--and-----infinity"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If the argument resolves to a value of <code class="leafygreen-ui-1l06pbn"> null </code> or refers to a field that is missing, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-cos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $cos </code> </span> </a> returns <code class="leafygreen-ui-1l06pbn"> null </code> . If the argument resolves to <code class="leafygreen-ui-1l06pbn"> NaN </code> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-cos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $cos </code> </span> </a> returns <code class="leafygreen-ui-1l06pbn"> NaN </code> . If the argument resolves to negative or positive infinity, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-cos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $cos </code> </span> </a> throws an error. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:85%"/> <col style="width:15%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Example </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Results </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { $cos: NaN } </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> NaN </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { $cos: null } </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> null </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { $cos : Infinity} </code> </p> <p class="leafygreen-ui-1kp3ins"> <em> or </em> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { $cos : -Infinity } </code> </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Throws an error message resembling the following formatted output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"errmsg\" :\n \"Failed to optimize pipeline :: caused by :: cannot\n apply $cos to -inf, value must in (-inf,inf)\"","programmingLanguage":"Bash"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"errmsg"</span> :</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Failed to optimize pipeline :: caused by :: cannot</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> apply </span><span class="lg-highlight-variable lg-highlight-string">$cos</span><span class="lg-highlight-string"> to -inf, value must in (-inf,inf)"</span></td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-9"> <div aria-label="Tabs to describe usage of degrees/radians" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_j06kogfmp" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_xy9a2h9sb" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Cosine of Value in Degrees </div> </button> <button aria-controls="_j6ngss6lx" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_x1zl9ui51" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Cosine of Value in Radians </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="_8r6uevlra" class="" id="_pqy5vslld" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> trigonometry </code> collection contains a document that stores the hypotenuse and one angle in a right-angle triangle: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"angle_a\" : NumberDecimal(\"53.13010235415597870314438744090659\"),\n \"hypotenuse\" : NumberDecimal(\"5\")\n}","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"53.13010235415597870314438744090659"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-cos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $cos </code> </span> </a> expression to calculate the side adjacent to <code class="leafygreen-ui-1l06pbn"> angle_a </code> and add it to the input document using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> pipeline stage. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trigonometry.aggregate([\n {\n $addFields : {\n \"side_a\" : {\n $multiply : [\n { $cos : {$degreesToRadians : \"$angle_a\"} },\n \"$hypotenuse\"\n ]\n }\n }\n }\n])","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.trigonometry.aggregate([</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$addFields</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$multiply</span> : [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-variable">$cos</span> : {<span class="lg-highlight-variable">$degreesToRadians</span> : <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$angle_a</span><span class="lg-highlight-string">"</span>} },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$hypotenuse</span><span class="lg-highlight-string">"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/degreesToRadians/#mongodb-expression-exp.-degreesToRadians"> <code class="leafygreen-ui-1l06pbn"> $degreesToRadians </code> </a> expression converts the degree value of <code class="leafygreen-ui-1l06pbn"> angle_a </code> to the equivalent value in radians. </p> <p class="leafygreen-ui-1kp3ins"> The command returns the following output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"angle_a\" : NumberDecimal(\"53.13010235415597870314438744090659\"),\n \"side_a\" : NumberDecimal(\"2.999999999999999999999999999999999\"),\n \"hypotenuse\" : NumberDecimal(\"5\"),\n}","programmingLanguage":"Bash"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"53.13010235415597870314438744090659"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"2.999999999999999999999999999999999"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Since <code class="leafygreen-ui-1l06pbn"> angle_a </code> and <code class="leafygreen-ui-1l06pbn"> hypotenuse </code> are stored as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self"> <span> 128-bit decimals </span> </a> , the output of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-cos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $cos </code> </span> </a> is a 128-bit decimal. </p> </div> </div> </div> <div> <div aria-labelledby="_aet2ix0bs" class="leafygreen-ui-38lglc" id="_32cfjw6r2" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> trigonometry </code> collection contains a document that stores the hypotenuse and one angle in a right-angle triangle: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"angle_a\" : NumberDecimal(\"0.9272952180016122324285124629224288\"),\n \"hypotenuse\" : NumberDecimal(\"5\")\n}","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"0.9272952180016122324285124629224288"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-cos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $cos </code> </span> </a> expression to calculate the side adjacent to <code class="leafygreen-ui-1l06pbn"> angle_a </code> and add it to the input document using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> pipeline stage. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trigonometry.aggregate([\n {\n $addFields : {\n \"side_b\" : {\n $multiply : [\n { $cos : \"$angle_a\" },\n \"$hypotenuse\"\n ]\n }\n }\n }\n])","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.trigonometry.aggregate([</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$addFields</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$multiply</span> : [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-variable">$cos</span> : <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$angle_a</span><span class="lg-highlight-string">"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$hypotenuse</span><span class="lg-highlight-string">"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The command returns the following output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"angle_a\" : NumberDecimal(\"0.9272952180016122324285124629224288\"),\n \"side_b\" : NumberDecimal(\"3.000000000000000000000000000000000\"),\n \"hypotenuse\" : NumberDecimal(\"5\"),\n}","programmingLanguage":"Bash"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"0.9272952180016122324285124629224288"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : NumberDecimal(<span class="lg-highlight-string">"3.000000000000000000000000000000000"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Since <code class="leafygreen-ui-1l06pbn"> angle_a </code> and <code class="leafygreen-ui-1l06pbn"> hypotenuse </code> are stored as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self"> <span> 128-bit decimals </span> </a> , the output of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-cos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $cos </code> </span> </a> is a 128-bit decimal. </p> </div> </div> </div> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/built-in-roles/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Built-In Roles in Self-Managed Deployments <a class="headerlink leafygreen-ui-1kepx47" href="#built-in-roles-in-self-managed-deployments" 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="built-in-roles-in-self-managed-deployments"> </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="#mongodb-atlas-built-in-roles" target="_self"> <span> MongoDB Atlas Built-In Roles </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#self-hosted-deployment-built-in-roles" target="_self"> <span> Self-Hosted Deployment Built-In Roles </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#database-user-roles" target="_self"> <span> Database User Roles </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#database-administration-roles" target="_self"> <span> Database Administration Roles </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#cluster-administration-roles" target="_self"> <span> Cluster Administration Roles </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#backup-and-restoration-roles" target="_self"> <span> Backup and Restoration Roles </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#all-database-roles" target="_self"> <span> All-Database Roles </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#superuser-roles" target="_self"> <span> Superuser Roles </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#internal-role" target="_self"> <span> Internal Role </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> MongoDB grants access to data and commands through <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-roles"> role-based authorization </a> and provides built-in roles that provide the different levels of access commonly needed in a database system. You can additionally create <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-user-defined-roles/#std-label-user-defined-roles"> user-defined roles <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> A role grants privileges to perform sets of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#std-label-security-user-actions"> actions </a> on defined <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-document"> resources </a> . A given role applies to the database on which it is defined and can grant access down to a collection level of granularity. </p> <p class="leafygreen-ui-1kp3ins"> <em> System collections </em> include those in: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;database&gt;.system.* </code> namespace </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> local.replset.* </code> replica set namespace </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For details, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#std-label-metadata-system-collections"> System Collections <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> <em> Non-system collections </em> are those not in namespaces in the previous list. </p> <p class="leafygreen-ui-1kp3ins"> Each of MongoDB's built-in roles defines access at the database level for all <em> non </em> -system collections in the role's database and at the collection level for all system collections. </p> <p class="leafygreen-ui-1kp3ins"> This section describes the privileges for each built-in role. You can also view the privileges for a built-in role at any time by issuing the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/rolesInfo/#mongodb-dbcommand-dbcmd.rolesInfo"> <code class="leafygreen-ui-1l06pbn"> rolesInfo </code> </a> command with the <code class="leafygreen-ui-1l06pbn"> showPrivileges </code> and <code class="leafygreen-ui-1l06pbn"> showBuiltinRoles </code> fields both set to <code class="leafygreen-ui-1l06pbn"> true </code> . </p> <p class="leafygreen-ui-1kp3ins"> MongoDB Atlas deployments have different built-in roles than self-hosted deployments. See the following resources to learn more: </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="#std-label-atlas-built-in-roles" target="_self"> <span> MongoDB Atlas Built-In Roles </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-self-hosted-built-in-roles" target="_self"> <span> Self-Hosted Deployment Built-In Roles </span> </a> </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-atlas-built-in-roles"> </span> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> MongoDB Atlas Built-In Roles <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-atlas-built-in-roles" 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="mongodb-atlas-built-in-roles"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> For the built-in database user roles for deployments hosted in MongoDB Atlas, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/mongodb-users-roles-and-privileges/" target="_self"> <span> Altas Built-In Roles and Privileges <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> You can create database users and assign built-in roles in the MongoDB Atlas user interface. To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/security-add-mongodb-users/#add-database-users" target="_self"> <span> Add Database Users <!-- --> . </span> </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-self-hosted-built-in-roles"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Self-Hosted Deployment Built-In Roles <a class="headerlink leafygreen-ui-1kepx47" href="#self-hosted-deployment-built-in-roles" 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="self-hosted-deployment-built-in-roles"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB provides the following built-in roles for self-hosted deployments: </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="#std-label-database-user-roles" target="_self"> <span> Database user </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-database-administration-roles" target="_self"> <span> database administration </span> </a> roles on <em> every </em> database </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> All other roles only on the <code class="leafygreen-ui-1l06pbn"> admin </code> database </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-database-user-roles"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Database User Roles <a class="headerlink leafygreen-ui-1kepx47" href="#database-user-roles" 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="database-user-roles"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Every database includes the following client roles: </p> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> read </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-read" title="Permalink to this definition"> <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="mongodb-authrole-read"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides the ability to read data on all <em> non </em> -system collections and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.js"> <code class="leafygreen-ui-1l06pbn"> system.js </code> </a> 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"> The role does not provide privileges to directly access the <code class="leafygreen-ui-1l06pbn"> system.namespaces </code> collection directly. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> The role provides read access by granting the following <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#std-label-security-user-actions"> actions <!-- --> : </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-changeStream"> <code class="leafygreen-ui-1l06pbn"> changeStream </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbHash"> <code class="leafygreen-ui-1l06pbn"> dbHash </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> listSearchIndexes </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> If the user does not have the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listDatabases"> <code class="leafygreen-ui-1l06pbn"> listDatabases </code> </a> privilege action, users can run the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/listDatabases/#mongodb-dbcommand-dbcmd.listDatabases"> <code class="leafygreen-ui-1l06pbn"> listDatabases </code> </a> command to return a list of databases for which the user has privileges (including databases for which the user has privileges on specific collections) if the command is run with <code class="leafygreen-ui-1l06pbn"> authorizedDatabases </code> option unspecified or set to <code class="leafygreen-ui-1l06pbn"> true </code> . </p> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> readWrite </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-readWrite" title="Permalink to this definition"> <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="mongodb-authrole-readWrite"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides all the privileges of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-read" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> read </code> </span> </a> role plus ability to modify data on all <em> non </em> -system collections and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.js"> <code class="leafygreen-ui-1l06pbn"> system.js </code> </a> collection. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-manual-reference-role-read-write"> </span> <p class="leafygreen-ui-1kp3ins"> The role provides the following actions on those collections: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-changeStream"> <code class="leafygreen-ui-1l06pbn"> changeStream </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-convertToCapped"> <code class="leafygreen-ui-1l06pbn"> convertToCapped </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createCollection"> <code class="leafygreen-ui-1l06pbn"> createCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createIndex"> <code class="leafygreen-ui-1l06pbn"> createIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> createSearchIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbHash"> <code class="leafygreen-ui-1l06pbn"> dbHash </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropCollection"> <code class="leafygreen-ui-1l06pbn"> dropCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropIndex"> <code class="leafygreen-ui-1l06pbn"> dropIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropSearchIndex"> <code class="leafygreen-ui-1l06pbn"> dropSearchIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> listSearchIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-remove"> <code class="leafygreen-ui-1l06pbn"> remove </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-renameCollectionSameDB"> <code class="leafygreen-ui-1l06pbn"> renameCollectionSameDB </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-update"> <code class="leafygreen-ui-1l06pbn"> update </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-updateSearchIndex"> <code class="leafygreen-ui-1l06pbn"> updateSearchIndex </code> </a> </p> </li> </ul> </dd> </dl> <span class="leafygreen-ui-1qnjd6d" id="std-label-database-administration-roles"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Database Administration Roles <a class="headerlink leafygreen-ui-1kepx47" href="#database-administration-roles" 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="database-administration-roles"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Every database includes the following database administration roles: </p> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> dbAdmin </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-dbAdmin" title="Permalink to this definition"> <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="mongodb-authrole-dbAdmin"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides the ability to perform administrative tasks such as schema-related tasks, indexing, and gathering statistics. This role does not grant privileges for user and role management. </p> <p class="leafygreen-ui-1kp3ins"> Specifically, the role provides the following privileges: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:35%"/> <col style="width:65%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Resource </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Permitted Actions </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.profile"> <code class="leafygreen-ui-1l06pbn"> system.profile </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <table class="hlist"> <tbody> <tr> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-changeStream"> <code class="leafygreen-ui-1l06pbn"> changeStream </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-convertToCapped"> <code class="leafygreen-ui-1l06pbn"> convertToCapped </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createCollection"> <code class="leafygreen-ui-1l06pbn"> createCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbHash"> <code class="leafygreen-ui-1l06pbn"> dbHash </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropCollection"> <code class="leafygreen-ui-1l06pbn"> dropCollection </code> </a> </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> listSearchIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheRead"> <code class="leafygreen-ui-1l06pbn"> planCacheRead </code> </a> </p> </li> </ul> </td> </tr> </tbody> </table> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> All <em> non </em> -system collections (i.e. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-specific-db"> database resource <!-- --> ) </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <table class="hlist"> <tbody> <tr> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-bypassDocumentValidation"> <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collMod"> <code class="leafygreen-ui-1l06pbn"> collMod </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-compact"> <code class="leafygreen-ui-1l06pbn"> compact </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-convertToCapped"> <code class="leafygreen-ui-1l06pbn"> convertToCapped </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createCollection"> <code class="leafygreen-ui-1l06pbn"> createCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createIndex"> <code class="leafygreen-ui-1l06pbn"> createIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> createSearchIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropCollection"> <code class="leafygreen-ui-1l06pbn"> dropCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropDatabase"> <code class="leafygreen-ui-1l06pbn"> dropDatabase </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropIndex"> <code class="leafygreen-ui-1l06pbn"> dropIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropSearchIndex"> <code class="leafygreen-ui-1l06pbn"> dropSearchIndex </code> </a> </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-enableProfiler"> <code class="leafygreen-ui-1l06pbn"> enableProfiler </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> listSearchIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheIndexFilter"> <code class="leafygreen-ui-1l06pbn"> planCacheIndexFilter </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheRead"> <code class="leafygreen-ui-1l06pbn"> planCacheRead </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheWrite"> <code class="leafygreen-ui-1l06pbn"> planCacheWrite </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-reIndex"> <code class="leafygreen-ui-1l06pbn"> reIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-renameCollectionSameDB"> <code class="leafygreen-ui-1l06pbn"> renameCollectionSameDB </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-storageDetails"> <code class="leafygreen-ui-1l06pbn"> storageDetails </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-updateSearchIndex"> <code class="leafygreen-ui-1l06pbn"> updateSearchIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-validate"> <code class="leafygreen-ui-1l06pbn"> validate </code> </a> </p> </li> </ul> </td> </tr> </tbody> </table> <p class="leafygreen-ui-1kp3ins"> For these collections, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-dbAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dbAdmin </code> </span> </a> <em> does not </em> include full read access (i.e. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> ). </p> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> dbOwner </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-dbOwner" title="Permalink to this definition"> <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="mongodb-authrole-dbOwner"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The database owner can perform any administrative action on the database. This role combines the privileges granted by the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-readWrite" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> readWrite </code> </span> </a> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-dbAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dbAdmin </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdmin </code> </span> </a> roles. </p> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> userAdmin </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-userAdmin" title="Permalink to this definition"> <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="mongodb-authrole-userAdmin"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides the ability to create and modify roles and users on the current database. Since the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdmin </code> </span> </a> role allows users to grant any privilege to any user, including themselves, the role also indirectly provides <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-superuser" target="_self"> <span> superuser </span> </a> access to either the database or, if scoped to the <code class="leafygreen-ui-1l06pbn"> admin </code> database, the cluster. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdmin </code> </span> </a> role explicitly provides the following actions: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-changeCustomData"> <code class="leafygreen-ui-1l06pbn"> changeCustomData </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-changePassword"> <code class="leafygreen-ui-1l06pbn"> changePassword </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createRole"> <code class="leafygreen-ui-1l06pbn"> createRole </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createUser"> <code class="leafygreen-ui-1l06pbn"> createUser </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropRole"> <code class="leafygreen-ui-1l06pbn"> dropRole </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropUser"> <code class="leafygreen-ui-1l06pbn"> dropUser </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-grantRole"> <code class="leafygreen-ui-1l06pbn"> grantRole </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-revokeRole"> <code class="leafygreen-ui-1l06pbn"> revokeRole </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-setAuthenticationRestriction"> <code class="leafygreen-ui-1l06pbn"> setAuthenticationRestriction </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-viewRole"> <code class="leafygreen-ui-1l06pbn"> viewRole </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-viewUser"> <code class="leafygreen-ui-1l06pbn"> viewUser </code> </a> </p> </li> </ul> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> It is important to understand the security implications of granting the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdmin </code> </span> </a> role: a user with this role for a database can assign themselves any privilege on that database. Granting the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdmin </code> </span> </a> role on the <code class="leafygreen-ui-1l06pbn"> admin </code> database has further security implications as this indirectly provides <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-superuser" target="_self"> <span> superuser </span> </a> access to a cluster. With <code class="leafygreen-ui-1l06pbn"> admin </code> scope a user with the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdmin </code> </span> </a> role can grant cluster-wide roles or privileges including <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdminAnyDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdminAnyDatabase </code> . </span> </a> </p> </div> </div> </dd> </dl> <span class="leafygreen-ui-1qnjd6d" id="std-label-cluster-admin-roles"> </span> <span class="leafygreen-ui-1qnjd6d" id="std-label-admin-roles"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Cluster Administration Roles <a class="headerlink leafygreen-ui-1kepx47" href="#cluster-administration-roles" 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="cluster-administration-roles"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> admin </code> database includes the following roles for administering the whole system rather than just a single database. These roles include but are not limited to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set"> replica set </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster </a> administrative functions. </p> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> clusterAdmin </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-clusterAdmin" title="Permalink to this definition"> <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="mongodb-authrole-clusterAdmin"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides the greatest cluster-management access. This role combines the privileges granted by the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterManager" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterManager </code> </span> </a> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterMonitor" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterMonitor </code> </span> </a> , and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-hostManager" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> hostManager </code> </span> </a> roles. Additionally, the role provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropDatabase"> <code class="leafygreen-ui-1l06pbn"> dropDatabase </code> </a> action. </p> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> clusterManager </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-clusterManager" title="Permalink to this definition"> <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="mongodb-authrole-clusterManager"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides management and monitoring actions on the cluster. A user with this role can access the <code class="leafygreen-ui-1l06pbn"> config </code> and <code class="leafygreen-ui-1l06pbn"> local </code> databases, which are used in sharding and replication, respectively. Additionally, the role provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-querySettings"> <code class="leafygreen-ui-1l06pbn"> querySettings </code> </a> action. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Resource </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Actions </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-cluster"> cluster </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <table class="hlist"> <tbody> <tr> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-addShard"> <code class="leafygreen-ui-1l06pbn"> addShard </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-appendOplogNote"> <code class="leafygreen-ui-1l06pbn"> appendOplogNote </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-applicationMessage"> <code class="leafygreen-ui-1l06pbn"> applicationMessage </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-checkMetadataConsistency"> <code class="leafygreen-ui-1l06pbn"> checkMetadataConsistency </code> </a> (New in version 7.0) </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-cleanupOrphaned"> <code class="leafygreen-ui-1l06pbn"> cleanupOrphaned </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-flushRouterConfig"> <code class="leafygreen-ui-1l06pbn"> flushRouterConfig </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getClusterParameter/#mongodb-dbcommand-dbcmd.getClusterParameter"> <code class="leafygreen-ui-1l06pbn"> getClusterParameter </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-getDefaultRWConcern"> <code class="leafygreen-ui-1l06pbn"> getDefaultRWConcern </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSessions"> <code class="leafygreen-ui-1l06pbn"> listSessions </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listShards"> <code class="leafygreen-ui-1l06pbn"> listShards </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-removeShard"> <code class="leafygreen-ui-1l06pbn"> removeShard </code> </a> </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-replSetConfigure"> <code class="leafygreen-ui-1l06pbn"> replSetConfigure </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-replSetGetConfig"> <code class="leafygreen-ui-1l06pbn"> replSetGetConfig </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-replSetGetStatus"> <code class="leafygreen-ui-1l06pbn"> replSetGetStatus </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-replSetStateChange"> <code class="leafygreen-ui-1l06pbn"> replSetStateChange </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-resync"> <code class="leafygreen-ui-1l06pbn"> resync </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setClusterParameter/#mongodb-dbcommand-dbcmd.setClusterParameter"> <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-setDefaultRWConcern"> <code class="leafygreen-ui-1l06pbn"> setDefaultRWConcern </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-setFeatureCompatibilityVersion"> <code class="leafygreen-ui-1l06pbn"> setFeatureCompatibilityVersion </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-transitionFromDedicatedConfigServer"> <code class="leafygreen-ui-1l06pbn"> transitionFromDedicatedConfigServer </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-transitionToDedicatedConfigServer"> <code class="leafygreen-ui-1l06pbn"> transitionToDedicatedConfigServer </code> </a> </p> </li> </ul> </td> </tr> </tbody> </table> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <em> All </em> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-specific-db"> databases </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <table class="hlist"> <tbody> <tr> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/analyzeShardKey/#mongodb-dbcommand-dbcmd.analyzeShardKey"> <code class="leafygreen-ui-1l06pbn"> analyzeShardKey </code> </a> (New in version 7.0) </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-clearJumboFlag"> <code class="leafygreen-ui-1l06pbn"> clearJumboFlag </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/configureQueryAnalyzer/#mongodb-dbcommand-dbcmd.configureQueryAnalyzer"> <code class="leafygreen-ui-1l06pbn"> configureQueryAnalyzer </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-enableSharding"> <code class="leafygreen-ui-1l06pbn"> enableSharding </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-moveChunk"> <code class="leafygreen-ui-1l06pbn"> moveChunk </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-refineCollectionShardKey"> <code class="leafygreen-ui-1l06pbn"> refineCollectionShardKey </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-reshardCollection"> <code class="leafygreen-ui-1l06pbn"> reshardCollection </code> </a> </p> </li> </ul> </td> </tr> </tbody> </table> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterManager" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterManager </code> </span> </a> provides additional privileges for the <code class="leafygreen-ui-1l06pbn"> config </code> and <code class="leafygreen-ui-1l06pbn"> local </code> databases. </p> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> On the <code class="leafygreen-ui-1l06pbn"> config </code> database, permits the following actions: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:40%"/> <col style="width:60%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Resource </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Actions </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> All non-system collections in the <code class="leafygreen-ui-1l06pbn"> config </code> database </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <table class="hlist"> <tbody> <tr> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbHash"> <code class="leafygreen-ui-1l06pbn"> dbHash </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-enableSharding"> <code class="leafygreen-ui-1l06pbn"> enableSharding </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> listSearchIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-moveChunk"> <code class="leafygreen-ui-1l06pbn"> moveChunk </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheRead"> <code class="leafygreen-ui-1l06pbn"> planCacheRead </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-remove"> <code class="leafygreen-ui-1l06pbn"> remove </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-update"> <code class="leafygreen-ui-1l06pbn"> update </code> </a> </p> </li> </ul> </td> </tr> </tbody> </table> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.js"> <code class="leafygreen-ui-1l06pbn"> system.js </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <table class="hlist"> <tbody> <tr> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbHash"> <code class="leafygreen-ui-1l06pbn"> dbHash </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> listSearchIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheRead"> <code class="leafygreen-ui-1l06pbn"> planCacheRead </code> </a> </p> </li> </ul> </td> </tr> </tbody> </table> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> On the <code class="leafygreen-ui-1l06pbn"> local </code> database, permits the following actions: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:40%"/> <col style="width:60%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Resource </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Actions </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> All non-system collections in the <code class="leafygreen-ui-1l06pbn"> local </code> database </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <table class="hlist"> <tbody> <tr> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-enableSharding"> <code class="leafygreen-ui-1l06pbn"> enableSharding </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-moveChunk"> <code class="leafygreen-ui-1l06pbn"> moveChunk </code> </a> </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-remove"> <code class="leafygreen-ui-1l06pbn"> remove </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-update"> <code class="leafygreen-ui-1l06pbn"> update </code> </a> </p> </li> </ul> </td> </tr> </tbody> </table> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/local-database/#mongodb-data-local.system.replset"> <code class="leafygreen-ui-1l06pbn"> system.replset </code> </a> collection </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <table class="hlist"> <tbody> <tr> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbHash"> <code class="leafygreen-ui-1l06pbn"> dbHash </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> listSearchIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheRead"> <code class="leafygreen-ui-1l06pbn"> planCacheRead </code> </a> </p> </li> </ul> </td> </tr> </tbody> </table> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> clusterMonitor </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-clusterMonitor" title="Permalink to this definition"> <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="mongodb-authrole-clusterMonitor"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides read-only access to monitoring tools, such as the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://cloud.mongodb.com/?tck=docs_server" target="_self"> <span> MongoDB Cloud Manager </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/ops-manager/current/" target="_self"> <span> Ops Manager </span> </a> monitoring agent. </p> <p class="leafygreen-ui-1kp3ins"> Permits the following actions on the cluster as a whole: </p> <table class="hlist"> <tbody> <tr> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-connPoolStats"> <code class="leafygreen-ui-1l06pbn"> connPoolStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-getCmdLineOpts"> <code class="leafygreen-ui-1l06pbn"> getCmdLineOpts </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-getDefaultRWConcern"> <code class="leafygreen-ui-1l06pbn"> getDefaultRWConcern </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-getLog"> <code class="leafygreen-ui-1l06pbn"> getLog </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-getParameter"> <code class="leafygreen-ui-1l06pbn"> getParameter </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-getShardMap"> <code class="leafygreen-ui-1l06pbn"> getShardMap </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-hostInfo"> <code class="leafygreen-ui-1l06pbn"> hostInfo </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-inprog"> <code class="leafygreen-ui-1l06pbn"> inprog </code> </a> </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listDatabases"> <code class="leafygreen-ui-1l06pbn"> listDatabases </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSessions"> <code class="leafygreen-ui-1l06pbn"> listSessions </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listShards"> <code class="leafygreen-ui-1l06pbn"> listShards </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-replSetGetConfig"> <code class="leafygreen-ui-1l06pbn"> replSetGetConfig </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-replSetGetStatus"> <code class="leafygreen-ui-1l06pbn"> replSetGetStatus </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-serverStatus"> <code class="leafygreen-ui-1l06pbn"> serverStatus </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-shardingState"> <code class="leafygreen-ui-1l06pbn"> shardingState </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-top"> <code class="leafygreen-ui-1l06pbn"> top </code> </a> </p> </li> </ul> </td> </tr> </tbody> </table> <p class="leafygreen-ui-1kp3ins"> Permits the following actions on <em> all </em> databases in the cluster: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-indexStats"> <code class="leafygreen-ui-1l06pbn"> indexStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-useUUID"> <code class="leafygreen-ui-1l06pbn"> useUUID </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Permits the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> action on all <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.profile"> <code class="leafygreen-ui-1l06pbn"> system.profile </code> </a> collections in the cluster. </p> <p class="leafygreen-ui-1kp3ins"> On the <code class="leafygreen-ui-1l06pbn"> config </code> database, permits the following actions: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:40%"/> <col style="width:60%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Resource </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Actions </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> All non-system collections in the <code class="leafygreen-ui-1l06pbn"> config </code> database </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbHash"> <code class="leafygreen-ui-1l06pbn"> dbHash </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-indexStats"> <code class="leafygreen-ui-1l06pbn"> indexStats </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> listSearchIndexes </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheRead"> <code class="leafygreen-ui-1l06pbn"> planCacheRead </code> </a> </div> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.js"> <code class="leafygreen-ui-1l06pbn"> system.js </code> </a> collection </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbHash"> <code class="leafygreen-ui-1l06pbn"> dbHash </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheRead"> <code class="leafygreen-ui-1l06pbn"> planCacheRead </code> </a> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> On the <code class="leafygreen-ui-1l06pbn"> local </code> database, permits the following actions: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Resource </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Actions </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> All non-system collections in the <code class="leafygreen-ui-1l06pbn"> local </code> database </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbHash"> <code class="leafygreen-ui-1l06pbn"> dbHash </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-indexStats"> <code class="leafygreen-ui-1l06pbn"> indexStats </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> listSearchIndexes </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheRead"> <code class="leafygreen-ui-1l06pbn"> planCacheRead </code> </a> </div> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.js"> <code class="leafygreen-ui-1l06pbn"> system.js </code> </a> collection </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbHash"> <code class="leafygreen-ui-1l06pbn"> dbHash </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> listSearchIndexes </code> </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheRead"> <code class="leafygreen-ui-1l06pbn"> planCacheRead </code> </a> </div> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/local-database/#mongodb-data-local.system.replset"> <code class="leafygreen-ui-1l06pbn"> system.replset </code> </a> , </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.profile"> <code class="leafygreen-ui-1l06pbn"> system.profile </code> </a> , </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> directShardOperations </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-directShardOperations" title="Permalink to this definition"> <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="mongodb-authrole-directShardOperations"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 8.0, you can use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-directShardOperations" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> directShardOperations </code> </span> </a> role to perform maintenance operations that require you to execute commands directly against a shard. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Running commands using the <code class="leafygreen-ui-1l06pbn"> directShardOperations </code> role can cause your cluster to stop working correctly and may cause data corruption. Only use the <code class="leafygreen-ui-1l06pbn"> directShardOperations </code> role for maintenance purposes or under the guidance of MongoDB support. Once you are done performing maintenance operations, stop using the <code class="leafygreen-ui-1l06pbn"> directShardOperations </code> role. </p> </div> </div> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> enableSharding </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-enableSharding" title="Permalink to this definition"> <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="mongodb-authrole-enableSharding"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides the ability to enable sharding for a collection and modify existing shard keys. </p> <p class="leafygreen-ui-1kp3ins"> Provides the following actions on all non-system collections: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-enableSharding"> <code class="leafygreen-ui-1l06pbn"> enableSharding </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-refineCollectionShardKey"> <code class="leafygreen-ui-1l06pbn"> refineCollectionShardKey </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-reshardCollection"> <code class="leafygreen-ui-1l06pbn"> reshardCollection </code> </a> </p> </li> </ul> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> hostManager </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-hostManager" title="Permalink to this definition"> <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="mongodb-authrole-hostManager"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides the ability to monitor and manage servers. </p> <p class="leafygreen-ui-1kp3ins"> On the cluster as a whole, provides the following actions: </p> <table class="hlist"> <tbody> <tr> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-applicationMessage"> <code class="leafygreen-ui-1l06pbn"> applicationMessage </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-closeAllDatabases"> <code class="leafygreen-ui-1l06pbn"> closeAllDatabases </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-compact"> <code class="leafygreen-ui-1l06pbn"> compact </code> </a> (New in version 7.3) </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-connPoolSync"> <code class="leafygreen-ui-1l06pbn"> connPoolSync </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-flushRouterConfig"> <code class="leafygreen-ui-1l06pbn"> flushRouterConfig </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-fsync"> <code class="leafygreen-ui-1l06pbn"> fsync </code> </a> </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-invalidateUserCache"> <code class="leafygreen-ui-1l06pbn"> invalidateUserCache </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killAnyCursor"> <code class="leafygreen-ui-1l06pbn"> killAnyCursor </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killAnySession"> <code class="leafygreen-ui-1l06pbn"> killAnySession </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killop"> <code class="leafygreen-ui-1l06pbn"> killop </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-logRotate"> <code class="leafygreen-ui-1l06pbn"> logRotate </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-oidReset"> <code class="leafygreen-ui-1l06pbn"> oidReset </code> </a> </p> </li> </ul> </td> <td> <ul class="simple"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-resync"> <code class="leafygreen-ui-1l06pbn"> resync </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-rotateCertificates"> <code class="leafygreen-ui-1l06pbn"> rotateCertificates </code> </a> (New in version 5.0) </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-setParameter"> <code class="leafygreen-ui-1l06pbn"> setParameter </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-shutdown"> <code class="leafygreen-ui-1l06pbn"> shutdown </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-touch"> <code class="leafygreen-ui-1l06pbn"> touch </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-unlock"> <code class="leafygreen-ui-1l06pbn"> unlock </code> </a> </p> </li> </ul> </td> </tr> </tbody> </table> <p class="leafygreen-ui-1kp3ins"> On <em> all </em> databases in the cluster, provides the following actions: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </p> </li> </ul> </dd> </dl> <span class="leafygreen-ui-1qnjd6d" id="std-label-backup-and-restore-roles"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Backup and Restoration Roles <a class="headerlink leafygreen-ui-1kepx47" href="#backup-and-restoration-roles" 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="backup-and-restoration-roles"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> admin </code> database includes the following roles for backing up and restoring data: </p> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> backup </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-backup" title="Permalink to this definition"> <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="mongodb-authrole-backup"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides minimal privileges needed for backing up data. This role provides sufficient privileges to use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://cloud.mongodb.com/?tck=docs_server" target="_self"> <span> MongoDB Cloud Manager </span> </a> backup agent, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/ops-manager/current/" target="_self"> <span> Ops Manager </span> </a> backup agent, or to use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongodump/#mongodb-binary-bin.mongodump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongodump </code> </span> </a> to back up an entire <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instance. </p> <p class="leafygreen-ui-1kp3ins"> Provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-update"> <code class="leafygreen-ui-1l06pbn"> update </code> </a> actions on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/config-database/#mongodb-data-config.settings"> <code class="leafygreen-ui-1l06pbn"> settings </code> </a> collection in the <code class="leafygreen-ui-1l06pbn"> config </code> database. </p> <p class="leafygreen-ui-1kp3ins"> On <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-anyResource"> <code class="leafygreen-ui-1l06pbn"> anyResource </code> </a> , provides the </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listDatabases"> <code class="leafygreen-ui-1l06pbn"> listDatabases </code> </a> action </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> action </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listIndexes"> <code class="leafygreen-ui-1l06pbn"> listIndexes </code> </a> action </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> listSearchIndexes </code> </a> action </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> On the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-cluster"> cluster </a> as a whole, provides the </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-appendOplogNote"> <code class="leafygreen-ui-1l06pbn"> appendOplogNote </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-getParameter"> <code class="leafygreen-ui-1l06pbn"> getParameter </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listDatabases"> <code class="leafygreen-ui-1l06pbn"> listDatabases </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-serverStatus"> <code class="leafygreen-ui-1l06pbn"> serverStatus </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-setUserWriteBlockMode"> <code class="leafygreen-ui-1l06pbn"> setUserWriteBlockMode </code> </a> (Starting in MongoDB 6.0) </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> action on the following: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> all <em> non </em> -system collections in the cluster, including those in the <code class="leafygreen-ui-1l06pbn"> config </code> and <code class="leafygreen-ui-1l06pbn"> local </code> databases </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The following system collections in the cluster: </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.js"> <code class="leafygreen-ui-1l06pbn"> system.js </code> </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.profile"> <code class="leafygreen-ui-1l06pbn"> system.profile </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data-admin.system.users"> <code class="leafygreen-ui-1l06pbn"> admin.system.users </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data-admin.system.roles"> <code class="leafygreen-ui-1l06pbn"> admin.system.roles </code> </a> collections </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/config-database/#mongodb-data-config.settings"> <code class="leafygreen-ui-1l06pbn"> config.settings </code> </a> collection </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Legacy <code class="leafygreen-ui-1l06pbn"> system.users </code> collections from versions of MongoDB prior to 2.6 </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-update"> <code class="leafygreen-ui-1l06pbn"> update </code> </a> actions on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/config-database/#mongodb-data-config.settings"> <code class="leafygreen-ui-1l06pbn"> config.settings </code> </a> collection. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-backup" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> backup </code> </span> </a> role provides additional privileges to back up the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.profile"> <code class="leafygreen-ui-1l06pbn"> system.profile </code> </a> collection that exists when running with <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-the-database-profiler/#std-label-database-profiling"> database profiling <!-- --> . </a> </p> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> restore </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-restore" title="Permalink to this definition"> <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="mongodb-authrole-restore"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-convertToCapped"> <code class="leafygreen-ui-1l06pbn"> convertToCapped </code> </a> on non-system collections. </p> <p class="leafygreen-ui-1kp3ins"> Provides the necessary privileges to restore data from backups <em> if </em> the data does not include <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.profile"> <code class="leafygreen-ui-1l06pbn"> system.profile </code> </a> collection data and you run <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongorestore </code> </span> </a> without the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#std-option-mongorestore.--oplogReplay" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --oplogReplay </code> </span> </a> option. </p> <p class="leafygreen-ui-1kp3ins"> If the backup data includes <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.profile"> <code class="leafygreen-ui-1l06pbn"> system.profile </code> </a> collection data or you run with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#std-option-mongorestore.--oplogReplay" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --oplogReplay </code> </span> </a> , you need additional privileges: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> system.profile </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> If the backup data includes <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.profile"> <code class="leafygreen-ui-1l06pbn"> system.profile </code> </a> collection data and the target database does not contain the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.profile"> <code class="leafygreen-ui-1l06pbn"> system.profile </code> </a> collection, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongorestore </code> </span> </a> attempts to create the collection even though the program does not actually restore <code class="leafygreen-ui-1l06pbn"> system.profile </code> documents. As such, the user requires additional privileges to perform <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createCollection"> <code class="leafygreen-ui-1l06pbn"> createCollection </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-convertToCapped"> <code class="leafygreen-ui-1l06pbn"> convertToCapped </code> </a> actions on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.profile"> <code class="leafygreen-ui-1l06pbn"> system.profile </code> </a> collection for a database. </p> <p class="leafygreen-ui-1kp3ins"> Both the built-in roles <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-dbAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dbAdmin </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-dbAdminAnyDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dbAdminAnyDatabase </code> </span> </a> provide the additional privileges. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> --oplogReplay </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> To run with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#std-option-mongorestore.--oplogReplay" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --oplogReplay </code> </span> </a> , create a <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-users-and-roles/#std-label-create-user-defined-role"> user-defined role </a> that has <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-anyAction"> <code class="leafygreen-ui-1l06pbn"> anyAction </code> </a> on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-anyresource"> <code class="leafygreen-ui-1l06pbn"> anyResource </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Grant only to users who must run <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongorestore </code> </span> </a> with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#std-option-mongorestore.--oplogReplay" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --oplogReplay </code> . </span> </a> </p> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Provides the following action on the cluster as a whole: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-getParameter"> <code class="leafygreen-ui-1l06pbn"> getParameter </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Provides the following actions on all <em> non </em> -system collections: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-bypassDocumentValidation"> <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-changeCustomData"> <code class="leafygreen-ui-1l06pbn"> changeCustomData </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-changePassword"> <code class="leafygreen-ui-1l06pbn"> changePassword </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collMod"> <code class="leafygreen-ui-1l06pbn"> collMod </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-convertToCapped"> <code class="leafygreen-ui-1l06pbn"> convertToCapped </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createCollection"> <code class="leafygreen-ui-1l06pbn"> createCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createIndex"> <code class="leafygreen-ui-1l06pbn"> createIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createRole"> <code class="leafygreen-ui-1l06pbn"> createRole </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> createSearchIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createUser"> <code class="leafygreen-ui-1l06pbn"> createUser </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropCollection"> <code class="leafygreen-ui-1l06pbn"> dropCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropRole"> <code class="leafygreen-ui-1l06pbn"> dropRole </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropUser"> <code class="leafygreen-ui-1l06pbn"> dropUser </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-grantRole"> <code class="leafygreen-ui-1l06pbn"> grantRole </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-revokeRole"> <code class="leafygreen-ui-1l06pbn"> revokeRole </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-updateSearchIndex"> <code class="leafygreen-ui-1l06pbn"> updateSearchIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-viewRole"> <code class="leafygreen-ui-1l06pbn"> viewRole </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-viewUser"> <code class="leafygreen-ui-1l06pbn"> viewUser </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Provides the following actions on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.js"> <code class="leafygreen-ui-1l06pbn"> system.js </code> </a> collection: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-bypassDocumentValidation"> <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collMod"> <code class="leafygreen-ui-1l06pbn"> collMod </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createCollection"> <code class="leafygreen-ui-1l06pbn"> createCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createIndex"> <code class="leafygreen-ui-1l06pbn"> createIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropCollection"> <code class="leafygreen-ui-1l06pbn"> dropCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-updateSearchIndex"> <code class="leafygreen-ui-1l06pbn"> updateSearchIndex </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Provides the following action on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-anyResource"> <code class="leafygreen-ui-1l06pbn"> anyResource </code> : </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listCollections"> <code class="leafygreen-ui-1l06pbn"> listCollections </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Provides the following actions on all non-system collections on the <code class="leafygreen-ui-1l06pbn"> config </code> and the <code class="leafygreen-ui-1l06pbn"> local </code> databases: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-bypassDocumentValidation"> <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collMod"> <code class="leafygreen-ui-1l06pbn"> collMod </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createCollection"> <code class="leafygreen-ui-1l06pbn"> createCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createIndex"> <code class="leafygreen-ui-1l06pbn"> createIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropCollection"> <code class="leafygreen-ui-1l06pbn"> dropCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-updateSearchIndex"> <code class="leafygreen-ui-1l06pbn"> updateSearchIndex </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Provides the following actions on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data-admin.system.version"> <code class="leafygreen-ui-1l06pbn"> admin.system.version </code> </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-bypassDocumentValidation"> <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collMod"> <code class="leafygreen-ui-1l06pbn"> collMod </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createCollection"> <code class="leafygreen-ui-1l06pbn"> createCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createIndex"> <code class="leafygreen-ui-1l06pbn"> createIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropCollection"> <code class="leafygreen-ui-1l06pbn"> dropCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-updateSearchIndex"> <code class="leafygreen-ui-1l06pbn"> updateSearchIndex </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Provides the following action on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data-admin.system.roles"> <code class="leafygreen-ui-1l06pbn"> admin.system.roles </code> </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createIndex"> <code class="leafygreen-ui-1l06pbn"> createIndex </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Provides the following actions on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data-admin.system.users"> <code class="leafygreen-ui-1l06pbn"> admin.system.users </code> </a> and legacy <code class="leafygreen-ui-1l06pbn"> system.users </code> collections: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-bypassDocumentValidation"> <code class="leafygreen-ui-1l06pbn"> bypassDocumentValidation </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collMod"> <code class="leafygreen-ui-1l06pbn"> collMod </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createCollection"> <code class="leafygreen-ui-1l06pbn"> createCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createIndex"> <code class="leafygreen-ui-1l06pbn"> createIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropCollection"> <code class="leafygreen-ui-1l06pbn"> dropCollection </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-insert"> <code class="leafygreen-ui-1l06pbn"> insert </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-remove"> <code class="leafygreen-ui-1l06pbn"> remove </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-update"> <code class="leafygreen-ui-1l06pbn"> update </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-updateSearchIndex"> <code class="leafygreen-ui-1l06pbn"> updateSearchIndex </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Although, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-restore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> restore </code> </span> </a> includes the ability to modify the documents in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data-admin.system.users"> <code class="leafygreen-ui-1l06pbn"> admin.system.users </code> </a> collection using normal modification operations, <em> only </em> modify these data using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/#std-label-user-management-methods"> user management methods <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Provides the following action on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data--database-.system.views"> <code class="leafygreen-ui-1l06pbn"> &lt;database&gt;.system.views </code> </a> collection: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropCollection"> <code class="leafygreen-ui-1l06pbn"> dropCollection </code> </a> (Starting in MongoDB 7.2) </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> On the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-cluster"> cluster </a> as a whole, provides the following actions: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-bypassWriteBlockingMode"> <code class="leafygreen-ui-1l06pbn"> bypassWriteBlockingMode </code> </a> (Staring in MongoDB 6.0) </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-setUserWriteBlockMode"> <code class="leafygreen-ui-1l06pbn"> setUserWriteBlockMode </code> </a> (Starting in MongoDB 6.0) </p> </li> </ul> </dd> </dl> <span class="leafygreen-ui-1qnjd6d" id="std-label-auth-any-database-roles"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> All-Database Roles <a class="headerlink leafygreen-ui-1kepx47" href="#all-database-roles" 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="all-database-roles"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following roles are available on the <code class="leafygreen-ui-1l06pbn"> admin </code> database and provide privileges which apply to all databases except <code class="leafygreen-ui-1l06pbn"> local </code> and <code class="leafygreen-ui-1l06pbn"> config </code> : </p> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> readAnyDatabase </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-readAnyDatabase" title="Permalink to this definition"> <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="mongodb-authrole-readAnyDatabase"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides the same read-only privileges as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-read" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> read </code> </span> </a> on all databases except <code class="leafygreen-ui-1l06pbn"> local </code> and <code class="leafygreen-ui-1l06pbn"> config </code> . The role also provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listDatabases"> <code class="leafygreen-ui-1l06pbn"> listDatabases </code> </a> action on the cluster as a whole. </p> <p class="leafygreen-ui-1kp3ins"> See also the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterManager" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterManager </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterMonitor" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterMonitor </code> </span> </a> roles for access to the <code class="leafygreen-ui-1l06pbn"> config </code> and <code class="leafygreen-ui-1l06pbn"> local </code> databases. </p> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> readWriteAnyDatabase </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-readWriteAnyDatabase" title="Permalink to this definition"> <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="mongodb-authrole-readWriteAnyDatabase"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides the same privileges as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-readWrite" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> readWrite </code> </span> </a> on all databases except <code class="leafygreen-ui-1l06pbn"> local </code> and <code class="leafygreen-ui-1l06pbn"> config </code> . The role also provides: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listDatabases"> <code class="leafygreen-ui-1l06pbn"> listDatabases </code> </a> action on the cluster as a whole </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-compactStructuredEncryptionData"> <code class="leafygreen-ui-1l06pbn"> compactStructuredEncryptionData </code> </a> action </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> See also the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterManager" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterManager </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterMonitor" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterMonitor </code> </span> </a> roles for access to the <code class="leafygreen-ui-1l06pbn"> config </code> and <code class="leafygreen-ui-1l06pbn"> local </code> databases. </p> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> userAdminAnyDatabase </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-userAdminAnyDatabase" title="Permalink to this definition"> <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="mongodb-authrole-userAdminAnyDatabase"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides the same access to user administration operations as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdmin </code> </span> </a> on all databases except <code class="leafygreen-ui-1l06pbn"> local </code> and <code class="leafygreen-ui-1l06pbn"> config </code> . </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdminAnyDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdminAnyDatabase </code> </span> </a> also provides the following privilege actions on the cluster: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-authSchemaUpgrade"> <code class="leafygreen-ui-1l06pbn"> authSchemaUpgrade </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-invalidateUserCache"> <code class="leafygreen-ui-1l06pbn"> invalidateUserCache </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listDatabases"> <code class="leafygreen-ui-1l06pbn"> listDatabases </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The role provides the following privilege actions on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data-admin.system.users"> <code class="leafygreen-ui-1l06pbn"> system.users </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#mongodb-data-admin.system.roles"> <code class="leafygreen-ui-1l06pbn"> system.roles </code> </a> collections on the <code class="leafygreen-ui-1l06pbn"> admin </code> database, and on legacy <code class="leafygreen-ui-1l06pbn"> system.users </code> collections from versions of MongoDB prior to 2.6: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-collStats"> <code class="leafygreen-ui-1l06pbn"> collStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createIndex"> <code class="leafygreen-ui-1l06pbn"> createIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-createSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> createSearchIndexes </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbHash"> <code class="leafygreen-ui-1l06pbn"> dbHash </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dbStats"> <code class="leafygreen-ui-1l06pbn"> dbStats </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropIndex"> <code class="leafygreen-ui-1l06pbn"> dropIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropSearchIndex"> <code class="leafygreen-ui-1l06pbn"> dropSearchIndex </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-killCursors"> <code class="leafygreen-ui-1l06pbn"> killCursors </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheRead"> <code class="leafygreen-ui-1l06pbn"> planCacheRead </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdminAnyDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdminAnyDatabase </code> </span> </a> role does not restrict the privileges that a user can grant. As a result, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdminAnyDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdminAnyDatabase </code> </span> </a> users can grant themselves privileges in excess of their current privileges and even can grant themselves <em> all privileges </em> , even though the role does not explicitly authorize privileges beyond user administration. This role is effectively a MongoDB system <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-superuser" target="_self"> <span> superuser <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> See also the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterManager" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterManager </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterMonitor" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterMonitor </code> </span> </a> roles for access to the <code class="leafygreen-ui-1l06pbn"> config </code> and <code class="leafygreen-ui-1l06pbn"> local </code> databases. </p> </dd> </dl> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> dbAdminAnyDatabase </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-dbAdminAnyDatabase" title="Permalink to this definition"> <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="mongodb-authrole-dbAdminAnyDatabase"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides the same privileges as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-dbAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dbAdmin </code> </span> </a> on all databases except <code class="leafygreen-ui-1l06pbn"> local </code> and <code class="leafygreen-ui-1l06pbn"> config </code> . The role also provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-listDatabases"> <code class="leafygreen-ui-1l06pbn"> listDatabases </code> </a> action on the cluster as a whole. </p> <p class="leafygreen-ui-1kp3ins"> See also the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterManager" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterManager </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterMonitor" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterMonitor </code> </span> </a> roles for access to the <code class="leafygreen-ui-1l06pbn"> config </code> and <code class="leafygreen-ui-1l06pbn"> local </code> databases. </p> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-dbAdminAnyDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dbAdminAnyDatabase </code> </span> </a> includes the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#std-label-internal-actions"> applyOps </a> privilege action. </p> </dd> </dl> <span class="leafygreen-ui-1qnjd6d" id="std-label-superuser"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Superuser Roles <a class="headerlink leafygreen-ui-1kepx47" href="#superuser-roles" 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="superuser-roles"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Several roles provide either indirect or direct system-wide superuser access. </p> <p class="leafygreen-ui-1kp3ins"> The following roles provide the ability to assign any user any privilege on any database, which means that users with one of these roles can assign <em> themselves </em> any privilege on any database: </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="#mongodb-authrole-dbOwner" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dbOwner </code> </span> </a> role, when scoped to the <code class="leafygreen-ui-1l06pbn"> admin </code> database </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdmin </code> </span> </a> role, when scoped to the <code class="leafygreen-ui-1l06pbn"> admin </code> database </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdminAnyDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdminAnyDatabase </code> </span> </a> role </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The following role provides full privileges on all resources: </p> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> root </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-root" title="Permalink to this definition"> <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="mongodb-authrole-root"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Provides access to the operations and all the resources of the following roles <em> combined </em> : </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="#mongodb-authrole-readWriteAnyDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> readWriteAnyDatabase </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-dbAdminAnyDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dbAdminAnyDatabase </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-userAdminAnyDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> userAdminAnyDatabase </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-clusterAdmin" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> clusterAdmin </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-restore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> restore </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-authrole-backup" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> backup </code> </span> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Also provides the following privilege actions: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-validate"> <code class="leafygreen-ui-1l06pbn"> validate </code> </a> on <code class="leafygreen-ui-1l06pbn"> system. </code> collections. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-bypassDefaultMaxTimeMS"> <code class="leafygreen-ui-1l06pbn"> bypassDefaultMaxTimeMS </code> </a> , which causes all queries run by the user to ignore the value of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/cluster-parameters/defaultMaxTimeMS/#mongodb-parameter-param.defaultMaxTimeMS"> <code class="leafygreen-ui-1l06pbn"> defaultMaxTimeMS </code> . </a> </p> </li> </ul> <div> <p> <em> Changed <!-- --> in version <!-- --> 6.0 </em> : <!-- --> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-root"> <code class="leafygreen-ui-1l06pbn"> root </code> </a> role includes <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-remove"> <code class="leafygreen-ui-1l06pbn"> remove </code> </a> privileges on the <code class="leafygreen-ui-1l06pbn"> system.preimages </code> collection in the <code class="leafygreen-ui-1l06pbn"> config </code> database. </p> </div> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Internal Role <a class="headerlink leafygreen-ui-1kepx47" href="#internal-role" 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="internal-role"> </div> </a> </h3> <dl class="authrole"> <dt> <code class="leafygreen-ui-1l06pbn"> __system </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-authrole-__system" title="Permalink to this definition"> <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="mongodb-authrole-__system"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> MongoDB assigns this role to user objects that represent cluster members, such as replica set members and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instances. The role entitles its holder to take any action against any object in the database. </p> <p class="leafygreen-ui-1kp3ins"> <strong> Do not </strong> assign this role to user objects representing applications or human administrators, other than in exceptional circumstances. </p> <p class="leafygreen-ui-1kp3ins"> If you need access to all actions on all resources, for example to run <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/applyOps/#mongodb-dbcommand-dbcmd.applyOps"> <code class="leafygreen-ui-1l06pbn"> applyOps </code> </a> commands, do not assign this role. Instead, <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-users-and-roles/#std-label-create-user-defined-role"> create a user-defined role </a> that grants <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-anyAction"> <code class="leafygreen-ui-1l06pbn"> anyAction </code> </a> on <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-anyresource"> <code class="leafygreen-ui-1l06pbn"> anyResource </code> </a> and ensure that only the users who need access to these operations have this access. </p> </dd> </dl> </section> </section> </section>
https://www.mongodb.com/docs/manual/core/security-user-defined-roles/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> User-Defined Roles on Self-Managed Deployments <a class="headerlink leafygreen-ui-1kepx47" href="#user-defined-roles-on-self-managed-deployments" 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="user-defined-roles-on-self-managed-deployments"> </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="#role-management-interface" target="_self"> <span> Role Management Interface </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#scope" target="_self"> <span> Scope </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#centralized-role-data" target="_self"> <span> Centralized Role Data </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> MongoDB provides a number of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/"> built-in roles </a> . However, if these roles cannot describe the desired set of privileges, you can create new roles. </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"> You can configure custom database roles in the UI for deployments hosted in MongoDB Atlas. To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/security-add-mongodb-roles/" target="_self"> <span> Configure Custom Database Roles <!-- --> . </span> </a> </p> </div> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Role Management Interface <a class="headerlink leafygreen-ui-1kepx47" href="#role-management-interface" 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="role-management-interface"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To add a role, MongoDB provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.createRole/#mongodb-method-db.createRole"> <code class="leafygreen-ui-1l06pbn"> db.createRole() </code> </a> method. MongoDB also provides methods to update existing user-defined roles. For a full list of role management methods, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/#std-label-role-management-methods"> Role Management <!-- --> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Scope <a class="headerlink leafygreen-ui-1kepx47" href="#scope" 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="scope"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> When adding a role, you create the role in a specific database. MongoDB uses the combination of the database and the role name to uniquely define a role. </p> <p class="leafygreen-ui-1kp3ins"> Except for roles created in the <code class="leafygreen-ui-1l06pbn"> admin </code> database, a role can only include privileges that apply to its database and can only inherit from other roles in its database. </p> <p class="leafygreen-ui-1kp3ins"> A role created in the <code class="leafygreen-ui-1l06pbn"> admin </code> database can include privileges that apply to the <code class="leafygreen-ui-1l06pbn"> admin </code> database, other databases or to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-cluster"> cluster </a> resource, and can inherit from roles in other databases as well as the <code class="leafygreen-ui-1l06pbn"> admin </code> database. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Centralized Role Data <a class="headerlink leafygreen-ui-1kepx47" href="#centralized-role-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="centralized-role-data"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB stores all role information in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-roles-collection/"> system.roles </a> collection in the <code class="leafygreen-ui-1l06pbn"> admin </code> database </p> <p class="leafygreen-ui-1kp3ins"> Do not access this collection directly but instead use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/#std-label-role-management-commands"> role management commands </a> to view and edit custom roles. </p> </section> </section>
https://www.mongodb.com/docs/manual/tutorial/enable-authentication/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Enable Access Control on Self-Managed Deployments <a class="headerlink leafygreen-ui-1kepx47" href="#enable-access-control-on-self-managed-deployments" 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="enable-access-control-on-self-managed-deployments"> </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="#access-control-resources" target="_self"> <span> Access Control Resources </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#next-steps" target="_self"> <span> Next Steps </span> </a> </li> </ul> </div> <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, LDAP authentication and authorization is deprecated. LDAP is available and will continue to operate without changes throughout the lifetime of MongoDB 8. LDAP will be removed in a future major release. </p> <p class="leafygreen-ui-1kp3ins"> For details, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/LDAP-deprecation/#std-label-ldap-deprecation"> LDAP Deprecation. </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Enabling access control on a MongoDB deployment enforces authentication. With access control enabled, users are required to identify themselves and can only perform actions that adhere to the permissions granted by the roles assigned to their user. </p> <a class="css-53dzkk" href="https://www.mongodb.com/docs/atlas/atlas-ui-authentication/"> <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-authentication/" target="_self"> <span> configure authentication 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> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> You can't disable access control in MongoDB Atlas. </p> </div> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Access Control Resources <a class="headerlink leafygreen-ui-1kepx47" href="#access-control-resources" 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="access-control-resources"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> If you would like to enable access control for a standalone MongoDB instance, please refer to one of the following resources: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-scram-client-authentication/"> Use SCRAM to Authenticate Clients on Self-Managed Deployments </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-x509-client-authentication/"> Use x.509 Certificates to Authenticate Clients on Self-Managed Deployments </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/control-access-to-mongodb-with-kerberos-authentication/"> Configure Self-Managed MongoDB with Kerberos Authentication on Linux </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/control-access-to-mongodb-windows-with-kerberos-authentication/"> Configure Self-Managed MongoDB with Kerberos Authentication on Windows </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/kerberos-auth-activedirectory-authz/"> Configure Self-Managed MongoDB with Kerberos Authentication and Active Directory Authorization </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ldap-sasl-activedirectory/"> Authenticate Using Self-Managed SASL and LDAP with ActiveDirectory </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ldap-sasl-openldap/"> Authenticate Using Self-Managed SASL and LDAP with OpenLDAP </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/authenticate-nativeldap-activedirectory/"> Authenticate and Authorize Users Using Self-Managed Active Directory with Native LDAP </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-oidc/"> Configure Self-Managed MongoDB with OpenID Connect </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> If you would like to enable access control for a <a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/"> replica set </a> or a <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/#std-label-sharding-sharded-cluster"> sharded cluster </a> , please refer to one of the following resources: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/deploy-replica-set-with-keyfile-access-control/"> Deploy Self-Managed Replica Set With Keyfile Authentication </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/enforce-keyfile-access-control-in-existing-replica-set/"> Update Self-Managed Replica Set to Keyfile Authentication </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/enforce-keyfile-access-control-in-existing-replica-set-without-downtime/"> Update Self-Managed Replica Set to Keyfile Authentication (No Downtime) </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/deploy-sharded-cluster-with-keyfile-access-control/"> Deploy Self-Managed Sharded Cluster with Keyfile Authentication </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/enforce-keyfile-access-control-in-existing-sharded-cluster/"> Update Self-Managed Sharded Cluster to Keyfile Authentication </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/enforce-keyfile-access-control-in-existing-sharded-cluster-no-downtime/"> Update Self-Managed Sharded Cluster to Keyfile Authentication (No Downtime) </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/control-access-to-mongodb-with-kerberos-authentication/"> Configure Self-Managed MongoDB with Kerberos Authentication on Linux </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/control-access-to-mongodb-windows-with-kerberos-authentication/"> Configure Self-Managed MongoDB with Kerberos Authentication on Windows </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/kerberos-auth-activedirectory-authz/"> Configure Self-Managed MongoDB with Kerberos Authentication and Active Directory Authorization </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ldap-sasl-activedirectory/"> Authenticate Using Self-Managed SASL and LDAP with ActiveDirectory </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ldap-sasl-openldap/"> Authenticate Using Self-Managed SASL and LDAP with OpenLDAP </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/authenticate-nativeldap-activedirectory/"> Authenticate and Authorize Users Using Self-Managed Active Directory with Native LDAP </a> </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Next Steps <a class="headerlink leafygreen-ui-1kepx47" href="#next-steps" 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="next-steps"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To create additional users, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/create-users/"> Create a User on Self-Managed Deployments. </a> </p> <p class="leafygreen-ui-1kp3ins"> To manage users, assign roles, and create custom roles, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-users-and-roles/"> Manage Users and Roles on Self-Managed Deployments. </a> </p> </section> </section>
https://www.mongodb.com/docs/manual/reference/write-concern/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Write Concern <a class="headerlink leafygreen-ui-1kepx47" href="#write-concern" 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="write-concern"> </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="#write-concern-specification" target="_self"> <span> Write Concern Specification </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#implicit-default-write-concern" target="_self"> <span> Implicit Default Write Concern </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#acknowledgment-behavior" target="_self"> <span> Acknowledgment Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-information" target="_self"> <span> Additional Information </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> Write concern describes the level of acknowledgment requested from MongoDB for write operations to a standalone <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/#std-label-replication"> replica sets </a> , or <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/#std-label-sharding-background"> sharded clusters </a> . In sharded clusters, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instances will pass the write concern on to the shards. </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"> For <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> multi-document transactions </a> , you set the write concern at the transaction level, <strong class="css-4dei7l"> not at the individual operation level </strong> . Do not explicitly set the write concern for individual write operations in a transaction. </p> <p class="leafygreen-ui-1kp3ins"> If you specify a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> write concern for a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> multi-document transaction </a> and the transaction fails to replicate to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-calculating-majority-count" target="_self"> <span> calculated majority </span> </a> of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set"> replica set </a> members, then the transaction may not immediately roll back on replica set members. The replica set will be <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-eventual-consistency"> eventually consistent </a> . A transaction is always applied or rolled back on all replica set members. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Replica sets and sharded clusters support setting a global default write concern. Operations which do not specify an explicit write concern inherit the global default write concern settings. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#mongodb-dbcommand-dbcmd.setDefaultRWConcern"> <code class="leafygreen-ui-1l06pbn"> setDefaultRWConcern </code> </a> for more information. </p> <p class="leafygreen-ui-1kp3ins"> To learn more about setting the write concern for deployments hosted in MongoDB Atlas, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/resilient-application/#write-concern" target="_self"> <span> Build a Resilient Application with MongoDB Atlas </span> </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-wc-specs"> </span> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Write Concern Specification <a class="headerlink leafygreen-ui-1kepx47" href="#write-concern-specification" 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="write-concern-specification"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Write concern can include the following fields: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ w: &lt;value&gt;, j: &lt;boolean&gt;, wtimeout: &lt;number&gt; }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">w</span>: &lt;<!-- -->value<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">j</span>: &lt;<!-- -->boolean<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">wtimeout</span>: &lt;<!-- -->number<!-- -->&gt; <!-- -->}</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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-w" target="_self"> <span> w </span> </a> option to request acknowledgment that the write operation has propagated to a specified number of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances or to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances with specified tags. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-j" target="_self"> <span> j </span> </a> option to request acknowledgment that the write operation has been written to the on-disk journal, and </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-wtimeout" target="_self"> <span> wtimeout </span> </a> option to specify a time limit to prevent write operations from blocking indefinitely. </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-wc-w"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> w </code> Option <a class="headerlink leafygreen-ui-1kepx47" href="#w-option" 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="w-option"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> w </code> option requests acknowledgment that the write operation has propagated to a specified number of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances or to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances with specified tags. If the write concern is missing the <code class="leafygreen-ui-1l06pbn"> w </code> field, MongoDB sets the <code class="leafygreen-ui-1l06pbn"> w </code> option to the default write concern. </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 use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#mongodb-dbcommand-dbcmd.setDefaultRWConcern"> <code class="leafygreen-ui-1l06pbn"> setDefaultRWConcern </code> </a> to set the default write concern, you must specify a <code class="leafygreen-ui-1l06pbn"> w </code> field value. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Using the <code class="leafygreen-ui-1l06pbn"> w </code> option, the following <code class="leafygreen-ui-1l06pbn"> w: &lt;value&gt; </code> write concerns are available: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:25%"/> <col style="width:75%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="writeconcern"> <dt> <code class="leafygreen-ui-1l06pbn"> "majority" </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-writeconcern-writeconcern.-majority-" title="Permalink to this definition"> <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="mongodb-writeconcern-writeconcern.-majority-"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Requests acknowledgment that the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-calculating-majority-count" target="_self"> <span> calculated majority </span> </a> of data-bearing voting members have durably written the change to their local <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> . The members then asynchronously apply changes as they read them from their local oplogs. </p> <div> <p> <em> Changed <!-- --> in version <!-- --> 8.0 </em> : <!-- --> <!-- --> MongoDB doesn't wait for the members to apply the change before it acknowledges the write, as it did in previous releases. </p> </div> <p class="leafygreen-ui-1kp3ins"> The data-bearing voting members of a replica set are the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary"> primary </a> member and any <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary"> secondary </a> members with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.votes"> <code class="leafygreen-ui-1l06pbn"> members[n].votes </code> </a> greater than <code class="leafygreen-ui-1l06pbn"> 0 </code> . </p> <p class="leafygreen-ui-1kp3ins"> For more information, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-write-concern-majority-reads" target="_self"> <span> Reads after { w: "majority" } Writes <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { w: "majority" } </code> is the default write concern for <em> most </em> MongoDB deployments. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-default-behavior" target="_self"> <span> Implicit Default Write Concern <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> For example, consider a replica set with 3 voting members, Primary-Secondary-Secondary (P-S-S). For this replica set, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-calculating-majority-count" target="_self"> <span> calculated majority </span> </a> is two, and the write must propagate to the oplogs of the primary and one secondary to acknowledge the write concern to the client. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-hidden-member/#std-label-replica-set-hidden-members"> Hidden </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-delayed-member/#std-label-replica-set-delayed-members"> delayed </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-priority-0-member/#std-label-replica-set-secondary-only-members"> priority 0 </a> members with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.votes"> <code class="leafygreen-ui-1l06pbn"> members[n].votes </code> </a> greater than <code class="leafygreen-ui-1l06pbn"> 0 </code> can acknowledge <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> write operations. </p> <p class="leafygreen-ui-1kp3ins"> Delayed secondaries can return write acknowledgment no earlier than the configured <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.secondaryDelaySecs"> <code class="leafygreen-ui-1l06pbn"> secondaryDelaySecs </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> After the write operation returns with a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> w: "majority" </code> </span> </a> acknowledgment to the client, the client can read the result of that write with a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> readConcern. </p> <p class="leafygreen-ui-1kp3ins"> If you specify a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> write concern for a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions"> multi-document transaction </a> and the transaction fails to replicate to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-calculating-majority-count" target="_self"> <span> calculated majority </span> </a> of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set"> replica set </a> members, then the transaction may not immediately roll back on replica set members. The replica set will be <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-eventual-consistency"> eventually consistent </a> . A transaction is always applied or rolled back on all replica set members. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-ack-behavior" target="_self"> <span> Acknowledgment Behavior </span> </a> for when <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances acknowledge the write. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-write-concern-lv-number"> </span> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="writeconcern"> <dt> <code class="leafygreen-ui-1l06pbn"> &lt;number&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-writeconcern-writeconcern.-number-" title="Permalink to this definition"> <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="mongodb-writeconcern-writeconcern.-number-"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Requests acknowledgment that the write operation has propagated to the specified number of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances. For example: </p> <dl> <dt> <code class="leafygreen-ui-1l06pbn"> w: 1 </code> </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> Requests acknowledgment that the write operation has propagated to the standalone <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> or the primary in a replica set. Data can be <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-rollbacks/#std-label-rollback-avoid"> rolled back </a> if the primary steps down before the write operations have replicated to any of the secondaries. </p> <p class="leafygreen-ui-1kp3ins"> <strong class="css-4dei7l"> WARNING: </strong> If write operations use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-number-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> { w: 1 } </code> </span> </a> write concern, the rollback directory may exclude writes submitted after an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog-hole"> oplog hole </a> if the primary restarts before the write operation completes. </p> </dd> <dt> <code class="leafygreen-ui-1l06pbn"> w: 0 </code> </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> Requests no acknowledgment of the write operation. However, <code class="leafygreen-ui-1l06pbn"> w: 0 </code> may return information about socket exceptions and networking errors to the application. Data can be <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-rollbacks/#std-label-rollback-avoid"> rolled back </a> if the primary steps down before the write operations have replicated to any of the secondaries. </p> <p class="leafygreen-ui-1kp3ins"> If you specify <code class="leafygreen-ui-1l06pbn"> w: 0 </code> but include <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-j" target="_self"> <span> j: true </span> </a> , the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-j" target="_self"> <span> j: true </span> </a> prevails to request acknowledgment from the standalone <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> or the primary of a replica set. </p> </dd> </dl> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> w </code> greater than 1 requires acknowledgment from the primary and as many data-bearing secondaries as needed to meet the specified write concern. The secondaries do not need to be voting members to meet the write concern threshold. </p> <p class="leafygreen-ui-1kp3ins"> For example, consider a 3-member replica set with a primary and 2 secondaries. Specifying <code class="leafygreen-ui-1l06pbn"> w: 2 </code> would require acknowledgment from the primary and one of the secondaries. Specifying <code class="leafygreen-ui-1l06pbn"> w: 3 </code> would require acknowledgment from the primary and both secondaries. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-hidden-member/#std-label-replica-set-hidden-members"> Hidden </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-delayed-member/#std-label-replica-set-delayed-members"> delayed </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-priority-0-member/#std-label-replica-set-secondary-only-members"> priority 0 </a> members can acknowledge <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-number-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> w: &lt;number&gt; </code> </span> </a> write operations. </p> <p class="leafygreen-ui-1kp3ins"> Delayed secondaries can return write acknowledgment no earlier than the configured <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.secondaryDelaySecs"> <code class="leafygreen-ui-1l06pbn"> secondaryDelaySecs </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-ack-behavior" target="_self"> <span> Acknowledgment Behavior </span> </a> for when <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances acknowledge the write. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="writeconcern"> <dt> <code class="leafygreen-ui-1l06pbn"> &lt;custom write concern name&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-writeconcern-writeconcern.-custom-write-concern-name-" title="Permalink to this definition"> <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="mongodb-writeconcern-writeconcern.-custom-write-concern-name-"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Requests acknowledgment that the write operations have propagated to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.tags"> <code class="leafygreen-ui-1l06pbn"> tagged </code> </a> members that satisfy the custom write concern defined in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.getLastErrorModes"> <code class="leafygreen-ui-1l06pbn"> settings.getLastErrorModes </code> </a> . For an example, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-replica-set-tag-sets/#std-label-configure-custom-write-concern"> Custom Multi-Datacenter Write Concerns <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Data can be <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-rollbacks/#std-label-rollback-avoid"> rolled back </a> if the custom write concern only requires acknowledgment from the primary and the primary steps down before the write operations have replicated to any of the secondaries. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-ack-behavior" target="_self"> <span> Acknowledgment Behavior </span> </a> for when <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances acknowledge the write. </p> </div> </div> </td> </tr> </tbody> </table> </div> <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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-defaults/#std-label-default-mongodb-read-write-concerns"> Default MongoDB Read Concerns/Write Concerns </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-set-protocol-versions/#std-label-replica-set-protocol-version"> Self-Managed Replica Set Protocol Version </a> </p> </li> </ul> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-wc-j"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> j </code> Option <a class="headerlink leafygreen-ui-1kepx47" href="#j-option" 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="j-option"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> j </code> option requests acknowledgment from MongoDB that the write operation has been written to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journaling-internals"> on-disk journal <!-- --> . </a> </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="writeconcern"> <dt> <code class="leafygreen-ui-1l06pbn"> j </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-writeconcern-writeconcern.j" title="Permalink to this definition"> <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="mongodb-writeconcern-writeconcern.j"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> j: true </code> , requests acknowledgment that the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances, as specified in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-w" target="_self"> <span> w: &lt;value&gt; </span> </a> , have written to the on-disk journal. <code class="leafygreen-ui-1l06pbn"> j: true </code> does not by itself guarantee that the write will not be rolled back due to replica set primary failover. </p> <p class="leafygreen-ui-1kp3ins"> With <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.j" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> j: true </code> </span> </a> , MongoDB returns only after the requested number of members, including the primary, have written to the journal. Previously <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.j" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> j: true </code> </span> </a> write concern in a replica set only requires the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary"> primary </a> to write to the journal, regardless of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-w" target="_self"> <span> w: &lt;value&gt; </span> </a> write concern. </p> </div> </div> </td> </tr> </tbody> </table> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specifying a write concern that includes <code class="leafygreen-ui-1l06pbn"> j: true </code> 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> instance that is running without journaling produces an error. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If journaling is enabled, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> w: "majority" </code> </span> </a> may imply <code class="leafygreen-ui-1l06pbn"> j: true </code> . The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault"> <code class="leafygreen-ui-1l06pbn"> writeConcernMajorityJournalDefault </code> </a> replica set configuration setting determines the behavior. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-ack-behavior" target="_self"> <span> Acknowledgment Behavior </span> </a> for details. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A write concern that includes or implies <code class="leafygreen-ui-1l06pbn"> j: true </code> causes an immediate journal synchronization. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journal-process"> Journaling Process <!-- --> . </a> </p> </li> </ul> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-wc-wtimeout"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> wtimeout </code> <a class="headerlink leafygreen-ui-1kepx47" href="#wtimeout" 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="wtimeout"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> This option specifies a time limit, in milliseconds, for the write concern. <code class="leafygreen-ui-1l06pbn"> wtimeout </code> is only applicable for <code class="leafygreen-ui-1l06pbn"> w </code> values greater than <code class="leafygreen-ui-1l06pbn"> 1 </code> . </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> wtimeout </code> causes write operations to return with an error after the specified limit, even if the required write concern will eventually succeed. When these write operations return, MongoDB <strong> does not </strong> undo successful data modifications performed before the write concern exceeded the <code class="leafygreen-ui-1l06pbn"> wtimeout </code> time limit. </p> <p class="leafygreen-ui-1kp3ins"> If you do not specify the <code class="leafygreen-ui-1l06pbn"> wtimeout </code> option and the level of write concern is unachievable, the write operation will block indefinitely. Specifying a <code class="leafygreen-ui-1l06pbn"> wtimeout </code> value of <code class="leafygreen-ui-1l06pbn"> 0 </code> is equivalent to a write concern without the <code class="leafygreen-ui-1l06pbn"> wtimeout </code> option. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-wc-default-behavior"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Implicit Default Write Concern <a class="headerlink leafygreen-ui-1kepx47" href="#implicit-default-write-concern" 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="implicit-default-write-concern"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, the implicit default <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-write-concern" target="_self"> <span> write concern </span> </a> is <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> w: majority </code> </span> </a> . However, special considerations are made for deployments containing <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-arbiter/#std-label-replica-set-arbiter-configuration"> arbiters <!-- --> : </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The voting majority of a replica set is 1 plus half the number of voting members, rounded down. If the number of data-bearing voting members is not greater than the voting majority, the default write concern is <code class="leafygreen-ui-1l06pbn"> { w: 1 } </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> In all other scenarios, the default write concern is <code class="leafygreen-ui-1l06pbn"> { w: "majority" } </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Specifically, MongoDB uses the following formula to determine the default write concern: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"if [ (#arbiters &gt; 0) AND (#non-arbiters &lt;= majority(#voting-nodes)) ]\n defaultWriteConcern = { w: 1 }\nelse\n defaultWriteConcern = { w: \"majority\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" 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">if [ (#arbiters &gt; 0) AND (#non-arbiters &lt;= majority(#voting-nodes)) ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> defaultWriteConcern = { w: 1 }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">else</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> defaultWriteConcern = { w: "majority" }</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> For example, consider the following deployments and their respective default write concerns: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Non-Arbiters </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Arbiters </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Voting Nodes </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Majority of Voting Nodes </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Implicit Default Write Concern </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 1 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 3 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { w: 1 } </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 4 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 1 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 5 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 3 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { w: "majority" } </code> </div> </div> </td> </tr> </tbody> </table> </div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> In the first example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> There are 2 non-arbiters and 1 arbiter for a total of 3 voting nodes. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The majority of voting nodes (1 plus half of 3, rounded down) is 2. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The number of non-arbiters (2) is equal to the majority of voting nodes (2), resulting in an implicit write concern of <code class="leafygreen-ui-1l06pbn"> { w: 1 } </code> . </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> In the second example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> There are 4 non-arbiters and 1 arbiter for a total of 5 voting nodes. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The majority of voting nodes (1 plus half of 5, rounded down) is 3. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The number of non-arbiters (4) is greater than the majority of voting nodes (3), resulting in an implicit write concern of <code class="leafygreen-ui-1l06pbn"> { w: "majority" } </code> . </p> </li> </ul> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-wc-ack-behavior"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Acknowledgment Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#acknowledgment-behavior" 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="acknowledgment-behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-w" target="_self"> <span> w </span> </a> option and the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-j" target="_self"> <span> j </span> </a> option determine when <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances acknowledge write operations. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Standalone <a class="headerlink leafygreen-ui-1kepx47" href="#standalone" 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="standalone"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> A standalone <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> acknowledges a write operation either after applying the write in memory or after writing to the on-disk journal. The following table lists the acknowledgment behavior for a standalone and the relevant write concerns: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:35%"/> <col style="width:40%"/> <col style="width:25%"/> <col style="width:20%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <code class="leafygreen-ui-1l06pbn"> j </code> is unspecified </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <code class="leafygreen-ui-1l06pbn"> j:true </code> </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <code class="leafygreen-ui-1l06pbn"> j:false </code> </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> w: 1 </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> In memory </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> On-disk journal </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> In memory </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> w: "majority" </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> On-disk journal <em> if running with journaling </em> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> On-disk journal </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> In memory </div> </div> </td> </tr> </tbody> </table> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> With <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault"> <code class="leafygreen-ui-1l06pbn"> writeConcernMajorityJournalDefault </code> </a> set to <code class="leafygreen-ui-1l06pbn"> false </code> , MongoDB does not wait for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> w: "majority" </code> </span> </a> writes to be written to the on-disk journal before acknowledging the writes. As such, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> write operations could possibly roll back in the event of a transient loss (e.g. crash and restart) of a majority of nodes in a given replica set. </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-wc-replica-ack-behavior"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Replica Sets <a class="headerlink leafygreen-ui-1kepx47" href="#replica-sets" 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="replica-sets"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The value specified to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-w" target="_self"> <span> w </span> </a> determines the number of replica set members that must acknowledge the write before returning success. For each eligible replica set member, the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-j" target="_self"> <span> j </span> </a> option determines whether the member acknowledges writes after applying the write operation in memory or after writing to the on-disk journal. </p> <dl> <dt> <code class="leafygreen-ui-1l06pbn"> w: "majority" </code> </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> Any data-bearing voting member of the replica set can contribute to write acknowledgment of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> write operations. </p> <p class="leafygreen-ui-1kp3ins"> The following table lists when the member can acknowledge the write based on the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-j" target="_self"> <span> j </span> </a> value: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> j </code> is unspecified </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Acknowledgment depends on the value of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault"> <code class="leafygreen-ui-1l06pbn"> writeConcernMajorityJournalDefault </code> : </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> true </code> , acknowledgment requires writing operation to on-disk journal ( <code class="leafygreen-ui-1l06pbn"> j: true </code> ). </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault"> <code class="leafygreen-ui-1l06pbn"> writeConcernMajorityJournalDefault </code> </a> defaults to <code class="leafygreen-ui-1l06pbn"> true </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> false </code> , acknowledgment requires writing operation in memory ( <code class="leafygreen-ui-1l06pbn"> j: false </code> ). </p> </li> </ul> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> j: true </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Acknowledgment requires writing operation to on-disk journal. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> j: false </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Acknowledgment requires writing operation in memory. </p> <p class="leafygreen-ui-1kp3ins"> Typically, if <code class="leafygreen-ui-1l06pbn"> j: false </code> is set, writing the operation to the on-disk journal isn't required. However, if <code class="leafygreen-ui-1l06pbn"> writeConcernMajorityJournalDefault: true </code> is set, writing the operation to the journal is required even if <code class="leafygreen-ui-1l06pbn"> j: false </code> is set. </p> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> j: false </code> and <code class="leafygreen-ui-1l06pbn"> writeConcernMajorityJournalDefault: true </code> are set, the write operations are written to the journal asynchronously. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Writes that have <code class="leafygreen-ui-1l06pbn"> w: majority </code> set aren't acknowledged as complete until the journal is flushed to disk. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> w: majority </code> writes wait for the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> read snapshot to complete, regardless of the <code class="leafygreen-ui-1l06pbn"> j </code> setting. This is because if <code class="leafygreen-ui-1l06pbn"> writeConcernMajorityJournalDefault: true </code> is set, the majority read snapshot is based on the majority of journaled writes. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> After the write operation returns with a <code class="leafygreen-ui-1l06pbn"> w: majority </code> acknowledgment to the client application, the application can read the result of the write if the <code class="leafygreen-ui-1l06pbn"> majority </code> read concern is set. </p> </li> </ul> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> For behavior details, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-majority-behavior" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> w: "majority" </code> Behavior <!-- --> . </span> </a> </p> </dd> <dt> <code class="leafygreen-ui-1l06pbn"> w: &lt;number&gt; </code> </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> Any data-bearing member of the replica set can contribute to write acknowledgment of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-w" target="_self"> <span> w: &lt;number&gt; </span> </a> write operations. </p> <p class="leafygreen-ui-1kp3ins"> The following table lists when the member can acknowledge the write based on the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-j" target="_self"> <span> j </span> </a> value: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> j </code> is unspecified </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Acknowledgment requires writing operation in memory ( <code class="leafygreen-ui-1l06pbn"> j: false </code> ). </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> j: true </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Acknowledgment requires writing operation to on-disk journal. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> j: false </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Acknowledgment requires writing operation in memory. </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <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 class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-hidden-member/#std-label-replica-set-hidden-members"> Hidden </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-delayed-member/#std-label-replica-set-delayed-members"> delayed </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-priority-0-member/#std-label-replica-set-secondary-only-members"> priority 0 </a> members can acknowledge <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-number-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> w: &lt;number&gt; </code> </span> </a> write operations. </p> <p class="leafygreen-ui-1kp3ins"> Delayed secondaries can return write acknowledgment no earlier than the configured <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.secondaryDelaySecs"> <code class="leafygreen-ui-1l06pbn"> secondaryDelaySecs </code> . </a> </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-write-concern-majority-reads"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Reads after { w: "majority" } Writes <a class="headerlink leafygreen-ui-1kepx47" href="#reads-after---w---majority----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-after---w---majority----writes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 8.0, <code class="leafygreen-ui-1l06pbn"> { w: "majority" } </code> writes return an acknowledgment after a majority of data-bearing members durably write the oplog entry. The members then asynchronously apply the changes as they read them from their local oplogs. In earlier releases, MongoDB waited until after the members applied the write to return the acknowledgment. </p> <p class="leafygreen-ui-1kp3ins"> Queries on secondaries immediately after a <code class="leafygreen-ui-1l06pbn"> { w: "majority" } </code> write returns an acknowledgment may read from the collection before the secondary applies changes from the write. </p> <p class="leafygreen-ui-1kp3ins"> If your application reads from secondaries and requires immediate access to changes made in <code class="leafygreen-ui-1l06pbn"> { w: "majority" } </code> writes, run these operations in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-causal-consistency"> causally consistent </a> session. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" 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> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Causally Consistent Sessions and Write Concerns <a class="headerlink leafygreen-ui-1kepx47" href="#causally-consistent-sessions-and-write-concerns" 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="causally-consistent-sessions-and-write-concerns"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> With <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions"> causally consistent client sessions </a> , the client sessions only guarantee causal consistency if: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the associated read operations use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> read concern, and </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the associated write operations use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> write concern. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For details, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-causal-consistency"> Causal Consistency <!-- --> . </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-wc-majority-behavior"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> w: "majority" </code> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#w---majority--behavior" 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="w---majority--behavior"> </div> </a> </h3> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> With <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault"> <code class="leafygreen-ui-1l06pbn"> writeConcernMajorityJournalDefault </code> </a> set to <code class="leafygreen-ui-1l06pbn"> false </code> , MongoDB does not wait for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> w: "majority" </code> </span> </a> writes to be written to the on-disk journal before acknowledging the writes. As such, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> write operations could possibly roll back in the event of a transient loss (e.g. crash and restart) of a majority of nodes in a given replica set. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-hidden-member/#std-label-replica-set-hidden-members"> Hidden </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-delayed-member/#std-label-replica-set-delayed-members"> delayed </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-priority-0-member/#std-label-replica-set-secondary-only-members"> priority 0 </a> members with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.votes"> <code class="leafygreen-ui-1l06pbn"> members[n].votes </code> </a> greater than <code class="leafygreen-ui-1l06pbn"> 0 </code> can acknowledge <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> write operations. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Delayed secondaries can return write acknowledgment no earlier than the configured <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.secondaryDelaySecs"> <code class="leafygreen-ui-1l06pbn"> secondaryDelaySecs </code> . </a> </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, replica set members in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.STARTUP2"> <code class="leafygreen-ui-1l06pbn"> STARTUP2 </code> </a> state do not participate in write majorities. </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Write Concern not Supported on <code class="leafygreen-ui-1l06pbn"> local </code> Database <a class="headerlink leafygreen-ui-1kepx47" href="#write-concern-not-supported-on-local-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="write-concern-not-supported-on-local-database"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/local-database/#std-label-replica-set-local-database"> local database </a> does not support write concerns. MongoDB silently ignores any configured write concern for an operation on a collection in the local database. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-calculating-majority-count"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Calculating Majority for Write Concern <a class="headerlink leafygreen-ui-1kepx47" href="#calculating-majority-for-write-concern" 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="calculating-majority-for-write-concern"> </div> </a> </h3> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.status/#mongodb-method-rs.status"> <code class="leafygreen-ui-1l06pbn"> rs.status() </code> </a> returns the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetStatus/#mongodb-data-replSetGetStatus.writeMajorityCount"> <code class="leafygreen-ui-1l06pbn"> writeMajorityCount </code> </a> field which contains the calculated majority number. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> The majority for write concern <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> is calculated as the smaller of the following values: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the majority of <em> all </em> voting members (including arbiters) vs. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the number of all <strong> data-bearing </strong> voting members. </p> </li> </ul> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> In cases where the calculated majority number is equal to the number of all <strong> data-bearing </strong> voting members (such as with a 3-member Primary-Secondary-Arbiter deployment), write concern <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> may time out or never be acknowledged if a data bearing voting member is down or unreachable. If possible, use a data-bearing voting member instead of an arbiter. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> For example, consider: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A replica set with 3 voting members, Primary-Secondary-Secondary (P-S-S): </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The majority of all voting members is 2. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The number of all data-bearing voting members is 3. </p> </li> </ul> <div class="line-block"> <div class="line"> The calculated majority is 2, the minimum of 2 and 3. The write must propagate to the primary and one of the secondaries to acknowledge the write concern <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> to the client. </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A replica set with 3 voting members, Primary-Secondary-Arbiter (P-S-A) </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The majority of all voting members is 2. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The number of all data-bearing voting members is 2. </p> </li> </ul> <div class="line-block"> <div class="line"> The calculated majority is 2, the minimum of 2 and 2. Since the write can only be applied to data-bearing members, the write must propagate to the primary and the secondary to acknowledge the write concern <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> to the client. </div> </div> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Avoid using a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> write concern with a (P-S-A) or other topologies that require all data-bearing voting members to be available to acknowledge the writes. Customers who want the durability guarantees of using a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-writeconcern-writeconcern.-majority-" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </span> </a> write concern should instead deploy a topology that does not require all data bearing voting members to be available (e.g. P-S-S). </p> </div> </div> </li> </ul> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Avoid deploying more than one <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-arbiter"> arbiter </a> in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set"> replica set </a> . See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-arbiter/#std-label-rollbacks-multi-arbiters"> Concerns with Multiple Arbiters <!-- --> . </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> To add an arbiter to an existing replica set: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Typically, if there are two or fewer data-bearing members in the replica set, you might need to first set the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#std-label-set_global_default_write_concern"> cluster wide write concern </a> for the replica set. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#std-label-set_global_default_write_concern"> cluster wide write concern </a> for more information on why you might need to set the cluster wide write concern. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You do not need to change the cluster wide write concern before starting a new replica set with an arbiter. </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/reference/mongodb-defaults/#std-label-default-wc-formula"> Default write concern formula </a> </p> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Write Concern Provenance <a class="headerlink leafygreen-ui-1kepx47" href="#write-concern-provenance" 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="write-concern-provenance"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB tracks write concern <code class="leafygreen-ui-1l06pbn"> provenance </code> , which indicates the source of a particular write concern. You may see <code class="leafygreen-ui-1l06pbn"> provenance </code> shown in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.metrics.getLastError"> <code class="leafygreen-ui-1l06pbn"> getLastError </code> </a> metrics, write concern error objects, and MongoDB logs. </p> <p class="leafygreen-ui-1kp3ins"> The following table shows the possible write concern <code class="leafygreen-ui-1l06pbn"> provenance </code> values and their significance: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:40%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Provenance </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> clientSupplied </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern was specified in the application. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> customDefault </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern originated from a custom defined default value. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#mongodb-dbcommand-dbcmd.setDefaultRWConcern"> <code class="leafygreen-ui-1l06pbn"> setDefaultRWConcern </code> . </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> getLastErrorDefaults </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern originated from the replica set's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.getLastErrorDefaults"> <code class="leafygreen-ui-1l06pbn"> settings.getLastErrorDefaults </code> </a> field. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> implicitDefault </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern originated from the server in absence of all other write concern specifications. </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-write-concern-contrasted-with-commit-quorum"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Write Concern Contrasted with Commit Quorum <a class="headerlink leafygreen-ui-1kepx47" href="#write-concern-contrasted-with-commit-quorum" 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="write-concern-contrasted-with-commit-quorum"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> There are important differences between <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/createIndexes/#std-label-createIndexes-cmd-commitQuorum"> commit quorums </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-write-concern" target="_self"> <span> write concerns <!-- --> : </span> </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Index builds use commit quorums. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Write operations use write concerns. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Each data-bearing node in a cluster is a voting member. </p> <p class="leafygreen-ui-1kp3ins"> The commit quorum specifies how many data-bearing voting members, or which voting members, including the primary, must be prepared to commit a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations-simultaneous-build"> simultaneous index build </a> before the primary will execute the commit. </p> <p class="leafygreen-ui-1kp3ins"> The write concern is the level of acknowledgment that the write has propagated to the specified number of instances. </p> <div> <p> <em> Changed <!-- --> in version <!-- --> 8.0 </em> : <!-- --> <!-- --> The commit quorum specifies how many nodes must be ready to finish the index build before the primary commits the index build. In contrast, when the primary has committed the index build, the write concern specifies how many nodes must replicate the index build oplog entry before the command returns success. </p> <p class="leafygreen-ui-1kp3ins"> In previous releases, when the primary committed the index build, the write concern specified how many nodes must finish the index build before the command returned success. </p> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/core/csfle/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Client-Side Field Level Encryption <a class="headerlink leafygreen-ui-1kepx47" href="#client-side-field-level-encryption" 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="client-side-field-level-encryption"> </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="#introduction" target="_self"> <span> Introduction </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self"> <span> Considerations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#features" target="_self"> <span> Features </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#installation" target="_self"> <span> Installation </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#quick-start" target="_self"> <span> Quick Start </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#fundamentals" target="_self"> <span> Fundamentals </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#tutorials" target="_self"> <span> Tutorials </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#reference" target="_self"> <span> Reference </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Introduction <a class="headerlink leafygreen-ui-1kepx47" href="#introduction" 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="introduction"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Client-Side Field Level Encryption (CSFLE) is a feature that enables you to encrypt data in your application before you send it over the network to MongoDB. With CSFLE enabled, no MongoDB product has access to your data in an unencrypted form. </p> <p class="leafygreen-ui-1kp3ins"> You can set up CSFLE using the following mechanisms: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Automatic Encryption: Enables you to perform encrypted read and write operations without having to add explicit calls to encrypt and decrypt fields. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Explicit Encryption: Enables you to perform encrypted read and write operations through your MongoDB driver's encryption library. You must specify the logic for encryption with this library throughout your application. </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> When implementing an application that uses Client-Side Field Level Encryption, consider the points listed in <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/about-qe-csfle/#std-label-qe-csfle-security-considerations"> Security Considerations <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> For limitations, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/limitations/#std-label-csfle-reference-encryption-limits"> CSFLE limitations <!-- --> . </a> </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To learn which MongoDB server products and drivers support CSFLE, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/reference/compatibility/#std-label-csfle-compatibility-reference"> Client-Side Field Level Encryption Compatibility <!-- --> . </a> </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Features <a class="headerlink leafygreen-ui-1kepx47" href="#features" 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="features"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To learn about the security benefits of CSFLE for your applications, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/features/#std-label-csfle-features"> Features </a> page. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Installation <a class="headerlink leafygreen-ui-1kepx47" href="#installation" 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="installation"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To learn what you must install to use CSFLE, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/install/#std-label-csfle-install"> Installation Requirements </a> page. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Quick Start <a class="headerlink leafygreen-ui-1kepx47" href="#quick-start" 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="quick-start"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To start using CSFLE, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/quick-start/#std-label-csfle-quick-start"> Quick Start <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Throughout this guide, code examples use placeholder text. Before you run the examples, substitute your own values for these placeholders. </p> <p class="leafygreen-ui-1kp3ins"> For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"dek_id := \"&lt;your&gt;\"","programmingLanguage":"Golang"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light go leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">dek_id <!-- -->:=<!-- --> <span class="lg-highlight-string">"&lt;Your Base64 DEK ID&gt;"</span></td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> You would replace everything between quotes with your <span class="leafygreen-ui-vm4wms" tabindex="0"> DEK </span> ID. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"dek_id := \"abc123\"","programmingLanguage":"Golang"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light go leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">dek_id <!-- -->:=<!-- --> <span class="lg-highlight-string">"abc123"</span></td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Fundamentals <a class="headerlink leafygreen-ui-1kepx47" href="#fundamentals" 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="fundamentals"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To learn how CSFLE works and how to set it up, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/#std-label-csfle-fundamentals"> Fundamentals </a> section. </p> <p class="leafygreen-ui-1kp3ins"> The fundamentals section contains the following pages: </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/csfle/fundamentals/automatic-encryption/#std-label-csfle-fundamentals-automatic-encryption"> Automatic Encryption </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/manual-encryption/#std-label-csfle-fundamentals-manual-encryption"> Explicit Encryption </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/create-schema/#std-label-csfle-fundamentals-create-schema"> Encryption Schemas </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/manage-keys/#std-label-csfle-fundamentals-manage-keys"> Encryption Key Management </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/encryption-algorithms/#std-label-csfle-reference-encryption-algorithms"> Fields and Encryption Types </a> </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Tutorials <a class="headerlink leafygreen-ui-1kepx47" href="#tutorials" 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="tutorials"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To learn how to perform specific tasks with CSFLE, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/tutorials/#std-label-csfle-tutorials"> Tutorials </a> section. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Reference <a class="headerlink leafygreen-ui-1kepx47" href="#reference" 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="reference"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To learn about encryption key management, read <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/keys-key-vaults/#std-label-qe-reference-keys-key-vaults"> Encryption Keys and Key Vaults <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> For more information about developing your CSFLE-enabled applications, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/#std-label-csfle-reference"> Reference </a> section, which contains the following pages: </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/csfle/reference/encryption-schemas/#std-label-csfle-reference-encryption-schemas"> CSFLE Encryption Schemas </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/server-side-schema/#std-label-csfle-reference-server-side-schema"> CSFLE Server-Side Schema Enforcement </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/supported-operations/#std-label-csfle-reference-automatic-encryption-supported-operations"> Supported Operations for Automatic Encryption </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/csfle-options-clients/#std-label-csfle-reference-mongo-client"> MongoClient Options for CSFLE </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/encryption-components/#std-label-csfle-reference-encryption-components"> CSFLE Encryption Components </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/decryption/#std-label-csfle-reference-decryption"> How CSFLE Decrypts Documents </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/cryptographic-primitives/#std-label-csfle-reference-cryptographic-primitives"> CSFLE Cryptographic Primitives </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/install-library/#std-label-csfle-reference-mongocryptd"> Install and Configure a CSFLE Library </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/libmongocrypt/#std-label-csfle-reference-libmongocrypt"> Install libmongocrypt for CSFLE </a> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/core/csfle/quick-start/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Quick Start <a class="headerlink leafygreen-ui-1kepx47" href="#quick-start" 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="quick-start"> </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="#overview" target="_self"> <span> Overview </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#before-you-get-started" target="_self"> <span> Before You Get Started </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#full-application-code" target="_self"> <span> Full Application Code </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#procedure" target="_self"> <span> Procedure </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-a-customer-master-key" target="_self"> <span> Create a Customer Master Key </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-a-unique-index-on-your-key-vault-collection" target="_self"> <span> Create a Unique Index on your Key Vault collection </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-a-data-encryption-key" target="_self"> <span> Create a Data Encryption Key </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#configure-the-mongoclient" target="_self"> <span> Configure the MongoClient </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#insert-a-document-with-encrypted-fields" target="_self"> <span> Insert a Document with Encrypted Fields </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#retrieve-your-document-with-encrypted-fields" target="_self"> <span> Retrieve Your Document with Encrypted Fields </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Overview <a class="headerlink leafygreen-ui-1kepx47" href="#overview" 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="overview"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This guide shows you how to encrypt a document with automatic Client-Side Field Level Encryption (CSFLE) and a MongoDB driver. </p> <p class="leafygreen-ui-1kp3ins"> After completing this guide, you should have the following knowledge and software: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Knowledge of the steps to configure a driver to encrypt fields in a document. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A working, but not production-ready, client application that utilizes automatic Client-Side Field Level Encryption. </p> </li> </ul> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Do Not Use this Application In Production </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Since this example application stores an encryption key on your application's filesystem, you risk unauthorized access to the key or loss of the key to decrypt your data. </p> <p class="leafygreen-ui-1kp3ins"> To view a tutorial that demonstrates how to create a production-ready CSFLE-enabled application, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/tutorials/#std-label-csfle-tutorial-automatic-encryption"> Tutorials <!-- --> . </a> </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-csfle-guide-intro"> </span> <span class="leafygreen-ui-1qnjd6d" id="std-label-fle-create-a-master-key"> </span> <span class="leafygreen-ui-1qnjd6d" id="std-label-download-example-project"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Before You Get Started <a class="headerlink leafygreen-ui-1kepx47" href="#before-you-get-started" 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="before-you-get-started"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To complete and run the code in this guide, you need to set up your development environment as shown in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/install/#std-label-csfle-install"> Installation Requirements </a> page. </p> <p class="leafygreen-ui-1kp3ins"> Select the programming language for which you want to see code examples for from the <span class="guilabel css-h15tq0"> Select your language </span> dropdown menu on the right side of the page. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Full Application Code <a class="headerlink leafygreen-ui-1kepx47" href="#full-application-code" 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="full-application-code"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To see the complete code for the sample application, select your programming language in the language selector. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-7"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_m699dhytl" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_raeo0uej3" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_vp6wg4oxx" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_i9cs3m1w7" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_743wf6ypd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_bt73c2eb4" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_0ixs8u9yh" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_75ucgzp61" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_ngrjc2xc9" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_yfaitqacd" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_xbl3qkzw2" class="leafygreen-ui-38lglc" id="_14ye0yg1j" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/dotnet/local/reader/CSFLE/" rel="noopener noreferrer"> <span> Complete C# Application </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> </p> </div> </div> </div> <div> <div aria-labelledby="_540l3j7cr" class="leafygreen-ui-38lglc" id="_s7r3zuzul" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/go/local/reader/" rel="noopener noreferrer"> <span> Complete Go Application </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> </p> </div> </div> </div> <div> <div aria-labelledby="_uc0an68tv" class="leafygreen-ui-38lglc" id="_kz4inl8eb" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/java/local/reader/" rel="noopener noreferrer"> <span> Complete Java Application </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> </p> </div> </div> </div> <div> <div aria-labelledby="_zsdf27uoy" class="" id="_b0ea1fdz2" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/node/local/reader/" rel="noopener noreferrer"> <span> Complete Node.js Application </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> </p> </div> </div> </div> <div> <div aria-labelledby="_te5dbk3ly" class="leafygreen-ui-38lglc" id="_ah94yfqz1" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/python/local/reader/" rel="noopener noreferrer"> <span> Complete Python Application </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> </p> </div> </div> </div> </div> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Procedure <a class="headerlink leafygreen-ui-1kepx47" href="#procedure" 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="procedure"> </div> </a> </h2> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-9"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_64i7ajydx" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_36ntf2dgc" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_cnl3mwil5" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_4tr6vqvnp" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_5ffw5cphg" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_dthbg736w" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_1ni4o3bx8" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_xywforglt" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_ryspuk2f1" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_fio7tqb7l" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_6i1rmi3ng" class="leafygreen-ui-38lglc" id="_2dpv0bi7j" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// You are viewing the C# driver code examples.\n// Use the dropdown menu to select a different driver.","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> You are viewing </span><span class="lg-highlight-comment">the C# driver code examples.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Use the dropdown </span><span class="lg-highlight-comment">menu</span><span class="lg-highlight-comment"> to select a </span><span class="lg-highlight-comment">different driver.</span></td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-37-menu" aria-describedby="select-37-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-38" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r7s:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r7s:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r7s:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r7s:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_olk3obj61" class="leafygreen-ui-38lglc" id="_l88evt3e7" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// You are viewing the Golang driver code examples.\n// Use the dropdown menu to select a different driver.","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> You are viewing </span><span class="lg-highlight-comment">the</span><span class="lg-highlight-comment"> Golang driver code </span><span class="lg-highlight-comment">examples.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Use the dropdown </span><span class="lg-highlight-comment">menu</span><span class="lg-highlight-comment"> to select a </span><span class="lg-highlight-comment">different driver.</span></td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-40-menu" aria-describedby="select-40-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-41" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r7t:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r7t:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r7t:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r7t:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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 class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> When building or running the Golang code in this guide using <code class="leafygreen-ui-1l06pbn"> go build </code> or <code class="leafygreen-ui-1l06pbn"> go run </code> , always include the <code class="leafygreen-ui-1l06pbn"> cse </code> build constraint to enable CSFLE. See the following shell command for an example of including the build constraint: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"go run -tags cse insert-encrypted-document.go","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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">go run -tags cse insert-encrypted-<span class="lg-highlight-variable lg-highlight-language">document</span>.<span class="lg-highlight-property">go</span></td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-43-menu" aria-describedby="select-43-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-44" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r7u:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r7u:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r7u:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r7u:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <div> <div aria-labelledby="_k97zjckpy" class="leafygreen-ui-38lglc" id="_q4958uhts" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// You are viewing the Java synchronous driver code examples.\n// Use the dropdown menu to select a different driver.","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> You are viewing </span><span class="lg-highlight-comment">the</span><span class="lg-highlight-comment"> Java synchronous driver </span><span class="lg-highlight-comment">code examples.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Use the dropdown </span><span class="lg-highlight-comment">menu</span><span class="lg-highlight-comment"> to select a </span><span class="lg-highlight-comment">different driver.</span></td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-46-menu" aria-describedby="select-46-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-47" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r7v:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r7v:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r7v:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r7v:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_xtcm73gmo" class="" id="_s44x911aj" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// You are viewing the Node.js driver code examples.\n// Use the dropdown menu to select a different driver.","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> You are viewing </span><span class="lg-highlight-comment">the Node.js driver code examples.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Use the dropdown </span><span class="lg-highlight-comment">menu</span><span class="lg-highlight-comment"> to select a </span><span class="lg-highlight-comment">different driver.</span></td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-49-menu" aria-describedby="select-49-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-50" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r80:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r80:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r80:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r80:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_0rr5ujmyn" class="leafygreen-ui-38lglc" id="_icr11aavq" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"# You are viewing the Python driver code examples.\n# Use the dropdown menu to select a different driver.","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"># <span class="lg-highlight-title lg-highlight-class">You</span> are viewing the <span class="lg-highlight-title lg-highlight-class">Python</span> driver code examples.</td></tr><tr class=""><td class="leafygreen-ui-7razhx"># <span class="lg-highlight-title lg-highlight-class">Use</span> the dropdown menu to select a different driver.</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-52-menu" aria-describedby="select-52-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-53" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r81:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r81:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r81:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r81:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"You must create a Customer Master Key (CMK (Customer Master Key)) to perform CSFLE.Create a 96-byte Customer Master Key and save it in your Local Key Provider,\nwhich is your filesystem,\nas the file master-key.txt:We recommend storing your Customer Master Keys in a remote Key Management System (KMS (Key Management System)). To learn how to use\na remote KMS (Key Management System) in your Queryable Encryption implementation, see the\nTutorials guide.If you choose to use a local key provider in production, exercise great\ncaution and do not store it on the file system. Consider injecting the key\ninto your client application using a sidecar process, or use another\napproach that keeps the key secure.Use the following command to generate a CMK (Customer Master Key)\nfrom a Unix shell or PowerShell:Unix shell:PowerShell:Save the output of the preceding command to a file named customer-master-key.txt.To view the complete code for making a Customer Master Key, see\nour Github repository.To view the complete code for making a Customer Master Key, see\nour Github repository.To view the complete code for making a Customer Master Key, see\nour Github repository.To view the complete code for making a Customer Master Key, see\nour Github repository.To view the complete code for making a Customer Master Key, see\nour Github repository.","name":"Create a Customer Master Key"},{"@type":"HowToStep","text":"Create a partial unique index on the keyAltNames field in your\nencryption.__keyVault namespace. This index should have a\npartialFilterExpression for documents where keyAltNames exists.Client-Side Field Level Encryption depends on server-enforced uniqueness of key alternate names.Select the tab corresponding to your preferred MongoDB driver:","name":"Create a Unique Index on your Key Vault collection"},{"@type":"HowToStep","text":"Read the Customer Master Key and Specify KMS Provider SettingsRetrieve the contents of the Customer Master Key file that you generated\nin the Create a Customer Master Key step of this guide.Use the CMK (Customer Master Key) value in your KMS provider settings. The\nclient uses these settings to discover the CMK (Customer Master Key). As\nyou are using the Local Key Provider, set the provider name to\nlocal.Create a Data Encryption KeyConstruct a client with your MongoDB connection string and Key Vault collection\nnamespace, and create a Data Encryption Key:To complete this tutorial, the database user your application uses to connect to\nMongoDB must have dbAdmin permissions on the following namespaces:encryption.__keyVaultmedicalRecords databaseWhen using the Node.js driver v6.0 and later, you must import\nClientEncryption from mongodb.For earlier driver versions, import ClientEncryption from\nmongodb-client-encryption.The output from the code above should resemble the following:To view the complete code for making a Data Encryption Key, see\nour Github repository.To view the complete code for making a Data Encryption Key, see\nour Github repository.To view the complete code for making a Data Encryption Key, see\nour Github repository.To view the complete code for making a Data Encryption Key, see\nour Github repository.To view the complete code for making a Data Encryption Key, see\nour Github repository.","name":"Create a Data Encryption Key"},{"@type":"HowToStep","text":"Specify the Key Vault Collection NamespaceSpecify encryption.__keyVault as the Key Vault collection\nnamespace.Specify the Local Customer Master KeySpecify the KMS provider and specify your key inline:Create an Encryption Schema For Your CollectionMake sure to update the following code to include your Base64\nDEK (Data Encryption Key) ID. You received this value in the\nGenerate your Data Encryption Key step of this\nguide.Specify the Location of the Automatic Encryption Shared LibraryThe automatic encryption options provide configuration\ninformation to the Automatic Encryption Shared Library,\nwhich modifies the application's behavior when accessing encrypted fields.To learn more about the Automatic Encryption Shared Library, see\nthe Install and Configure a CSFLE Library page.Create the MongoClientInstantiate a MongoDB client object with the following\nautomatic encryption settings:","name":"Configure the MongoClient"},{"@type":"HowToStep","text":"Use your CSFLE-enabled\nMongoClient instance to insert a document with encrypted fields into the\nmedicalRecords.patients namespace using the following code\nsnippet:Rather than creating a raw BSON document, you can pass a struct with bson tags directly\nto the driver for encoding.When you insert a document, your CSFLE-enabled client\nencrypts the fields of your document such that it resembles the following:To view the complete code for inserting a document with encrypted fields, see\nour Github repositoryTo view the complete code for inserting a document with encrypted fields, see\nour Github repository.To view the complete code for inserting a document with encrypted fields, see\nour Github repository.To view the complete code for inserting a document with encrypted fields, see\nour Github repository.To view the complete code for inserting a document with encrypted fields, see\nour Github repository.","name":"Insert a Document with Encrypted Fields"},{"@type":"HowToStep","text":"Retrieve the document with encrypted fields you inserted in the\nInsert a Document with Encrypted Fields\nstep of this guide.To show the functionality of CSFLE, the following code snippet queries for\nyour document with a client configured for automatic CSFLE as well as\na client that is not configured for automatic CSFLE.The output of the preceding code snippet should look like this:To view the complete code for finding a document with encrypted fields, see\nour Github repositoryTo view the complete code for finding a document with encrypted fields, see\nour Github repository.To view the complete code for finding a document with encrypted fields, see\nour Github repository.To view the complete code for finding a document with encrypted fields, see\nour Github repository.To view the complete code for finding a document with encrypted fields, see\nour Github repository.","name":"Retrieve Your Document with Encrypted Fields"}],"name":"Procedure","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create a Customer Master Key <a class="headerlink leafygreen-ui-1kepx47" href="#create-a-customer-master-key" 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-customer-master-key"> </div> </a> </h3> <span class="leafygreen-ui-1qnjd6d" id="std-label-csfle-quick-start-create-master-key"> </span> <span class="leafygreen-ui-1qnjd6d" id="std-label-fle-create-a-master-key-1"> </span> <p class="leafygreen-ui-1kp3ins"> You must create a Customer Master Key ( <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> ) to perform CSFLE. </p> <p class="leafygreen-ui-1kp3ins"> Create a 96-byte Customer Master Key and save it in your <strong> Local Key Provider </strong> , which is your filesystem, as the file <code class="leafygreen-ui-1l06pbn"> master-key.txt </code> : </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-11"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_ah1h4uwqa" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_nc1pao4nk" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_wobbkap8m" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ovzo7p25i" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_tcmle46gz" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_o05owwr7j" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_2t08vm8km" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_a8h8a31kr" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_4jzdobqhc" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_9rzampt02" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_aody6bh88" class="" id="_llnxnfs9r" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const fs = require(\"fs\");\nconst crypto = require(\"crypto\");\ntry {\n fs.writeFileSync(\"master-key.txt\", crypto.randomBytes(96));\n} catch (err) {\n console.error(err);\n}","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> fs <!-- -->= <span class="lg-highlight-built_in">require</span>(<span class="lg-highlight-string">"fs"</span>)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> crypto <!-- -->= <span class="lg-highlight-built_in">require</span>(<span class="lg-highlight-string">"crypto"</span>)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">try</span> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->fs.<span class="lg-highlight-title lg-highlight-function">writeFileSync</span>(<span class="lg-highlight-string">"master-key.txt"</span>, <!-- -->crypto.<span class="lg-highlight-title lg-highlight-function">randomBytes</span>(<span class="lg-highlight-number">96</span>))<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} <span class="lg-highlight-keyword">catch</span> <!-- -->(<!-- -->err) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">error</span>(<!-- -->err)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-55-menu" aria-describedby="select-55-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-56" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r82:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r82:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r82:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r82:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_wuta13cln" class="leafygreen-ui-38lglc" id="_ol9yq25se" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"using (var randomNumberGenerator = System.Security.Cryptography.RandomNumberGenerator.Create())\n{\n var bytes = new byte[96];\n randomNumberGenerator.GetBytes(bytes);\n var localMasterKeyBase64Write = Convert.ToBase64String(bytes);\n Console.WriteLine(localMasterKeyBase64Write);\n File.WriteAllText(\"master-key.txt\", localMasterKeyBase64Write);\n}","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">using (<span class="lg-highlight-keyword">var</span> randomNumberGenerator = <span class="lg-highlight-title lg-highlight-class">System</span>.<span class="lg-highlight-property">Security</span>.<span class="lg-highlight-property">Cryptography</span>.<span class="lg-highlight-property">RandomNumberGenerator</span>.<span class="lg-highlight-title lg-highlight-class">Create</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> bytes = <span class="lg-highlight-keyword">new</span> byte[<span class="lg-highlight-number">96</span>];</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> randomNumberGenerator.<span class="lg-highlight-title lg-highlight-class">GetBytes</span>(bytes);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> localMasterKeyBase64Write = <span class="lg-highlight-title lg-highlight-class">Convert</span>.<span class="lg-highlight-title lg-highlight-class">ToBase64String</span>(bytes);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>(localMasterKeyBase64Write);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">File</span>.<span class="lg-highlight-title lg-highlight-class">WriteAllText</span>(<span class="lg-highlight-string">"master-key.txt"</span>, localMasterKeyBase64Write);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-58-menu" aria-describedby="select-58-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-59" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r83:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r83:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r83:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r83:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_n5htjr6my" class="leafygreen-ui-38lglc" id="_r5phc35tb" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"func localMasterKey() []byte {\n\tkey := make([]byte, 96)\n\tif _, err := rand.Read(key); err != nil {\n\t\tlog.Fatalf(\"Unable to create a random 96 byte data key: %v\", err)\n\t}\n\tif err := ioutil.WriteFile(\"master-key.txt\", key, 0644); err != nil {\n\t\tlog.Fatalf(\"Unable to write key to file: %v\", err)\n\t}\n\treturn key\n}\n","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">func <span class="lg-highlight-title lg-highlight-function">localMasterKey</span>() []byte {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->key <!-- -->:= <span class="lg-highlight-title lg-highlight-function">make</span>([]byte, <span class="lg-highlight-number">96</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">if</span> _<!-- -->, <!-- -->err := rand.<span class="lg-highlight-title lg-highlight-class">Read</span>(key); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> log.<span class="lg-highlight-title lg-highlight-class">Fatalf</span>(<span class="lg-highlight-string">"Unable to create a random 96 byte data key: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">if</span> err <!-- -->:<!-- -->= ioutil.<span class="lg-highlight-title lg-highlight-class">WriteFile</span>(<span class="lg-highlight-string">"master-key.txt"</span>, key, <span class="lg-highlight-number">0644</span>); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> log.<span class="lg-highlight-title lg-highlight-class">Fatalf</span>(<span class="lg-highlight-string">"Unable to write key to file: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> key</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-61-menu" aria-describedby="select-61-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-62" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r84:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r84:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r84:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r84:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_dx53kjblc" class="leafygreen-ui-38lglc" id="_bs1thrxd1" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"byte[] localMasterKeyWrite = new byte[96];\nnew SecureRandom().nextBytes(localMasterKeyWrite);\ntry (FileOutputStream stream = new FileOutputStream(\"master-key.txt\")) {\n stream.write(localMasterKeyWrite);\n}","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">byte[] localMasterKeyWrite = <span class="lg-highlight-keyword">new</span> byte[<span class="lg-highlight-number">96</span>];</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">SecureRandom</span>().<span class="lg-highlight-title lg-highlight-function">nextBytes</span>(localMasterKeyWrite);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">try</span> (<span class="lg-highlight-title lg-highlight-class">FileOutputStream</span> stream = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">FileOutputStream</span>(<span class="lg-highlight-string">"master-key.txt"</span>)) {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> stream.<span class="lg-highlight-title lg-highlight-function">write</span>(localMasterKeyWrite);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-64-menu" aria-describedby="select-64-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-65" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r85:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r85:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r85:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r85:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_6ba27cps8" class="leafygreen-ui-38lglc" id="_u00fqnm74" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"import os\n\npath = \"master-key.txt\"\nfile_bytes = os.urandom(96)\nwith open(path, \"wb\") as f:\n f.write(file_bytes)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">import</span> os</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">path = <span class="lg-highlight-string">"master-key.txt"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">file_bytes = os.<span class="lg-highlight-title lg-highlight-function">urandom</span>(<span class="lg-highlight-number">96</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">with</span> <span class="lg-highlight-title lg-highlight-function">open</span>(path, <span class="lg-highlight-string">"wb"</span>) <span class="lg-highlight-keyword">as</span> <span class="lg-highlight-attr">f</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> f.<span class="lg-highlight-title lg-highlight-function">write</span>(file_bytes)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-67-menu" aria-describedby="select-67-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-68" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r86:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r86:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r86:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r86:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Secure your Local Key File in Production </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> We recommend storing your Customer Master Keys in a remote <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Key_management#Key_management_system" rel="noopener noreferrer"> <span> Key Management System </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> ( <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> ). To learn how to use a remote <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> in your Queryable Encryption implementation, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/tutorials/#std-label-qe-tutorial-automatic-encryption"> Tutorials </a> guide. </p> <p class="leafygreen-ui-1kp3ins"> If you choose to use a local key provider in production, exercise great caution and do not store it on the file system. Consider injecting the key into your client application using a sidecar process, or use another approach that keeps the key secure. </p> </div> </div> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Generate a CMK from the Command Line </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Use the following command to generate a <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> from a Unix shell or PowerShell: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Unix shell: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"echo $(head -c 96 /dev/urandom | base64 | tr -d '\\n')","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">echo $(head -c 96 /dev/urandom | base64 | tr -d '\n')</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> PowerShell: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"$r=[byte[]]::new(64);$g=[System.Security.Cryptography.RandomNumberGenerator]::Create();$g.GetBytes($r);[Convert]::ToBase64String($r)"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" 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">$r=[byte[]]::new(64);$g=[System.Security.Cryptography.RandomNumberGenerator]::Create();$g.GetBytes($r);[Convert]::ToBase64String($r)</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> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Save the output of the preceding command to a file named <code class="leafygreen-ui-1l06pbn"> customer-master-key.txt </code> . </p> </div> </div> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> See: Complete Code </strong> </h3> <div class="leafygreen-ui-9mycqc"> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-12"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_yuwclcyfd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_686qu1k8o" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_9m427ub1v" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_3g5i95f3j" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_bro6hcvkn" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_xmzs46er7" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_paawcw41s" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_qcbhg0l4k" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_v5abgpnpb" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ijapdj9mc" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_smhch80u1" class="leafygreen-ui-38lglc" id="_hx2h66ens" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for making a Customer Master Key, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/dotnet/local/reader/CSFLE/MakeDataKey.cs" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_fz21p45ds" class="leafygreen-ui-38lglc" id="_6btu6r8g2" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for making a Customer Master Key, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/go/local/reader/make-data-key.go" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_vsevafmpw" class="leafygreen-ui-38lglc" id="_mvn3j0xne" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for making a Customer Master Key, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/java/local/reader/src/main/java/com/mongodb/csfle/MakeDataKey.java" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_dpq0vlt55" class="" id="_no9qf30x0" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for making a Customer Master Key, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/node/local/reader/make_data_key.js" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_sin04hgwd" class="leafygreen-ui-38lglc" id="_8s3ibenx1" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for making a Customer Master Key, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/python/local/reader/make_data_key.py" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> </div> </div> </div> </div> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create a Unique Index on your Key Vault collection <a class="headerlink leafygreen-ui-1kepx47" href="#create-a-unique-index-on-your-key-vault-collection" 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-unique-index-on-your-key-vault-collection"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Create a partial unique index on the <code class="leafygreen-ui-1l06pbn"> keyAltNames </code> field in your <code class="leafygreen-ui-1l06pbn"> encryption.__keyVault </code> namespace. This index should have a <code class="leafygreen-ui-1l06pbn"> partialFilterExpression </code> for documents where <code class="leafygreen-ui-1l06pbn"> keyAltNames </code> exists. </p> <p class="leafygreen-ui-1kp3ins"> Client-Side Field Level Encryption depends on server-enforced uniqueness of key alternate names. </p> <p class="leafygreen-ui-1kp3ins"> Select the tab corresponding to your preferred MongoDB driver: </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-14"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_wv4e23qgk" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_hqi41qxer" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_y40bdpp11" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_gl573rrwo" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_8rhylpgpt" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_fijiil3xo" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_ors018q7z" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_si9w3jffq" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_hpolpkfa0" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_3v5s5xfz0" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_c8kwnk5t7" class="leafygreen-ui-38lglc" id="_ba3c3jx9f" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var connectionString = \"&lt;your&gt;\";\nvar keyVaultNamespace = CollectionNamespace.FromFullName(\"encryption.__keyVault\");\nvar keyVaultClient = new MongoClient(connectionString);\nvar indexOptions = new CreateIndexOptions&lt;bsondocument&gt;();\nindexOptions.Unique = true;\nindexOptions.PartialFilterExpression = new BsonDocument { { \"keyAltNames\", new BsonDocument { { \"$exists\", new BsonBoolean(true) } } } };\nvar builder = Builders&lt;bsondocument&gt;.IndexKeys;\nvar indexKeysDocument = builder.Ascending(\"keyAltNames\");\nvar indexModel = new CreateIndexModel&lt;bsondocument&gt;(indexKeysDocument, indexOptions);\nvar keyVaultDatabase = keyVaultClient.GetDatabase(keyVaultNamespace.DatabaseNamespace.ToString());\n// Drop the Key Vault Collection in case you created this collection\n// in a previous run of this application. \nkeyVaultDatabase.DropCollection(keyVaultNamespace.CollectionName);\n// Drop the database storing your encrypted fields as all\n// the DEKs encrypting those fields were deleted in the preceding line.\nkeyVaultClient.GetDatabase(\"medicalRecords\").DropCollection(\"patients\");\nvar keyVaultCollection = keyVaultDatabase.GetCollection&lt;bsondocument&gt;(keyVaultNamespace.CollectionName.ToString());\nkeyVaultCollection.Indexes.CreateOne(indexModel);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> connectionString = <span class="lg-highlight-string">"&lt;Your MongoDB URI&gt;"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> keyVaultNamespace = <span class="lg-highlight-title lg-highlight-class">CollectionNamespace</span>.<span class="lg-highlight-title lg-highlight-class">FromFullName</span>(<span class="lg-highlight-string">"encryption.__keyVault"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> keyVaultClient = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(connectionString);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> indexOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">CreateIndexOptions</span>&lt;<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">indexOptions.<span class="lg-highlight-property">Unique</span> = <span class="lg-highlight-literal">true</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">indexOptions.<span class="lg-highlight-property">PartialFilterExpression</span> = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span> { { <span class="lg-highlight-string">"keyAltNames"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span> { { <span class="lg-highlight-string">"$exists"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonBoolean</span>(<span class="lg-highlight-literal">true</span>) } } } };</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> builder = <span class="lg-highlight-title lg-highlight-class">Builders</span>&lt;<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>&gt;.<span class="lg-highlight-property">IndexKeys</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> indexKeysDocument = builder.<span class="lg-highlight-title lg-highlight-class">Ascending</span>(<span class="lg-highlight-string">"keyAltNames"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> indexModel = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">CreateIndexModel</span>&lt;<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>&gt;(indexKeysDocument, indexOptions);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> keyVaultDatabase = keyVaultClient.<span class="lg-highlight-title lg-highlight-class">GetDatabase</span>(keyVaultNamespace.<span class="lg-highlight-property">DatabaseNamespace</span>.<span class="lg-highlight-title lg-highlight-class">ToString</span>());</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the Key </span><span class="lg-highlight-comment">Vault</span><span class="lg-highlight-comment"> Collection in case </span><span class="lg-highlight-comment">you created this collection</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> in a previous </span><span class="lg-highlight-comment">run of this application. </span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultDatabase.<span class="lg-highlight-title lg-highlight-class">DropCollection</span>(keyVaultNamespace.<span class="lg-highlight-property">CollectionName</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the database </span><span class="lg-highlight-comment">storing</span><span class="lg-highlight-comment"> your encrypted fields </span><span class="lg-highlight-comment">as all</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// the DEKs</span><span class="lg-highlight-comment"> encrypting those fields </span><span class="lg-highlight-comment">were</span><span class="lg-highlight-comment"> deleted in the </span><span class="lg-highlight-comment">preceding line.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultClient.<span class="lg-highlight-title lg-highlight-class">GetDatabase</span>(<span class="lg-highlight-string">"medicalRecords"</span>).<span class="lg-highlight-title lg-highlight-class">DropCollection</span>(<span class="lg-highlight-string">"patients"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> keyVaultCollection = keyVaultDatabase.<span class="lg-highlight-property">GetCollection</span>&lt;<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>&gt;(keyVaultNamespace.<span class="lg-highlight-property">CollectionName</span>.<span class="lg-highlight-title lg-highlight-class">ToString</span>());</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultCollection.<span class="lg-highlight-property">Indexes</span>.<span class="lg-highlight-title lg-highlight-class">CreateOne</span>(indexModel);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-72-menu" aria-describedby="select-72-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-73" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r87:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r87:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r87:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r87:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_qaou1ijki" class="leafygreen-ui-38lglc" id="_pni1wma6k" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"uri := \"&lt;your&gt;\"\nkeyVaultClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))\nif err != nil {\n\treturn fmt.Errorf(\"Connect error for regular client: %v\", err)\n}\ndefer func() {\n\t_ = keyVaultClient.Disconnect(context.TODO())\n}()\n\nkeyVaultColl := \"__keyVault\"\nkeyVaultDb := \"encryption\"\nkeyVaultNamespace := keyVaultDb + \".\" + keyVaultColl\nkeyVaultIndex := mongo.IndexModel{\n\tKeys: bson.D{{\"keyAltNames\", 1}},\n\tOptions: options.Index().\n\t\tSetUnique(true).\n\t\tSetPartialFilterExpression(bson.D{\n\t\t\t{\"keyAltNames\", bson.D{\n\t\t\t\t{\"$exists\", true},\n\t\t\t}},\n\t\t}),\n}\n// Drop the Key Vault Collection in case you created this collection\n// in a previous run of this application.\nif err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Drop(context.TODO()); err != nil {\n\tlog.Fatalf(\"Collection.Drop error: %v\", err)\n}\n// Drop the database storing your encrypted fields as all\n// the DEKs encrypting those fields were deleted in the preceding line.\nif err = keyVaultClient.Database(\"medicalRecords\").Collection(\"patients\").Drop(context.TODO()); err != nil {\n\tlog.Fatalf(\"Collection.Drop error: %v\", err)\n}\n_, err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Indexes().CreateOne(context.TODO(), keyVaultIndex)\nif err != nil {\n\tpanic(err)\n}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">uri <!-- -->:<!-- -->= <span class="lg-highlight-string">"&lt;Your MongoDB URI&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultClient<!-- -->, <!-- -->err := mongo.<span class="lg-highlight-title lg-highlight-class">Connect</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), options.<span class="lg-highlight-title lg-highlight-class">Client</span>().<span class="lg-highlight-title lg-highlight-class">ApplyURI</span>(uri))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"Connect error for regular client: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">defer <span class="lg-highlight-title lg-highlight-function">func</span>() {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _ = keyVaultClient.<span class="lg-highlight-title lg-highlight-class">Disconnect</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</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">keyVaultColl <!-- -->:<!-- -->= <span class="lg-highlight-string">"__keyVault"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultDb <!-- -->:<!-- -->= <span class="lg-highlight-string">"encryption"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultNamespace <!-- -->:<!-- -->= keyVaultDb + <span class="lg-highlight-string">"."</span> + keyVaultColl</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultIndex <!-- -->:<!-- -->= mongo.<span class="lg-highlight-property">IndexModel</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Keys</span>: bson.<span class="lg-highlight-property">D</span>{{<span class="lg-highlight-string">"keyAltNames"</span>, <span class="lg-highlight-number">1</span>}},</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Options</span>: options.<span class="lg-highlight-title lg-highlight-class">Index</span>().</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetUnique</span>(<span class="lg-highlight-literal">true</span>).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetPartialFilterExpression</span>(bson.<span class="lg-highlight-property">D</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {<span class="lg-highlight-string">"keyAltNames"</span>, bson.<span class="lg-highlight-property">D</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {<span class="lg-highlight-string">"$exists"</span>, <span class="lg-highlight-literal">true</span>},</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }},</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }),</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the Key </span><span class="lg-highlight-comment">Vault</span><span class="lg-highlight-comment"> Collection in case </span><span class="lg-highlight-comment">you created this collection</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> in a previous </span><span class="lg-highlight-comment">run of this application.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err = keyVaultClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(keyVaultDb).<span class="lg-highlight-title lg-highlight-class">Collection</span>(keyVaultColl).<span class="lg-highlight-title lg-highlight-class">Drop</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>()); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> log.<span class="lg-highlight-title lg-highlight-class">Fatalf</span>(<span class="lg-highlight-string">"Collection.Drop error: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the database </span><span class="lg-highlight-comment">storing</span><span class="lg-highlight-comment"> your encrypted fields </span><span class="lg-highlight-comment">as all</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// the DEKs</span><span class="lg-highlight-comment"> encrypting those fields </span><span class="lg-highlight-comment">were</span><span class="lg-highlight-comment"> deleted in the </span><span class="lg-highlight-comment">preceding line.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err = keyVaultClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(<span class="lg-highlight-string">"medicalRecords"</span>).<span class="lg-highlight-title lg-highlight-class">Collection</span>(<span class="lg-highlight-string">"patients"</span>).<span class="lg-highlight-title lg-highlight-class">Drop</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>()); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> log.<span class="lg-highlight-title lg-highlight-class">Fatalf</span>(<span class="lg-highlight-string">"Collection.Drop error: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">_, err = keyVaultClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(keyVaultDb).<span class="lg-highlight-title lg-highlight-class">Collection</span>(keyVaultColl).<span class="lg-highlight-title lg-highlight-class">Indexes</span>().<span class="lg-highlight-title lg-highlight-class">CreateOne</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), keyVaultIndex)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-75-menu" aria-describedby="select-75-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-76" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r88:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r88:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r88:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r88:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_6iws4l1c5" class="leafygreen-ui-38lglc" id="_ok8irr33b" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"String connectionString = \"&lt;your&gt;\";\nString keyVaultDb = \"encryption\";\nString keyVaultColl = \"__keyVault\";\nString keyVaultNamespace = keyVaultDb + \".\" + keyVaultColl;\nMongoClient keyVaultClient = MongoClients.create(connectionString);\n\n// Drop the Key Vault Collection in case you created this collection\n// in a previous run of this application.\nkeyVaultClient.getDatabase(keyVaultDb).getCollection(keyVaultColl).drop();\n// Drop the database storing your encrypted fields as all\n// the DEKs encrypting those fields were deleted in the preceding line.\nkeyVaultClient.getDatabase(\"medicalRecords\").getCollection(\"patients\").drop();\n\n\nMongoCollection keyVaultCollection = keyVaultClient.getDatabase(keyVaultDb).getCollection(keyVaultColl);\nIndexOptions indexOpts = new IndexOptions().partialFilterExpression(new BsonDocument(\"keyAltNames\", new BsonDocument(\"$exists\", new BsonBoolean(true) ))).unique(true);\nkeyVaultCollection.createIndex(new BsonDocument(\"keyAltNames\", new BsonInt32(1)), indexOpts);\nkeyVaultClient.close();","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">String</span> connectionString = <span class="lg-highlight-string">"&lt;Your MongoDB URI&gt;"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> keyVaultDb = <span class="lg-highlight-string">"encryption"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> keyVaultColl = <span class="lg-highlight-string">"__keyVault"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> keyVaultNamespace = keyVaultDb + <span class="lg-highlight-string">"."</span> + keyVaultColl;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">MongoClient</span> keyVaultClient = <span class="lg-highlight-title lg-highlight-class">MongoClients</span>.<span class="lg-highlight-title lg-highlight-function">create</span>(connectionString);</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-comment">//</span><span class="lg-highlight-comment"> Drop the Key </span><span class="lg-highlight-comment">Vault</span><span class="lg-highlight-comment"> Collection in case </span><span class="lg-highlight-comment">you created this collection</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> in a previous </span><span class="lg-highlight-comment">run of this application.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultClient.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(keyVaultDb).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(keyVaultColl).<span class="lg-highlight-title lg-highlight-function">drop</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the database </span><span class="lg-highlight-comment">storing</span><span class="lg-highlight-comment"> your encrypted fields </span><span class="lg-highlight-comment">as all</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// the DEKs</span><span class="lg-highlight-comment"> encrypting those fields </span><span class="lg-highlight-comment">were</span><span class="lg-highlight-comment"> deleted in the </span><span class="lg-highlight-comment">preceding line.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultClient.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(<span class="lg-highlight-string">"medicalRecords"</span>).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(<span class="lg-highlight-string">"patients"</span>).<span class="lg-highlight-title lg-highlight-function">drop</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></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">MongoCollection</span> keyVaultCollection = keyVaultClient.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(keyVaultDb).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(keyVaultColl);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">IndexOptions</span> indexOpts = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">IndexOptions</span>().<span class="lg-highlight-title lg-highlight-function">partialFilterExpression</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"keyAltNames"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"$exists"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonBoolean</span>(<span class="lg-highlight-literal">true</span>) ))).<span class="lg-highlight-title lg-highlight-function">unique</span>(<span class="lg-highlight-literal">true</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultCollection.<span class="lg-highlight-title lg-highlight-function">createIndex</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"keyAltNames"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonInt32</span>(<span class="lg-highlight-number">1</span>)), indexOpts);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultClient.<span class="lg-highlight-title lg-highlight-function">close</span>();</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-78-menu" aria-describedby="select-78-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-79" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r89:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r89:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r89:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r89:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_dpxz03q3q" class="" id="_wonixovpa" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const uri = \"&lt;your&gt;\";\nconst keyVaultDatabase = \"encryption\";\nconst keyVaultCollection = \"__keyVault\";\nconst keyVaultNamespace = `${keyVaultDatabase}.${keyVaultCollection}`;\nconst keyVaultClient = new MongoClient(uri);\nawait keyVaultClient.connect();\nconst keyVaultDB = keyVaultClient.db(keyVaultDatabase);\n// Drop the Key Vault Collection in case you created this collection\n// in a previous run of this application.\nawait keyVaultDB.dropDatabase();\n// Drop the database storing your encrypted fields as all\n// the DEKs encrypting those fields were deleted in the preceding line.\nawait keyVaultClient.db(\"medicalRecords\").dropDatabase();\nconst keyVaultColl = keyVaultDB.collection(keyVaultCollection);\nawait keyVaultColl.createIndex(\n { keyAltNames: 1 },\n {\n unique: true,\n partialFilterExpression: { keyAltNames: { $exists: true } },\n }\n);","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> uri <!-- -->= <span class="lg-highlight-string">"&lt;Your Connection String&gt;"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultDatabase <!-- -->= <span class="lg-highlight-string">"encryption"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultCollection <!-- -->= <span class="lg-highlight-string">"__keyVault"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultNamespace <!-- -->= <span class="lg-highlight-string">`</span><span class="lg-highlight-subst lg-highlight-string">${keyVaultDatabase}</span><span class="lg-highlight-string">.</span><span class="lg-highlight-subst lg-highlight-string">${keyVaultCollection}</span><span class="lg-highlight-string">`</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultClient <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(<!-- -->uri)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> keyVaultClient.<span class="lg-highlight-title lg-highlight-function">connect</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultDB <!-- -->= <!-- -->keyVaultClient.<span class="lg-highlight-title lg-highlight-function">db</span>(<!-- -->keyVaultDatabase)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the Key </span><span class="lg-highlight-comment">Vault</span><span class="lg-highlight-comment"> Collection in case </span><span class="lg-highlight-comment">you created this collection</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> in a previous </span><span class="lg-highlight-comment">run of this application.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> keyVaultDB.<span class="lg-highlight-title lg-highlight-function">dropDatabase</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the database </span><span class="lg-highlight-comment">storing</span><span class="lg-highlight-comment"> your encrypted fields </span><span class="lg-highlight-comment">as all</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// the DEKs</span><span class="lg-highlight-comment"> encrypting those fields </span><span class="lg-highlight-comment">were</span><span class="lg-highlight-comment"> deleted in the </span><span class="lg-highlight-comment">preceding line.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> keyVaultClient.<span class="lg-highlight-title lg-highlight-function">db</span>(<span class="lg-highlight-string">"medicalRecords"</span>).<span class="lg-highlight-title lg-highlight-function">dropDatabase</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultColl <!-- -->= <!-- -->keyVaultDB.<span class="lg-highlight-title lg-highlight-function">collection</span>(<!-- -->keyVaultCollection)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> keyVaultColl.<span class="lg-highlight-title lg-highlight-function">createIndex</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">keyAltNames</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"> <span class="lg-highlight-attr">unique</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">partialFilterExpression</span>: <!-- -->{ <span class="lg-highlight-attr">keyAltNames</span>: <!-- -->{ <span class="lg-highlight-attr">$exists</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-81-menu" aria-describedby="select-81-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-82" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8a:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8a:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8a:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8a:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_t4ksmwr56" class="leafygreen-ui-38lglc" id="_vdvpp6alm" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"connection_string = \"&lt;your&gt;\"\n\nkey_vault_coll = \"__keyVault\"\nkey_vault_db = \"encryption\"\nkey_vault_namespace = f\"{key_vault_db}.{key_vault_coll}\"\nkey_vault_client = MongoClient(connection_string)\n# Drop the Key Vault Collection in case you created this collection\n# in a previous run of this application.\nkey_vault_client.drop_database(key_vault_db)\n# Drop the database storing your encrypted fields as all\n# the DEKs encrypting those fields were deleted in the preceding line.\nkey_vault_client[\"medicalRecords\"].drop_collection(\"patients\")\nkey_vault_client[key_vault_db][key_vault_coll].create_index(\n [(\"keyAltNames\", ASCENDING)],\n unique=True,\n partialFilterExpression={\"keyAltNames\": {\"$exists\": True}},\n)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">connection_string = <span class="lg-highlight-string">"&lt;your connection string here&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_coll = <span class="lg-highlight-string">"__keyVault"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_db = <span class="lg-highlight-string">"encryption"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_namespace = f<span class="lg-highlight-string">"{key_vault_db}.{key_vault_coll}"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_client = <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(connection_string)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"># <span class="lg-highlight-title lg-highlight-class">Drop</span> the <span class="lg-highlight-title lg-highlight-class">Key</span> <span class="lg-highlight-title lg-highlight-class">Vault</span> <span class="lg-highlight-title lg-highlight-class">Collection</span> <span class="lg-highlight-keyword">in</span> <span class="lg-highlight-keyword">case</span> you created <span class="lg-highlight-variable lg-highlight-language">this</span> collection</td></tr><tr class=""><td class="leafygreen-ui-7razhx"># <span class="lg-highlight-keyword">in</span> a previous run <span class="lg-highlight-keyword">of</span> <span class="lg-highlight-variable lg-highlight-language">this</span> application.</td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_client.<span class="lg-highlight-title lg-highlight-function">drop_database</span>(key_vault_db)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"># <span class="lg-highlight-title lg-highlight-class">Drop</span> the database storing your encrypted fields <span class="lg-highlight-keyword">as</span> all</td></tr><tr class=""><td class="leafygreen-ui-7razhx"># the <span class="lg-highlight-title lg-highlight-class">DEKs</span> encrypting those fields were deleted <span class="lg-highlight-keyword">in</span> the preceding line.</td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_client[<span class="lg-highlight-string">"medicalRecords"</span>].<span class="lg-highlight-title lg-highlight-function">drop_collection</span>(<span class="lg-highlight-string">"patients"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_client[key_vault_db][key_vault_coll].<span class="lg-highlight-title lg-highlight-function">create_index</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> [(<span class="lg-highlight-string">"keyAltNames"</span>, <span class="lg-highlight-variable lg-highlight-constant">ASCENDING</span>)],</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> unique=<span class="lg-highlight-title lg-highlight-class">True</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> partialFilterExpression={<span class="lg-highlight-string">"keyAltNames"</span>: {<span class="lg-highlight-string">"$exists"</span>: <span class="lg-highlight-title lg-highlight-class">True</span>}},</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-84-menu" aria-describedby="select-84-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-85" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8b:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8b:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8b:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8b:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create a Data Encryption Key <a class="headerlink leafygreen-ui-1kepx47" href="#create-a-data-encryption-key" 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-data-encryption-key"> </div> </a> </h3> <span class="leafygreen-ui-1qnjd6d" id="std-label-csfle-quick-start-create-dek"> </span> <ol class="leafygreen-ui-rioki0" type="a"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Read the Customer Master Key and Specify KMS Provider Settings </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-field-level-encryption-data-key-create"> </span> <p class="leafygreen-ui-1kp3ins"> Retrieve the contents of the Customer Master Key file that you generated in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-csfle-quick-start-create-master-key" target="_self"> <span> Create a Customer Master Key </span> </a> step of this guide. </p> <p class="leafygreen-ui-1kp3ins"> Use the <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> value in your KMS provider settings. The client uses these settings to discover the <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> . As you are using the Local Key Provider, set the provider name to <code class="leafygreen-ui-1l06pbn"> local </code> . </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-16"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_rh7fo791z" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_pqi0sj0hb" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_vnokvrjid" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_sfejgqu2z" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_z0b97edda" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_86kw92r7j" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_p4giluk96" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_fl43x4yhw" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_dq2itwa5l" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_a1syh3mmr" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_hm4qgryjn" class="leafygreen-ui-38lglc" id="_6xlxohy2w" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var kmsProviders = new Dictionary&lt;string,&gt;&gt;();\nvar provider = \"local\";\nstring localMasterKeyBase64Read = File.ReadAllText(\"master-key.txt\");\nvar localMasterKeyBytes = Convert.FromBase64String(localMasterKeyBase64Read);\nvar localOptions = new Dictionary&lt;string,&gt;\n{\n { \"key\", localMasterKeyBytes }\n};\nkmsProviders.Add(\"local\", localOptions);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> kmsProviders = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span>&lt;string, <span class="lg-highlight-title lg-highlight-class">IReadOnlyDictionary</span>&lt;string, object&gt;&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> provider = <span class="lg-highlight-string">"local"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">string localMasterKeyBase64Read = <span class="lg-highlight-title lg-highlight-class">File</span>.<span class="lg-highlight-title lg-highlight-class">ReadAllText</span>(<span class="lg-highlight-string">"master-key.txt"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> localMasterKeyBytes = <span class="lg-highlight-title lg-highlight-class">Convert</span>.<span class="lg-highlight-title lg-highlight-class">FromBase64String</span>(localMasterKeyBase64Read);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> localOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span>&lt;string, object&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"key"</span>, localMasterKeyBytes }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">};</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders.<span class="lg-highlight-title lg-highlight-class">Add</span>(<span class="lg-highlight-string">"local"</span>, localOptions);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-87-menu" aria-describedby="select-87-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-88" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8c:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8c:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8c:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8c:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_brbamulhd" class="leafygreen-ui-38lglc" id="_pb00sfthx" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"key, err := ioutil.ReadFile(\"master-key.txt\")\nif err != nil {\n\tlog.Fatalf(\"Could not read the key from master-key.txt: %v\", err)\n}\nprovider := \"local\"\nkmsProviders := map[string]map[string]interface{}{\"local\": {\"key\": key}}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">key<!-- -->, <!-- -->err := ioutil.<span class="lg-highlight-title lg-highlight-class">ReadFile</span>(<span class="lg-highlight-string">"master-key.txt"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> log.<span class="lg-highlight-title lg-highlight-class">Fatalf</span>(<span class="lg-highlight-string">"Could not read the key from master-key.txt: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">provider <!-- -->:<!-- -->= <span class="lg-highlight-string">"local"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders <!-- -->:<!-- -->= map[string]map[string]interface{}{<span class="lg-highlight-string">"local"</span>: {<span class="lg-highlight-string">"key"</span>: key}}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-90-menu" aria-describedby="select-90-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-91" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8d:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8d:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8d:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8d:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_u0mpl2p1t" class="leafygreen-ui-38lglc" id="_f06pdxdlp" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"String kmsProvider = \"local\";\nString path = \"master-key.txt\";\n\nbyte[] localMasterKeyRead = new byte[96];\n\ntry (FileInputStream fis = new FileInputStream(path)) {\n if (fis.read(localMasterKeyRead) &lt; 96)\n throw new Exception(\"Expected to read 96 bytes from file\");\n}\nMap&lt;string,&gt; keyMap = new HashMap&lt;string,&gt;();\nkeyMap.put(\"key\", localMasterKeyRead);\n\nMap&lt;string,&gt;&gt; kmsProviders = new HashMap&lt;string,&gt;&gt;();\nkmsProviders.put(\"local\", keyMap);","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">String</span> kmsProvider = <span class="lg-highlight-string">"local"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> path = <span class="lg-highlight-string">"master-key.txt"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">byte[] localMasterKeyRead = <span class="lg-highlight-keyword">new</span> byte[<span class="lg-highlight-number">96</span>];</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-keyword">try</span> (<span class="lg-highlight-title lg-highlight-class">FileInputStream</span> fis = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">FileInputStream</span>(path)) {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">if</span> (fis.<span class="lg-highlight-title lg-highlight-function">read</span>(localMasterKeyRead) &lt; <span class="lg-highlight-number">96</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">throw</span> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Exception</span>(<span class="lg-highlight-string">"Expected to read 96 bytes from file"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt; keyMap = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyMap.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"key"</span>, localMasterKeyRead);</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">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt;&gt; kmsProviders = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt;&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"local"</span>, keyMap);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-93-menu" aria-describedby="select-93-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-94" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8e:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8e:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8e:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8e:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_lt7x79lsh" class="" id="_f1vv87vfo" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const provider = \"local\";\nconst path = \"./master-key.txt\";\nconst localMasterKey = fs.readFileSync(path);\nconst kmsProviders = {\n local: {\n key: localMasterKey,\n },\n};","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> provider <!-- -->= <span class="lg-highlight-string">"local"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> path <!-- -->= <span class="lg-highlight-string">"./master-key.txt"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> localMasterKey <!-- -->= <!-- -->fs.<span class="lg-highlight-title lg-highlight-function">readFileSync</span>(<!-- -->path)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> kmsProviders <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">local</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->localMasterKey<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-96-menu" aria-describedby="select-96-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-97" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8f:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8f:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8f:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8f:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_rdf9bybie" class="leafygreen-ui-38lglc" id="_lbztbeymn" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"path = \"./master-key.txt\"\nwith open(path, \"rb\") as f:\n local_master_key = f.read()\nkms_providers = {\n \"local\": {\n \"key\": local_master_key # local_master_key variable from the previous step\n },\n}","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">path = <span class="lg-highlight-string">"./master-key.txt"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">with</span> <span class="lg-highlight-title lg-highlight-function">open</span>(path, <span class="lg-highlight-string">"rb"</span>) <span class="lg-highlight-keyword">as</span> <span class="lg-highlight-attr">f</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> local_master_key = f.<span class="lg-highlight-title lg-highlight-function">read</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kms_providers = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"local"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"key"</span>: local_master_key # local_master_key variable <span class="lg-highlight-keyword">from</span> the previous step</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-99-menu" aria-describedby="select-99-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-100" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8g:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8g:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8g:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8g:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create a Data Encryption Key </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-csfle-local-create-dek"> </span> <p class="leafygreen-ui-1kp3ins"> Construct a client with your MongoDB connection string and Key Vault collection namespace, and create a Data Encryption Key: </p> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Key Vault Collection Namespace Permissions </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> To complete this tutorial, the database user your application uses to connect to MongoDB must have <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-dbAdmin"> <code class="leafygreen-ui-1l06pbn"> dbAdmin </code> </a> permissions on the following namespaces: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> encryption.__keyVault </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> medicalRecords </code> database </p> </li> </ul> </div> </div> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-17"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_7t02cozx3" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ou4h85kqk" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_09k4ngye1" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_v3i3lr8t3" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_tqemtm0b6" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_wnjhfcibu" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_w9fsy9xaa" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_437h7itz8" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_s0ur9chm3" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ectiyrlmx" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_z9x3pke64" class="leafygreen-ui-38lglc" id="_xeunk5lm9" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var clientEncryptionOptions = new ClientEncryptionOptions(\n keyVaultClient: keyVaultClient,\n keyVaultNamespace: keyVaultNamespace,\n kmsProviders: kmsProviders\n );\n\nvar clientEncryption = new ClientEncryption(clientEncryptionOptions);\nvar dataKeyOptions = new DataKeyOptions();\nvar dataKeyId = clientEncryption.CreateDataKey(provider, dataKeyOptions, CancellationToken.None);\nvar dataKeyIdBase64 = Convert.ToBase64String(GuidConverter.ToBytes(dataKeyId, GuidRepresentation.Standard));\nConsole.WriteLine($\"DataKeyId [base64]: {dataKeyIdBase64}\");","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> clientEncryptionOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ClientEncryptionOptions</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultClient</span>: keyVaultClient,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultNamespace</span>: keyVaultNamespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmsProviders</span>: kmsProviders</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"><span class="lg-highlight-keyword">var</span> clientEncryption = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>(clientEncryptionOptions);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> dataKeyOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">DataKeyOptions</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> dataKeyId = clientEncryption.<span class="lg-highlight-title lg-highlight-class">CreateDataKey</span>(provider, dataKeyOptions, <span class="lg-highlight-title lg-highlight-class">CancellationToken</span>.<span class="lg-highlight-property">None</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> dataKeyIdBase64 = <span class="lg-highlight-title lg-highlight-class">Convert</span>.<span class="lg-highlight-title lg-highlight-class">ToBase64String</span>(<span class="lg-highlight-title lg-highlight-class">GuidConverter</span>.<span class="lg-highlight-title lg-highlight-class">ToBytes</span>(dataKeyId, <span class="lg-highlight-title lg-highlight-class">GuidRepresentation</span>.<span class="lg-highlight-property">Standard</span>));</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>($<span class="lg-highlight-string">"DataKeyId [base64]: {dataKeyIdBase64}"</span>);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-102-menu" aria-describedby="select-102-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-103" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8h:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8h:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8h:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8h:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_1npaky65r" class="leafygreen-ui-38lglc" id="_s153r1lqf" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"clientEncryptionOpts := options.ClientEncryption().SetKeyVaultNamespace(keyVaultNamespace).\n\tSetKmsProviders(kmsProviders)\nclientEnc, err := mongo.NewClientEncryption(keyVaultClient, clientEncryptionOpts)\nif err != nil {\n\treturn fmt.Errorf(\"NewClientEncryption error %v\", err)\n}\ndefer func() {\n\t_ = clientEnc.Close(context.TODO())\n}()\ndataKeyOpts := options.DataKey()\n\ndataKeyID, err := clientEnc.CreateDataKey(context.TODO(), provider, dataKeyOpts)\nif err != nil {\n\treturn fmt.Errorf(\"create data key error %v\", err)\n}\n\nfmt.Printf(\"DataKeyId [base64]: %s\\n\", base64.StdEncoding.EncodeToString(dataKeyID.Data))","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">clientEncryptionOpts <!-- -->:<!-- -->= options.<span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>().<span class="lg-highlight-title lg-highlight-class">SetKeyVaultNamespace</span>(keyVaultNamespace).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKmsProviders</span>(kmsProviders)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">clientEnc<!-- -->, <!-- -->err := mongo.<span class="lg-highlight-title lg-highlight-class">NewClientEncryption</span>(keyVaultClient, clientEncryptionOpts)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"NewClientEncryption error %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">defer <span class="lg-highlight-title lg-highlight-function">func</span>() {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _ = clientEnc.<span class="lg-highlight-title lg-highlight-class">Close</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}()</td></tr><tr class=""><td class="leafygreen-ui-7razhx">dataKeyOpts <!-- -->:<!-- -->= options.<span class="lg-highlight-title lg-highlight-class">DataKey</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">dataKeyID<!-- -->, <!-- -->err := clientEnc.<span class="lg-highlight-title lg-highlight-class">CreateDataKey</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), provider, dataKeyOpts)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"create data key error %v"</span>, err)</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">fmt.<span class="lg-highlight-title lg-highlight-class">Printf</span>(<span class="lg-highlight-string">"DataKeyId [base64]: %s</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>, base64.<span class="lg-highlight-property">StdEncoding</span>.<span class="lg-highlight-title lg-highlight-class">EncodeToString</span>(dataKeyID.<span class="lg-highlight-property">Data</span>))</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-105-menu" aria-describedby="select-105-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-106" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8i:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8i:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8i:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8i:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_j5wjchfrv" class="leafygreen-ui-38lglc" id="_pt7ye3gec" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder()\n .keyVaultMongoClientSettings(MongoClientSettings.builder()\n .applyConnectionString(new ConnectionString(connectionString))\n .build())\n .keyVaultNamespace(keyVaultNamespace)\n .kmsProviders(kmsProviders)\n .build();\n\nMongoClient regularClient = MongoClients.create(connectionString);\n\nClientEncryption clientEncryption = ClientEncryptions.create(clientEncryptionSettings);\nBsonBinary dataKeyId = clientEncryption.createDataKey(kmsProvider, new DataKeyOptions());\nString base64DataKeyId = Base64.getEncoder().encodeToString(dataKeyId.getData());\nSystem.out.println(\"DataKeyId [base64]: \" + base64DataKeyId);\nclientEncryption.close();","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">ClientEncryptionSettings</span> clientEncryptionSettings = <span class="lg-highlight-title lg-highlight-class">ClientEncryptionSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">keyVaultMongoClientSettings</span>(<span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">applyConnectionString</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ConnectionString</span>(connectionString))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">keyVaultNamespace</span>(keyVaultNamespace)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">kmsProviders</span>(kmsProviders)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>();</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">MongoClient</span> regularClient = <span class="lg-highlight-title lg-highlight-class">MongoClients</span>.<span class="lg-highlight-title lg-highlight-function">create</span>(connectionString);</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">ClientEncryption</span> clientEncryption = <span class="lg-highlight-title lg-highlight-class">ClientEncryptions</span>.<span class="lg-highlight-title lg-highlight-function">create</span>(clientEncryptionSettings);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">BsonBinary</span> dataKeyId = clientEncryption.<span class="lg-highlight-title lg-highlight-function">createDataKey</span>(kmsProvider, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">DataKeyOptions</span>());</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> base64DataKeyId = <span class="lg-highlight-title lg-highlight-class">Base64</span>.<span class="lg-highlight-title lg-highlight-function">getEncoder</span>().<span class="lg-highlight-title lg-highlight-function">encodeToString</span>(dataKeyId.<span class="lg-highlight-title lg-highlight-function">getData</span>());</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">System</span>.<span class="lg-highlight-property">out</span>.<span class="lg-highlight-title lg-highlight-function">println</span>(<span class="lg-highlight-string">"DataKeyId [base64]: "</span> + base64DataKeyId);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">clientEncryption.<span class="lg-highlight-title lg-highlight-function">close</span>();</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-108-menu" aria-describedby="select-108-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-109" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8j:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8j:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8j:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8j:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_dq8umocri" class="" id="_qql8emxru" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const client = new MongoClient(uri);\nawait client.connect();\n\nconst encryption = new ClientEncryption(client, {\n keyVaultNamespace,\n kmsProviders,\n});\nconst key = await encryption.createDataKey(provider);\nconsole.log(\"DataKeyId [base64]: \", key.toString(\"base64\"));\nawait keyVaultClient.close();\nawait client.close();","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> client <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(<!-- -->uri)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> client.<span class="lg-highlight-title lg-highlight-function">connect</span>(<!-- -->)<!-- -->;</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-keyword">const</span> encryption <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>(<!-- -->client<!-- -->, <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->keyVaultNamespace<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->kmsProviders<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">})<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> key <!-- -->= <span class="lg-highlight-keyword">await</span> encryption.<span class="lg-highlight-title lg-highlight-function">createDataKey</span>(<!-- -->provider)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(<span class="lg-highlight-string">"DataKeyId [base64]: "</span>, <!-- -->key.<span class="lg-highlight-title lg-highlight-function">toString</span>(<span class="lg-highlight-string">"base64"</span>))<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> keyVaultClient.<span class="lg-highlight-title lg-highlight-function">close</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> client.<span class="lg-highlight-title lg-highlight-function">close</span>(<!-- -->)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-111-menu" aria-describedby="select-111-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-112" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8k:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8k:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8k:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8k:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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 class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Import ClientEncryption </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> When using the Node.js driver v6.0 and later, you must import <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> from <code class="leafygreen-ui-1l06pbn"> mongodb </code> . </p> <p class="leafygreen-ui-1kp3ins"> For earlier driver versions, import <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> from <code class="leafygreen-ui-1l06pbn"> mongodb-client-encryption </code> . </p> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_bq0e0ecba" class="leafygreen-ui-38lglc" id="_8mg1mmrys" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"key_vault_database = \"encryption\"\nkey_vault_collection = \"__keyVault\"\nkey_vault_namespace = f\"{key_vault_database}.{key_vault_collection}\"\n\nclient = MongoClient(connection_string)\nclient_encryption = ClientEncryption(\n kms_providers, # pass in the kms_providers variable from the previous step\n key_vault_namespace,\n client,\n CodecOptions(uuid_representation=STANDARD),\n)\ndata_key_id = client_encryption.create_data_key(\"local\")\n\nbase_64_data_key_id = base64.b64encode(data_key_id)\nprint(\"DataKeyId [base64]: \", base_64_data_key_id)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">key_vault_database = <span class="lg-highlight-string">"encryption"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_collection = <span class="lg-highlight-string">"__keyVault"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_namespace = f<span class="lg-highlight-string">"{key_vault_database}.{key_vault_collection}"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">client = <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(connection_string)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">client_encryption = <span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kms_providers, # pass <span class="lg-highlight-keyword">in</span> the kms_providers variable <span class="lg-highlight-keyword">from</span> the previous step</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> key_vault_namespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> client,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">CodecOptions</span>(uuid_representation=<span class="lg-highlight-variable lg-highlight-constant">STANDARD</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">data_key_id = client_encryption.<span class="lg-highlight-title lg-highlight-function">create_data_key</span>(<span class="lg-highlight-string">"local"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">base_64_data_key_id = base64.<span class="lg-highlight-title lg-highlight-function">b64encode</span>(data_key_id)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-function">print</span>(<span class="lg-highlight-string">"DataKeyId [base64]: "</span>, base_64_data_key_id)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-114-menu" aria-describedby="select-114-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-115" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8l:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8l:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8l:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8l:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <p class="leafygreen-ui-1kp3ins"> The output from the code above should resemble the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"DataKeyId [base64]: 3k13WkSZSLy7kwAAP4HDyQ=="} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">DataKeyId [base64]: 3k13WkSZSLy7kwAAP4HDyQ==</td></tr></tbody></table></code></pre> </div> </div> </div> </li> </ol> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> See: Complete Code </strong> </h3> <div class="leafygreen-ui-9mycqc"> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-18"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_suud0aerg" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_w712o1ce3" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_vzq2kssqy" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_4z8v7e4cg" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_43l3yz3be" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_abxf6484h" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_6ri6as4xk" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_7rqjz1ib1" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_kxdbkfnkt" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_oo9uz8cj6" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_sa2gx8xjo" class="leafygreen-ui-38lglc" id="_h2tj9yb6n" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for making a Data Encryption Key, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/dotnet/local/reader/CSFLE/MakeDataKey.cs" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_tgw5pnobz" class="leafygreen-ui-38lglc" id="_rkounofyo" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for making a Data Encryption Key, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/go/local/reader/make-data-key.go" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_e102o76nv" class="leafygreen-ui-38lglc" id="_4vj43pzyo" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for making a Data Encryption Key, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/java/local/reader/src/main/java/com/mongodb/csfle/MakeDataKey.java" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_8ccyjv6w8" class="" id="_6smcc4j3d" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for making a Data Encryption Key, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/node/local/reader/make_data_key.js" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_guwrz424w" class="leafygreen-ui-38lglc" id="_2nms6tevz" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for making a Data Encryption Key, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/python/local/reader/make_data_key.py" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> </div> </div> </div> </div> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Configure the MongoClient <a class="headerlink leafygreen-ui-1kepx47" href="#configure-the-mongoclient" 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="configure-the-mongoclient"> </div> </a> </h3> <span class="leafygreen-ui-1qnjd6d" id="std-label-field-level-encryption-data-key-retrieve"> </span> <ol class="leafygreen-ui-rioki0" type="a"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specify the Key Vault Collection Namespace </p> <p class="leafygreen-ui-1kp3ins"> Specify <code class="leafygreen-ui-1l06pbn"> encryption.__keyVault </code> as the Key Vault collection namespace. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-20"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_pdflw8zmd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_2a8xnwkgf" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_rbl2gjwlw" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_72fzrl8nl" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_wva3k50zx" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_xozd0ev1s" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_3zuhwpypl" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_9ho4cp4oe" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_o41p4fk2v" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_jjjl7xfgz" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_fexmpxl97" class="leafygreen-ui-38lglc" id="_dvu8ypyfy" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var keyVaultNamespace = CollectionNamespace.FromFullName(\"encryption.__keyVault\");","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-keyword">var</span> keyVaultNamespace = <span class="lg-highlight-title lg-highlight-class">CollectionNamespace</span>.<span class="lg-highlight-title lg-highlight-class">FromFullName</span>(<span class="lg-highlight-string">"encryption.__keyVault"</span>);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-117-menu" aria-describedby="select-117-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-118" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8m:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8m:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8m:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8m:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_dlvszvj3l" class="leafygreen-ui-38lglc" id="_r3zt9r7gw" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"keyVaultNamespace := \"encryption.__keyVault\"","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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">keyVaultNamespace <!-- -->:<!-- -->= <span class="lg-highlight-string">"encryption.__keyVault"</span></td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-120-menu" aria-describedby="select-120-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-121" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8n:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8n:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8n:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8n:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_la1895g4x" class="leafygreen-ui-38lglc" id="_ntq2yvrou" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"String keyVaultNamespace = \"encryption.__keyVault\";","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-title lg-highlight-class">String</span> keyVaultNamespace = <span class="lg-highlight-string">"encryption.__keyVault"</span>;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-123-menu" aria-describedby="select-123-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-124" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8o:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8o:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8o:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8o:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_whvnuxa5y" class="" id="_3q4mcl99x" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const keyVaultNamespace = \"encryption.__keyVault\";","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-keyword">const</span> keyVaultNamespace <!-- -->= <span class="lg-highlight-string">"encryption.__keyVault"</span>;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-126-menu" aria-describedby="select-126-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-127" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8p:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8p:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8p:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8p:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_u53wv3ncv" class="leafygreen-ui-38lglc" id="_lkjyjm436" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"key_vault_namespace = \"encryption.__keyVault\"","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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">key_vault_namespace = <span class="lg-highlight-string">"encryption.__keyVault"</span></td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-129-menu" aria-describedby="select-129-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-130" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8q:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8q:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8q:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8q:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specify the Local Customer Master Key </p> <p class="leafygreen-ui-1kp3ins"> Specify the KMS provider and specify your key inline: </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-21"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_n24c8cgg0" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_31rrrusbh" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_mmiydfjdw" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_4q1ihnza0" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_llwczx5gs" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_yxf0d0rgr" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_m3u3mhpwl" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_4e8jussvs" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_z6assa7gd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_l26ucvn0z" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_jjvrbxo7t" class="leafygreen-ui-38lglc" id="_bh80l9a56" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var kmsProviders = new Dictionary&lt;string,&gt;&gt;();\nvar provider = \"local\";\nvar localMasterKeyPath = \"master-key.txt\";\nstring localMasterKeyBase64Read = File.ReadAllText(localMasterKeyPath);\nvar localMasterKeyBytes = Convert.FromBase64String(localMasterKeyBase64Read);\nvar localOptions = new Dictionary&lt;string,&gt;\n{\n { \"key\", localMasterKeyBytes }\n};\nkmsProviders.Add(provider, localOptions);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> kmsProviders = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span>&lt;string, <span class="lg-highlight-title lg-highlight-class">IReadOnlyDictionary</span>&lt;string, object&gt;&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> provider = <span class="lg-highlight-string">"local"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> localMasterKeyPath = <span class="lg-highlight-string">"master-key.txt"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">string localMasterKeyBase64Read = <span class="lg-highlight-title lg-highlight-class">File</span>.<span class="lg-highlight-title lg-highlight-class">ReadAllText</span>(localMasterKeyPath);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> localMasterKeyBytes = <span class="lg-highlight-title lg-highlight-class">Convert</span>.<span class="lg-highlight-title lg-highlight-class">FromBase64String</span>(localMasterKeyBase64Read);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> localOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span>&lt;string, object&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"key"</span>, localMasterKeyBytes }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">};</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders.<span class="lg-highlight-title lg-highlight-class">Add</span>(provider, localOptions);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-132-menu" aria-describedby="select-132-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-133" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8r:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8r:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8r:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8r:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_tc8cify11" class="leafygreen-ui-38lglc" id="_jxf14l197" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"key, err := ioutil.ReadFile(\"master-key.txt\")\nif err != nil {\n\tlog.Fatalf(\"Could not read the key from master-key.txt: %v\", err)\n}\nkmsProviders := map[string]map[string]interface{}{\"local\": {\"key\": key}}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">key<!-- -->, <!-- -->err := ioutil.<span class="lg-highlight-title lg-highlight-class">ReadFile</span>(<span class="lg-highlight-string">"master-key.txt"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> log.<span class="lg-highlight-title lg-highlight-class">Fatalf</span>(<span class="lg-highlight-string">"Could not read the key from master-key.txt: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders <!-- -->:<!-- -->= map[string]map[string]interface{}{<span class="lg-highlight-string">"local"</span>: {<span class="lg-highlight-string">"key"</span>: key}}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-135-menu" aria-describedby="select-135-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-136" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8s:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8s:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8s:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8s:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_qjckn3n18" class="leafygreen-ui-38lglc" id="_y5hmezou4" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"String kmsProvider = \"local\";\nString path = \"master-key.txt\";\n\nbyte[] localMasterKeyRead = new byte[96];\n\ntry (FileInputStream fis = new FileInputStream(path)) {\n if (fis.read(localMasterKeyRead) &lt; 96)\n throw new Exception(\"Expected to read 96 bytes from file\");\n}\nMap&lt;string,&gt; keyMap = new HashMap&lt;string,&gt;();\nkeyMap.put(\"key\", localMasterKeyRead);\n\nMap&lt;string,&gt;&gt; kmsProviders = new HashMap&lt;string,&gt;&gt;();\nkmsProviders.put(\"local\", keyMap);","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">String</span> kmsProvider = <span class="lg-highlight-string">"local"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> path = <span class="lg-highlight-string">"master-key.txt"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">byte[] localMasterKeyRead = <span class="lg-highlight-keyword">new</span> byte[<span class="lg-highlight-number">96</span>];</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-keyword">try</span> (<span class="lg-highlight-title lg-highlight-class">FileInputStream</span> fis = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">FileInputStream</span>(path)) {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">if</span> (fis.<span class="lg-highlight-title lg-highlight-function">read</span>(localMasterKeyRead) &lt; <span class="lg-highlight-number">96</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">throw</span> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Exception</span>(<span class="lg-highlight-string">"Expected to read 96 bytes from file"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt; keyMap = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyMap.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"key"</span>, localMasterKeyRead);</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">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt;&gt; kmsProviders = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt;&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"local"</span>, keyMap);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-138-menu" aria-describedby="select-138-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-139" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8t:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8t:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8t:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8t:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_g3fl73vp5" class="" id="_8uv0xv2mx" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const fs = require(\"fs\");\nconst provider = \"local\";\nconst path = \"./master-key.txt\";\nconst localMasterKey = fs.readFileSync(path);\nconst kmsProviders = {\n local: {\n key: localMasterKey,\n },\n};","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> fs <!-- -->= <span class="lg-highlight-built_in">require</span>(<span class="lg-highlight-string">"fs"</span>)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> provider <!-- -->= <span class="lg-highlight-string">"local"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> path <!-- -->= <span class="lg-highlight-string">"./master-key.txt"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> localMasterKey <!-- -->= <!-- -->fs.<span class="lg-highlight-title lg-highlight-function">readFileSync</span>(<!-- -->path)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> kmsProviders <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">local</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->localMasterKey<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-141-menu" aria-describedby="select-141-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-142" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8u:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8u:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8u:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8u:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_sm6hujmr2" class="leafygreen-ui-38lglc" id="_09ei3sj7e" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"path = \"./master-key.txt\"\nwith open(path, \"rb\") as f:\n local_master_key = f.read()\nkms_providers = {\n \"local\": {\n \"key\": local_master_key # local_master_key variable from the previous step\n },\n}","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">path = <span class="lg-highlight-string">"./master-key.txt"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">with</span> <span class="lg-highlight-title lg-highlight-function">open</span>(path, <span class="lg-highlight-string">"rb"</span>) <span class="lg-highlight-keyword">as</span> <span class="lg-highlight-attr">f</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> local_master_key = f.<span class="lg-highlight-title lg-highlight-function">read</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kms_providers = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"local"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"key"</span>: local_master_key # local_master_key variable <span class="lg-highlight-keyword">from</span> the previous step</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-144-menu" aria-describedby="select-144-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-145" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8v:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r8v:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8v:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r8v:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create an Encryption Schema For Your Collection </p> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Add Your Data Encryption Key Base64 ID </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Make sure to update the following code to include your Base64 <span class="leafygreen-ui-vm4wms" tabindex="0"> DEK </span> ID. You received this value in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-csfle-local-create-dek" target="_self"> <span> Generate your Data Encryption Key </span> </a> step of this guide. </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-csfle-quickstart-encryption-schema"> </span> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-22"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_hazbsy3vn" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_xbzlme730" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_v09dwdez7" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_z50g4d10w" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_whj36oxvq" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_pm4vmzzd1" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_e68yipx6t" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_ruz14uf79" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_pqdb54myh" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_jl71ru2qv" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_rzfsiypab" class="leafygreen-ui-38lglc" id="_v2s2v6pdg" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var keyId = \"&lt;your&gt;\";\nvar schema = new BsonDocument\n{\n { \"bsonType\", \"object\" },\n {\n \"encryptMetadata\",\n new BsonDocument(\"keyId\", new BsonArray(new[] { new BsonBinaryData(Convert.FromBase64String(keyId), BsonBinarySubType.UuidStandard) }))\n },\n {\n \"properties\",\n new BsonDocument\n {\n {\n \"ssn\", new BsonDocument\n {\n {\n \"encrypt\", new BsonDocument\n {\n { \"bsonType\", \"int\" },\n { \"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\" }\n }\n }\n }\n },\n {\n \"bloodType\", new BsonDocument\n {\n {\n \"encrypt\", new BsonDocument\n {\n { \"bsonType\", \"string\" },\n { \"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\" }\n }\n }\n }\n },\n {\n \"medicalRecords\", new BsonDocument\n {\n {\n \"encrypt\", new BsonDocument\n {\n { \"bsonType\", \"array\" },\n { \"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\" }\n }\n }\n }\n },\n {\n \"insurance\", new BsonDocument\n {\n { \"bsonType\", \"object\" },\n {\n \"properties\", new BsonDocument\n {\n {\n \"policyNumber\", new BsonDocument\n {\n {\n \"encrypt\", new BsonDocument\n {\n { \"bsonType\", \"int\" },\n { \"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\" }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n};\nvar schemaMap = new Dictionary&lt;string,&gt;();\nschemaMap.Add(dbNamespace, schema);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> keyId = <span class="lg-highlight-string">"&lt;Your base64 DEK ID here&gt;"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> schema = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"object"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encryptMetadata"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"keyId"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonArray</span>(<span class="lg-highlight-keyword">new</span>[] { <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonBinaryData</span>(<span class="lg-highlight-title lg-highlight-class">Convert</span>.<span class="lg-highlight-title lg-highlight-class">FromBase64String</span>(keyId), <span class="lg-highlight-title lg-highlight-class">BsonBinarySubType</span>.<span class="lg-highlight-property">UuidStandard</span>) }))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"properties"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ssn"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"int"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloodType"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"string"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"medicalRecords"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"array"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insurance"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"object"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"properties"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"policyNumber"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"int"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">};</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> schemaMap = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span>&lt;string, <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">schemaMap.<span class="lg-highlight-title lg-highlight-class">Add</span>(dbNamespace, schema);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-147-menu" aria-describedby="select-147-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-148" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r90:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r90:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r90:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r90:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_hrpxa8h03" class="leafygreen-ui-38lglc" id="_z9tz33asx" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"dek_id := \"&lt;your&gt;\"\nschema_template := `{\n\t\"bsonType\": \"object\",\n\t\"encryptMetadata\": {\n\t\t\"keyId\": [\n\t\t\t{\n\t\t\t\t\"$binary\": {\n\t\t\t\t\t\"base64\": \"%s\",\n\t\t\t\t\t\"subType\": \"04\"\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t},\n\t\"properties\": {\n\t\t\"insurance\": {\n\t\t\t\"bsonType\": \"object\",\n\t\t\t\"properties\": {\n\t\t\t\t\"policyNumber\": {\n\t\t\t\t\t\"encrypt\": {\n\t\t\t\t\t\t\"bsonType\": \"int\",\n\t\t\t\t\t\t\"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\"\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t\"medicalRecords\": {\n\t\t\t\"encrypt\": {\n\t\t\t\t\"bsonType\": \"array\",\n\t\t\t\t\"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\"\n\t\t\t}\n\t\t},\n\t\t\"bloodType\": {\n\t\t\t\"encrypt\": {\n\t\t\t\t\"bsonType\": \"string\",\n\t\t\t\t\"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\"\n\t\t\t}\n\t\t},\n\t\t\"ssn\": {\n\t\t\t\"encrypt\": {\n\t\t\t\t\"bsonType\": \"int\",\n\t\t\t\t\"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\"\n\t\t\t}\n\t\t}\n\t}\n}`\nschema := fmt.Sprintf(schema_template, dek_id)\nvar schemaDoc bson.Raw\nif err := bson.UnmarshalExtJSON([]byte(schema), true, &amp;schemaDoc); err != nil {\n\treturn fmt.Errorf(\"UnmarshalExtJSON error: %v\", err)\n}\nschemaMap := map[string]interface{}{\n\tdbName + \".\" + collName: schemaDoc,\n}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">dek_id <!-- -->:<!-- -->= <span class="lg-highlight-string">"&lt;Your Base64 DEK ID&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">schema_template <!-- -->:<!-- -->= <span class="lg-highlight-string">`{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "object",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "encryptMetadata": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "keyId": [</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "$binary": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "base64": "%s",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "subType": "04"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> ]</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> },</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "properties": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "insurance": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "object",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "properties": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "policyNumber": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "encrypt": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "int",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> },</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "medicalRecords": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "encrypt": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "array",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> },</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bloodType": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "encrypt": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "string",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> },</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "ssn": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "encrypt": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "int",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">}`</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">schema <!-- -->:<!-- -->= fmt.<span class="lg-highlight-title lg-highlight-class">Sprintf</span>(schema_template, dek_id)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> schemaDoc bson.<span class="lg-highlight-property">Raw</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err <!-- -->:<!-- -->= bson.<span class="lg-highlight-title lg-highlight-class">UnmarshalExtJSON</span>([]<span class="lg-highlight-title lg-highlight-function">byte</span>(schema), <span class="lg-highlight-literal">true</span>, &amp;schemaDoc); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"UnmarshalExtJSON error: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">schemaMap <!-- -->:<!-- -->= map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> dbName + <span class="lg-highlight-string">"."</span> + <span class="lg-highlight-attr">collName</span>: schemaDoc,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-150-menu" aria-describedby="select-150-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-151" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r91:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r91:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r91:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r91:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_9gevxk328" class="leafygreen-ui-38lglc" id="_ro8s7r58u" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"String dekId = \"&lt;paste-base-64-encoded-data-encryption-key-id&gt;&gt;\";\nDocument jsonSchema = new Document().append(\"bsonType\", \"object\").append(\"encryptMetadata\",\n new Document().append(\"keyId\", new ArrayList&lt;&gt;((Arrays.asList(new Document().append(\"$binary\", new Document()\n .append(\"base64\", dekId)\n .append(\"subType\", \"04\")))))))\n .append(\"properties\", new Document()\n .append(\"ssn\", new Document().append(\"encrypt\", new Document()\n .append(\"bsonType\", \"int\")\n .append(\"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\")))\n .append(\"bloodType\", new Document().append(\"encrypt\", new Document()\n .append(\"bsonType\", \"string\")\n .append(\"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\")))\n .append(\"medicalRecords\", new Document().append(\"encrypt\", new Document()\n .append(\"bsonType\", \"array\")\n .append(\"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\")))\n .append(\"insurance\", new Document()\n .append(\"bsonType\", \"object\")\n .append(\"properties\",\n new Document().append(\"policyNumber\", new Document().append(\"encrypt\", new Document()\n .append(\"bsonType\", \"int\")\n .append(\"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\"))))));\nHashMap&lt;string,&gt; schemaMap = new HashMap&lt;string,&gt;();\nschemaMap.put(\"medicalRecords.patients\", BsonDocument.parse(jsonSchema.toJson()));","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">String</span> dekId = <span class="lg-highlight-string">"&lt;paste-base-64-encoded-data-encryption-key-id&gt;&gt;"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Document</span> jsonSchema = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"object"</span>).<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"encryptMetadata"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"keyId"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ArrayList</span>&lt;&gt;((<span class="lg-highlight-title lg-highlight-class">Arrays</span>.<span class="lg-highlight-title lg-highlight-function">asList</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"$binary"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"base64"</span>, dekId)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"subType"</span>, <span class="lg-highlight-string">"04"</span>)))))))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"properties"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"ssn"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"int"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>)))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bloodType"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"string"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>)))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"medicalRecords"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"array"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>)))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"insurance"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"object"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"properties"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"policyNumber"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"int"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>))))));</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">HashMap</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>&gt; schemaMap = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">schemaMap.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"medicalRecords.patients"</span>, <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>.<span class="lg-highlight-title lg-highlight-function">parse</span>(jsonSchema.<span class="lg-highlight-title lg-highlight-function">toJson</span>()));</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-153-menu" aria-describedby="select-153-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-154" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r92:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r92:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r92:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r92:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_5ei9qktfm" class="" id="_tahvz2msd" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"dataKey = \"&lt;your&gt;\";\nconst schema = {\n bsonType: \"object\",\n encryptMetadata: {\n keyId: [new Binary(Buffer.from(dataKey, \"base64\"), 4)],\n },\n properties: {\n insurance: {\n bsonType: \"object\",\n properties: {\n policyNumber: {\n encrypt: {\n bsonType: \"int\",\n algorithm: \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\",\n },\n },\n },\n },\n medicalRecords: {\n encrypt: {\n bsonType: \"array\",\n algorithm: \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\",\n },\n },\n bloodType: {\n encrypt: {\n bsonType: \"string\",\n algorithm: \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\",\n },\n },\n ssn: {\n encrypt: {\n bsonType: \"int\",\n algorithm: \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\",\n },\n },\n },\n};\n\nvar patientSchema = {};\npatientSchema[namespace] = schema;","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">dataKey <!-- -->= <span class="lg-highlight-string">"&lt;Your base64 DEK ID&gt;"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> schema <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encryptMetadata</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyId</span>: <!-- -->[<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Binary</span>(<span class="lg-highlight-title lg-highlight-class">Buffer</span>.<span class="lg-highlight-title lg-highlight-function">from</span>(<!-- -->dataKey<!-- -->, <span class="lg-highlight-string">"base64"</span>)<!-- -->, <span class="lg-highlight-number">4</span>)]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">properties</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insurance</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">properties</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">policyNumber</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encrypt</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"int"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">algorithm</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">medicalRecords</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encrypt</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"array"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">algorithm</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bloodType</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encrypt</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"string"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">algorithm</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ssn</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encrypt</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"int"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">algorithm</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</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"><span class="lg-highlight-keyword">var</span> patientSchema <!-- -->= <!-- -->{<!-- -->}<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">patientSchema<!-- -->[<!-- -->namespace] <!-- -->= <!-- -->schema<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-156-menu" aria-describedby="select-156-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-157" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r93:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r93:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r93:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r93:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_iaq0gcm4j" class="leafygreen-ui-38lglc" id="_r6qltfs3f" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"dek_id = b\"&lt;paste-base-64-encoded-data-encryption-key-id&gt;\"\njson_schema = {\n \"bsonType\": \"object\",\n \"encryptMetadata\": {\"keyId\": [Binary(base64.b64decode(dek_id), UUID_SUBTYPE)]},\n \"properties\": {\n \"insurance\": {\n \"bsonType\": \"object\",\n \"properties\": {\n \"policyNumber\": {\n \"encrypt\": {\n \"bsonType\": \"int\",\n \"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\",\n }\n }\n },\n },\n \"medicalRecords\": {\n \"encrypt\": {\n \"bsonType\": \"array\",\n \"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\",\n }\n },\n \"bloodType\": {\n \"encrypt\": {\n \"bsonType\": \"string\",\n \"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\",\n }\n },\n \"ssn\": {\n \"encrypt\": {\n \"bsonType\": \"int\",\n \"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\",\n }\n },\n },\n}\n\npatient_schema = {\"medicalRecords.patients\": json_schema}","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">dek_id = b<span class="lg-highlight-string">"&lt;paste-base-64-encoded-data-encryption-key-id&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">json_schema = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encryptMetadata"</span>: {<span class="lg-highlight-string">"keyId"</span>: [<span class="lg-highlight-title lg-highlight-class">Binary</span>(base64.<span class="lg-highlight-title lg-highlight-function">b64decode</span>(dek_id), <span class="lg-highlight-variable lg-highlight-constant">UUID_SUBTYPE</span>)]},</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"properties"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insurance"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"properties"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"policyNumber"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"int"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"algorithm"</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"medicalRecords"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"array"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"algorithm"</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloodType"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"string"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"algorithm"</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ssn"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"int"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"algorithm"</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</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">patient_schema = {<span class="lg-highlight-string">"medicalRecords.patients"</span>: json_schema}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-159-menu" aria-describedby="select-159-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-160" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r94:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r94:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r94:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r94:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specify the Location of the Automatic Encryption Shared Library </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-23"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_if766jrj8" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_t5zfyryw7" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_yzw0ery6o" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_c3jkwyxjt" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_enlmmhi5s" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_avbqs0s1a" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_yweum5xsw" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_3xuijqq26" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_ap57jrc39" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_8q5zwvh2v" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_bs57vwnq7" class="leafygreen-ui-38lglc" id="_s9ifb52ww" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var mongoBinariesPath = \"&lt;full&gt;\";\nvar extraOptions = new Dictionary&lt;string,&gt;()\n{\n { \"cryptSharedLibPath\", mongoBinariesPath },\n};","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> mongoBinariesPath = <span class="lg-highlight-string">"&lt;Full path to your Automatic Encryption Shared Library&gt;"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> extraOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span>&lt;string, object&gt;()</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"cryptSharedLibPath"</span>, mongoBinariesPath },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">};</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-162-menu" aria-describedby="select-162-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-163" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r95:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r95:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r95:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r95:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_mr6ih23aw" class="leafygreen-ui-38lglc" id="_tcxp6lmlh" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"extraOptions := map[string]interface{}{\n\t\"cryptSharedLibPath\": \"&lt;full&gt;\",\n}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">extraOptions <!-- -->:<!-- -->= map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"cryptSharedLibPath"</span>: <span class="lg-highlight-string">"&lt;Full path to your Automatic Encryption Shared Library&gt;"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-165-menu" aria-describedby="select-165-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-166" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r96:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r96:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r96:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r96:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_i2j8le0e4" class="leafygreen-ui-38lglc" id="_gh7ytahzf" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Map&lt;string,&gt; extraOptions = new HashMap&lt;string,&gt;();\nextraOptions.put(\"cryptSharedLibPath\", \"&lt;full&gt;\"));","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt; extraOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">extraOptions.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"cryptSharedLibPath"</span>, <span class="lg-highlight-string">"&lt;Full path to your Automatic Encryption Shared Library&gt;"</span>));</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-168-menu" aria-describedby="select-168-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-169" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r97:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r97:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r97:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r97:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_tp3aplg1q" class="" id="_omnigd118" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const extraOptions = {\n cryptSharedLibPath: \"&lt;full&gt;\",\n};","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> extraOptions <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cryptSharedLibPath</span>: <span class="lg-highlight-string">"&lt;Full path to your Automatic Encryption Shared Library&gt;"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-171-menu" aria-describedby="select-171-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-172" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r98:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r98:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r98:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r98:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_idz4lbqq3" class="leafygreen-ui-38lglc" id="_qrewxf5wz" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"extra_options = {\n \"cryptSharedLibPath\": \"&lt;full&gt;\"\n}","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">extra_options = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"cryptSharedLibPath"</span>: <span class="lg-highlight-string">"&lt;Full path to your Automatic Encryption Shared Library&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-174-menu" aria-describedby="select-174-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-175" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r99:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r99:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r99:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r99:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Automatic Encryption Options </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The automatic encryption options provide configuration information to the Automatic Encryption Shared Library, which modifies the application's behavior when accessing encrypted fields. </p> <p class="leafygreen-ui-1kp3ins"> To learn more about the Automatic Encryption Shared Library, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/install-library/#std-label-csfle-reference-shared-library"> Install and Configure a CSFLE Library </a> page. </p> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create the MongoClient </p> <p class="leafygreen-ui-1kp3ins"> Instantiate a MongoDB client object with the following automatic encryption settings: </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-25"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_kaffkn3p9" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_6wlkt5xtg" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_nuh5e4pjg" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_0t3j8pucz" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_71wtbj4gv" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_l7lmi4u4j" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_506gx1ax0" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_ijp6eovwz" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_rivrd4r61" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_2d1oipq6s" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_v73urd8vh" class="leafygreen-ui-38lglc" id="_4x97u5tv7" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-24"> <div aria-label="Tabs to describe usage of csharp-v2/csharp-v3" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_9e8apnf10" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_2bz7kwndu" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> C# Driver v3.0+ </div> </button> <button aria-controls="_99c8neo8a" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_s96q1p81o" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# Driver &lt; v3.0 </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="_79yhtvz08" class="" id="_z12bykj6m" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoClientSettings.Extensions.AddAutoEncryption(); // .NET/C# Driver v3.0 or later only\nvar clientSettings = MongoClientSettings.FromConnectionString(connectionString);\nvar autoEncryptionOptions = new AutoEncryptionOptions(\n keyVaultNamespace: keyVaultNamespace,\n kmsProviders: kmsProviders,\n schemaMap: schemaMap,\n extraOptions: extraOptions\n );\nclientSettings.AutoEncryptionOptions = autoEncryptionOptions;\nvar secureClient = new MongoClient(clientSettings);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-property">Extensions</span>.<span class="lg-highlight-title lg-highlight-class">AddAutoEncryption</span>(); <span class="lg-highlight-comment">// .NET/C# Driver v3.0 or later only</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> clientSettings = <span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-class">FromConnectionString</span>(connectionString);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> autoEncryptionOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">AutoEncryptionOptions</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultNamespace</span>: keyVaultNamespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmsProviders</span>: kmsProviders,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">schemaMap</span>: schemaMap,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extraOptions</span>: extraOptions</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> );</td></tr><tr class=""><td class="leafygreen-ui-7razhx">clientSettings.<span class="lg-highlight-property">AutoEncryptionOptions</span> = autoEncryptionOptions;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> secureClient = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(clientSettings);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-177-menu" aria-describedby="select-177-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-178" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9a:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9a:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9a:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9a:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_zzj6l7iwa" class="leafygreen-ui-38lglc" id="_jh3jrftxe" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var clientSettings = MongoClientSettings.FromConnectionString(connectionString);\nvar autoEncryptionOptions = new AutoEncryptionOptions(\n keyVaultNamespace: keyVaultNamespace,\n kmsProviders: kmsProviders,\n schemaMap: schemaMap,\n extraOptions: extraOptions\n );\nclientSettings.AutoEncryptionOptions = autoEncryptionOptions;\nvar secureClient = new MongoClient(clientSettings);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> clientSettings = <span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-class">FromConnectionString</span>(connectionString);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> autoEncryptionOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">AutoEncryptionOptions</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultNamespace</span>: keyVaultNamespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmsProviders</span>: kmsProviders,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">schemaMap</span>: schemaMap,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extraOptions</span>: extraOptions</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> );</td></tr><tr class=""><td class="leafygreen-ui-7razhx">clientSettings.<span class="lg-highlight-property">AutoEncryptionOptions</span> = autoEncryptionOptions;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> secureClient = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(clientSettings);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-180-menu" aria-describedby="select-180-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-181" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9b:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9b:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9b:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9b:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> </div> </div> </div> <div> <div aria-labelledby="_q3aw1bek9" class="leafygreen-ui-38lglc" id="_5cr07quh0" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"autoEncryptionOpts := options.AutoEncryption().\n\tSetKmsProviders(kmsProviders).\n\tSetKeyVaultNamespace(keyVaultNamespace).\n\tSetSchemaMap(schemaMap).\n\tSetExtraOptions(extraOptions)\nsecureClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri).SetAutoEncryptionOptions(autoEncryptionOpts))\nif err != nil {\n\treturn fmt.Errorf(\"Connect error for encrypted client: %v\", err)\n}\ndefer func() {\n\t_ = secureClient.Disconnect(context.TODO())\n}()","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">autoEncryptionOpts <!-- -->:<!-- -->= options.<span class="lg-highlight-title lg-highlight-class">AutoEncryption</span>().</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKmsProviders</span>(kmsProviders).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKeyVaultNamespace</span>(keyVaultNamespace).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetSchemaMap</span>(schemaMap).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetExtraOptions</span>(extraOptions)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">secureClient<!-- -->, <!-- -->err := mongo.<span class="lg-highlight-title lg-highlight-class">Connect</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), options.<span class="lg-highlight-title lg-highlight-class">Client</span>().<span class="lg-highlight-title lg-highlight-class">ApplyURI</span>(uri).<span class="lg-highlight-title lg-highlight-class">SetAutoEncryptionOptions</span>(autoEncryptionOpts))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"Connect error for encrypted client: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">defer <span class="lg-highlight-title lg-highlight-function">func</span>() {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _ = secureClient.<span class="lg-highlight-title lg-highlight-class">Disconnect</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}()</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-183-menu" aria-describedby="select-183-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-184" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9c:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9c:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9c:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9c:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_fsc4yxg11" class="leafygreen-ui-38lglc" id="_nknf3t55c" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoClientSettings clientSettings = MongoClientSettings.builder()\n .applyConnectionString(new ConnectionString(connectionString))\n .autoEncryptionSettings(AutoEncryptionSettings.builder()\n .keyVaultNamespace(keyVaultNamespace)\n .kmsProviders(kmsProviders)\n .schemaMap(schemaMap)\n .extraOptions(extraOptions)\n .build())\n .build();\n\nMongoClient mongoClientSecure = MongoClients.create(clientSettings);","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span> clientSettings = <span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">applyConnectionString</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ConnectionString</span>(connectionString))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">autoEncryptionSettings</span>(<span class="lg-highlight-title lg-highlight-class">AutoEncryptionSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">keyVaultNamespace</span>(keyVaultNamespace)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">kmsProviders</span>(kmsProviders)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">schemaMap</span>(schemaMap)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">extraOptions</span>(extraOptions)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>();</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">MongoClient</span> mongoClientSecure = <span class="lg-highlight-title lg-highlight-class">MongoClients</span>.<span class="lg-highlight-title lg-highlight-function">create</span>(clientSettings);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-186-menu" aria-describedby="select-186-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-187" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9d:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9d:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9d:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9d:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_s8l5rxr3p" class="" id="_e4tocbafn" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const secureClient = new MongoClient(connectionString, {\n autoEncryption: {\n keyVaultNamespace,\n kmsProviders,\n schemaMap: patientSchema,\n extraOptions: extraOptions,\n },\n});","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> secureClient <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(<!-- -->connectionString<!-- -->, <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">autoEncryption</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->keyVaultNamespace<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->kmsProviders<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">schemaMap</span>: <!-- -->patientSchema<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extraOptions</span>: <!-- -->extraOptions<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">})<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-189-menu" aria-describedby="select-189-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-190" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9e:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9e:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9e:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9e:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_7d4g8yfei" class="leafygreen-ui-38lglc" id="_ktffj1vsz" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"fle_opts = AutoEncryptionOpts(\n kms_providers, key_vault_namespace, schema_map=patient_schema, **extra_options\n)\nsecureClient = MongoClient(connection_string, auto_encryption_opts=fle_opts)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">fle_opts = <span class="lg-highlight-title lg-highlight-class">AutoEncryptionOpts</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kms_providers, key_vault_namespace, schema_map=patient_schema, **extra_options</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">secureClient = <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(connection_string, auto_encryption_opts=fle_opts)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-192-menu" aria-describedby="select-192-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-193" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9f:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9f:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9f:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9f:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> </li> </ol> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 5 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Insert a Document with Encrypted Fields <a class="headerlink leafygreen-ui-1kepx47" href="#insert-a-document-with-encrypted-fields" 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-a-document-with-encrypted-fields"> </div> </a> </h3> <span class="leafygreen-ui-1qnjd6d" id="std-label-csfle-quick-start-insert"> </span> <p class="leafygreen-ui-1kp3ins"> Use your CSFLE-enabled <code class="leafygreen-ui-1l06pbn"> MongoClient </code> instance to insert a document with encrypted fields into the <code class="leafygreen-ui-1l06pbn"> medicalRecords.patients </code> namespace using the following code snippet: </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-27"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_tbnf307v8" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_tzrcceoc6" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_osetaigbv" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_gtnkqulve" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_ikh4b3q46" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_9jwegpory" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_ikdl4gnsb" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_9nm77jc8q" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_48q1nwccl" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_99ejln9qo" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_g0sl8afr5" class="leafygreen-ui-38lglc" id="_yp9zp0j1o" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var sampleDocFields = new BsonDocument\n{\n { \"name\", \"Jon Doe\" },\n { \"ssn\", 145014000 },\n { \"bloodType\", \"AB-\" },\n {\n \"medicalRecords\", new BsonArray\n {\n new BsonDocument(\"weight\", 180),\n new BsonDocument(\"bloodPressure\", \"120/80\")\n }\n },\n {\n \"insurance\", new BsonDocument\n {\n { \"policyNumber\", 123142 },\n { \"provider\", \"MaestCare\" }\n }\n }\n};\n\n// Construct an auto-encrypting client\nvar secureCollection = secureClient.GetDatabase(db).GetCollection&lt;bsondocument&gt;(coll);\n\n// Insert a document into the collection\nsecureCollection.InsertOne(sampleDocFields);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> sampleDocFields = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"ssn"</span>, <span class="lg-highlight-number">145014000</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bloodType"</span>, <span class="lg-highlight-string">"AB-"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"medicalRecords"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonArray</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"weight"</span>, <span class="lg-highlight-number">180</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"bloodPressure"</span>, <span class="lg-highlight-string">"120/80"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insurance"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"policyNumber"</span>, <span class="lg-highlight-number">123142</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"provider"</span>, <span class="lg-highlight-string">"MaestCare"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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"><span class="lg-highlight-comment">// Construct an auto-encrypting client</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> secureCollection = secureClient.<span class="lg-highlight-title lg-highlight-class">GetDatabase</span>(db).<span class="lg-highlight-property">GetCollection</span>&lt;<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>&gt;(coll);</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-comment">//</span><span class="lg-highlight-comment"> Insert a document </span><span class="lg-highlight-comment">into the collection</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">secureCollection.<span class="lg-highlight-title lg-highlight-class">InsertOne</span>(sampleDocFields);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-195-menu" aria-describedby="select-195-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-196" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9g:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9g:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9g:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9g:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_5vg400ily" class="leafygreen-ui-38lglc" id="_6l352s7eq" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"test_patient := map[string]interface{}{\n\t\"name\": \"Jon Doe\",\n\t\"ssn\": 241014209,\n\t\"bloodType\": \"AB+\",\n\t\"medicalRecords\": []map[string]interface{}{{\n\t\t\"weight\": 180,\n\t\t\"bloodPressure\": \"120/80\",\n\t}},\n\t\"insurance\": map[string]interface{}{\n\t\t\"provider\": \"MaestCare\",\n\t\t\"policyNumber\": 123142,\n\t},\n}\nif _, err := secureClient.Database(dbName).Collection(collName).InsertOne(context.TODO(), test_patient); err != nil {\n\treturn fmt.Errorf(\"InsertOne error: %v\", err)\n}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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_patient <!-- -->:<!-- -->= map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"Jon Doe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ssn"</span>: <span class="lg-highlight-number">241014209</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloodType"</span>: <span class="lg-highlight-string">"AB+"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"medicalRecords"</span>: []map[string]interface{}{{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"weight"</span>: <span class="lg-highlight-number">180</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloodPressure"</span>: <span class="lg-highlight-string">"120/80"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }},</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insurance"</span>: map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"provider"</span>: <span class="lg-highlight-string">"MaestCare"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"policyNumber"</span>: <span class="lg-highlight-number">123142</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> _<!-- -->, <!-- -->err := secureClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(dbName).<span class="lg-highlight-title lg-highlight-class">Collection</span>(collName).<span class="lg-highlight-title lg-highlight-class">InsertOne</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), test_patient); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"InsertOne error: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-198-menu" aria-describedby="select-198-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-199" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9h:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9h:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9h:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9h:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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 class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Rather than creating a raw BSON document, you can pass a struct with <code class="leafygreen-ui-1l06pbn"> bson </code> tags directly to the driver for encoding. </p> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_szjpp7p7k" class="leafygreen-ui-38lglc" id="_6ip79d58a" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ArrayList&lt;document&gt; medicalRecords = new ArrayList&lt;&gt;();\nmedicalRecords.add(new Document().append(\"weight\", \"180\"));\nmedicalRecords.add(new Document().append(\"bloodPressure\", \"120/80\"));\n\nDocument insurance = new Document()\n.append(\"policyNumber\", 123142)\n.append(\"provider\", \"MaestCare\");\n\nDocument patient = new Document()\n .append(\"name\", \"Jon Doe\")\n .append(\"ssn\", 241014209)\n .append(\"bloodType\", \"AB+\")\n .append(\"medicalRecords\", medicalRecords)\n .append(\"insurance\", insurance);\nmongoClientSecure.getDatabase(recordsDb).getCollection(recordsColl).insertOne(patient);","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">ArrayList</span>&lt;<span class="lg-highlight-title lg-highlight-class">Document</span>&gt; medicalRecords = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ArrayList</span>&lt;&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">medicalRecords.<span class="lg-highlight-title lg-highlight-function">add</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"weight"</span>, <span class="lg-highlight-string">"180"</span>));</td></tr><tr class=""><td class="leafygreen-ui-7razhx">medicalRecords.<span class="lg-highlight-title lg-highlight-function">add</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bloodPressure"</span>, <span class="lg-highlight-string">"120/80"</span>));</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">Document</span> insurance = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx">.<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"policyNumber"</span>, <span class="lg-highlight-number">123142</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">.<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"provider"</span>, <span class="lg-highlight-string">"MaestCare"</span>);</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">Document</span> patient = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"ssn"</span>, <span class="lg-highlight-number">241014209</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bloodType"</span>, <span class="lg-highlight-string">"AB+"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"medicalRecords"</span>, medicalRecords)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"insurance"</span>, insurance);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongoClientSecure.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(recordsDb).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(recordsColl).<span class="lg-highlight-title lg-highlight-function">insertOne</span>(patient);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-201-menu" aria-describedby="select-201-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-202" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9i:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9i:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9i:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9i:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_mdth6kntx" class="" id="_q461m4ut8" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"try {\n const writeResult = await secureClient\n .db(db)\n .collection(coll)\n .insertOne({\n name: \"Jon Doe\",\n ssn: 241014209,\n bloodType: \"AB+\",\n medicalRecords: [{ weight: 180, bloodPressure: \"120/80\" }],\n insurance: {\n policyNumber: 123142,\n provider: \"MaestCare\",\n },\n });\n} catch (writeError) {\n console.error(\"writeError occurred:\", writeError);\n}","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">try</span> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">const</span> writeResult <!-- -->= <span class="lg-highlight-keyword">await</span> secureClient</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">db</span>(<!-- -->db)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">collection</span>(<!-- -->coll)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">insertOne</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Jon Doe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ssn</span>: <span class="lg-highlight-number">241014209</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bloodType</span>: <span class="lg-highlight-string">"AB+"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">medicalRecords</span>: <!-- -->[<!-- -->{ <span class="lg-highlight-attr">weight</span>: <span class="lg-highlight-number">180</span>, <span class="lg-highlight-attr">bloodPressure</span>: <span class="lg-highlight-string">"120/80"</span> }]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insurance</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">policyNumber</span>: <span class="lg-highlight-number">123142</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">provider</span>: <span class="lg-highlight-string">"MaestCare"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->})<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} <span class="lg-highlight-keyword">catch</span> <!-- -->(<!-- -->writeError) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">error</span>(<span class="lg-highlight-string">"writeError occurred:"</span>, <!-- -->writeError)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-204-menu" aria-describedby="select-204-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-205" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9j:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9j:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9j:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9j:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_9kta1fnn5" class="leafygreen-ui-38lglc" id="_z8aizfyqg" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"def insert_patient(\n collection, name, ssn, blood_type, medical_records, policy_number, provider\n):\n insurance = {\"policyNumber\": policy_number, \"provider\": provider}\n doc = {\n \"name\": name,\n \"ssn\": ssn,\n \"bloodType\": blood_type,\n \"medicalRecords\": medical_records,\n \"insurance\": insurance,\n }\n collection.insert_one(doc)\n\n\nmedical_record = [{\"weight\": 180, \"bloodPressure\": \"120/80\"}]\ninsert_patient(\n secureClient.medicalRecords.patients,\n \"Jon Doe\",\n 241014209,\n \"AB+\",\n medical_record,\n 123142,\n \"MaestCare\",\n)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">def <span class="lg-highlight-title lg-highlight-function">insert_patient</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> collection, name, ssn, blood_type, medical_records, policy_number, provider</td></tr><tr class=""><td class="leafygreen-ui-7razhx">):<!-- --></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> insurance = {<span class="lg-highlight-string">"policyNumber"</span>: policy_number, <span class="lg-highlight-string">"provider"</span>: provider}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> doc = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span>: name,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ssn"</span>: ssn,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloodType"</span>: blood_type,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"medicalRecords"</span>: medical_records,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insurance"</span>: insurance,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> collection.<span class="lg-highlight-title lg-highlight-function">insert_one</span>(doc)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">medical_record = [{<span class="lg-highlight-string">"weight"</span>: <span class="lg-highlight-number">180</span>, <span class="lg-highlight-string">"bloodPressure"</span>: <span class="lg-highlight-string">"120/80"</span>}]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-function">insert_patient</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> secureClient.<span class="lg-highlight-property">medicalRecords</span>.<span class="lg-highlight-property">patients</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Jon Doe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-number">241014209</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"AB+"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> medical_record,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-number">123142</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"MaestCare"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-207-menu" aria-describedby="select-207-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-208" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9k:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9k:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9k:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9k:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <p class="leafygreen-ui-1kp3ins"> When you insert a document, your CSFLE-enabled client encrypts the fields of your document such that it resembles the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\": { \"$oid\": \"&lt;_id of your document&gt;\" },\n \"name\": \"Jon Doe\",\n \"ssn\": {\n \"$binary\": \"&lt;cipher-text&gt;\",\n \"$type\": \"6\"\n },\n \"bloodType\": {\n \"$binary\": \"&lt;cipher-text&gt;\",\n \"$type\": \"6\"\n },\n \"medicalRecords\": {\n \"$binary\": \"&lt;cipher-text&gt;\",\n \"$type\": \"6\"\n },\n \"insurance\": {\n \"provider\": \"MaestCare\",\n \"policyNumber\": {\n \"$binary\": \"&lt;cipher-text&gt;\",\n \"$type\": \"6\"\n }\n }\n}\n","programmingLanguage":"JSON"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"_id"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span> <span class="lg-highlight-attr">"$oid"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"&lt;_id of your document&gt;"</span> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"name"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"Jon Doe"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"ssn"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$binary"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"&lt;cipher-text&gt;"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$type"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"6"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"bloodType"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$binary"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"&lt;cipher-text&gt;"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$type"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"6"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"medicalRecords"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$binary"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"&lt;cipher-text&gt;"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$type"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"6"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"insurance"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"provider"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"MaestCare"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"policyNumber"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$binary"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"&lt;cipher-text&gt;"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$type"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"6"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre> </div> </div> </div> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> See: Complete Code </strong> </h3> <div class="leafygreen-ui-9mycqc"> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-28"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_povsqj45j" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_mc7vbm17b" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_pshx1cbvd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_mctx1g4nn" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_fv39o1pd0" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_93ah26w8y" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_0noxl1hup" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_58hyj3ljo" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_e4p2zltz5" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_sm391rdcu" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_p4tnfrszk" class="leafygreen-ui-38lglc" id="_kxur852bu" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for inserting a document with encrypted fields, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/dotnet/local/reader/CSFLE/InsertEncryptedDocument.cs" rel="noopener noreferrer"> <span> our Github repository </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> </p> </div> </div> </div> <div> <div aria-labelledby="_chmy1dy62" class="leafygreen-ui-38lglc" id="_95li073we" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for inserting a document with encrypted fields, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/go/local/reader/insert-encrypted-document.go" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_ftqnxdkez" class="leafygreen-ui-38lglc" id="_s37oqf1g8" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for inserting a document with encrypted fields, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/java/local/reader/src/main/java/com/mongodb/csfle/InsertEncryptedDocument.java" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_m3iiyunwq" class="" id="_fu2dvh8xj" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for inserting a document with encrypted fields, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/node/local/reader/insert_encrypted_document.js" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_4m7ox41ax" class="leafygreen-ui-38lglc" id="_r6i576pgy" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for inserting a document with encrypted fields, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/python/local/reader/insert_encrypted_document.py" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> </div> </div> </div> </div> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 6 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Retrieve Your Document with Encrypted Fields <a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-your-document-with-encrypted-fields" 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="retrieve-your-document-with-encrypted-fields"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Retrieve the document with encrypted fields you inserted in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-csfle-quick-start-insert" target="_self"> <span> Insert a Document with Encrypted Fields </span> </a> step of this guide. </p> <p class="leafygreen-ui-1kp3ins"> To show the functionality of CSFLE, the following code snippet queries for your document with a client configured for automatic CSFLE as well as a client that is not configured for automatic CSFLE. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-30"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_p7qrtfhfn" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_5nd9sfw6p" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_swbi0ov3b" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_8ey06qrm8" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_yfmdhy306" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_5pfoqk1mm" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_u4yxbhly3" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_i3pur0r20" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_ys734zuky" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_sud2a7ht8" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_ciiikn7hb" class="leafygreen-ui-38lglc" id="_cu65dwf2g" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Console.WriteLine(\"Finding a document with regular (non-encrypted) client.\");\nvar filter = Builders&lt;bsondocument&gt;.Filter.Eq(\"name\", \"Jon Doe\");\nvar regularResult = regularCollection.Find(filter).Limit(1).ToList()[0];\nConsole.WriteLine($\"\\n{regularResult}\\n\");\n\nConsole.WriteLine(\"Finding a document with encrypted client\");\nvar ssnFilter = Builders&lt;bsondocument&gt;.Filter.Eq(\"name\", \"Jon Doe\");\nvar secureResult = secureCollection.Find(ssnFilter).Limit(1).First();\nConsole.WriteLine($\"\\n{secureResult}\\n\");","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>(<span class="lg-highlight-string">"Finding a document with regular (non-encrypted) client."</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> filter = <span class="lg-highlight-title lg-highlight-class">Builders</span>&lt;<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>&gt;.<span class="lg-highlight-property">Filter</span>.<span class="lg-highlight-title lg-highlight-class">Eq</span>(<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> regularResult = regularCollection.<span class="lg-highlight-title lg-highlight-class">Find</span>(filter).<span class="lg-highlight-title lg-highlight-class">Limit</span>(<span class="lg-highlight-number">1</span>).<span class="lg-highlight-title lg-highlight-class">ToList</span>()[<span class="lg-highlight-number">0</span>];</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>($<span class="lg-highlight-string">"</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">{regularResult}</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>);</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">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>(<span class="lg-highlight-string">"Finding a document with encrypted client"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> ssnFilter = <span class="lg-highlight-title lg-highlight-class">Builders</span>&lt;<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>&gt;.<span class="lg-highlight-property">Filter</span>.<span class="lg-highlight-title lg-highlight-class">Eq</span>(<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> secureResult = secureCollection.<span class="lg-highlight-title lg-highlight-class">Find</span>(ssnFilter).<span class="lg-highlight-title lg-highlight-class">Limit</span>(<span class="lg-highlight-number">1</span>).<span class="lg-highlight-title lg-highlight-class">First</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>($<span class="lg-highlight-string">"</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">{secureResult}</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-210-menu" aria-describedby="select-210-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-211" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9l:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9l:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9l:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9l:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_z183q0y1e" class="leafygreen-ui-38lglc" id="_8dsdv9nxq" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"fmt.Println(\"Finding a document with regular (non-encrypted) client.\")\nvar resultRegular bson.M\nerr = regularClient.Database(dbName).Collection(collName).FindOne(context.TODO(), bson.D{{\"name\", \"Jon Doe\"}}).Decode(&amp;resultRegular)\nif err != nil {\n\tpanic(err)\n}\noutputRegular, err := json.MarshalIndent(resultRegular, \"\", \" \")\nif err != nil {\n\tpanic(err)\n}\nfmt.Printf(\"%s\\n\", outputRegular)\n\nfmt.Println(\"Finding a document with encrypted client\")\nvar resultSecure bson.M\nerr = secureClient.Database(dbName).Collection(collName).FindOne(context.TODO(), bson.D{{\"name\", \"Jon Doe\"}}).Decode(&amp;resultSecure)\nif err != nil {\n\tpanic(err)\n}\noutputSecure, err := json.MarshalIndent(resultSecure, \"\", \" \")\nif err != nil {\n\tpanic(err)\n}\nfmt.Printf(\"%s\\n\", outputSecure)","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">fmt.<span class="lg-highlight-title lg-highlight-class">Println</span>(<span class="lg-highlight-string">"Finding a document with regular (non-encrypted) client."</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> resultRegular bson.<span class="lg-highlight-property">M</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">err = regularClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(dbName).<span class="lg-highlight-title lg-highlight-class">Collection</span>(collName).<span class="lg-highlight-title lg-highlight-class">FindOne</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), bson.<span class="lg-highlight-property">D</span>{{<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>}}).<span class="lg-highlight-title lg-highlight-class">Decode</span>(&amp;resultRegular)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">outputRegular<!-- -->, <!-- -->err := json.<span class="lg-highlight-title lg-highlight-class">MarshalIndent</span>(resultRegular, <span class="lg-highlight-string">""</span>, <span class="lg-highlight-string">" "</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">fmt.<span class="lg-highlight-title lg-highlight-class">Printf</span>(<span class="lg-highlight-string">"%s</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>, outputRegular)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">fmt.<span class="lg-highlight-title lg-highlight-class">Println</span>(<span class="lg-highlight-string">"Finding a document with encrypted client"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> resultSecure bson.<span class="lg-highlight-property">M</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">err = secureClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(dbName).<span class="lg-highlight-title lg-highlight-class">Collection</span>(collName).<span class="lg-highlight-title lg-highlight-class">FindOne</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), bson.<span class="lg-highlight-property">D</span>{{<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>}}).<span class="lg-highlight-title lg-highlight-class">Decode</span>(&amp;resultSecure)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">outputSecure<!-- -->, <!-- -->err := json.<span class="lg-highlight-title lg-highlight-class">MarshalIndent</span>(resultSecure, <span class="lg-highlight-string">""</span>, <span class="lg-highlight-string">" "</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">fmt.<span class="lg-highlight-title lg-highlight-class">Printf</span>(<span class="lg-highlight-string">"%s</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>, outputSecure)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-213-menu" aria-describedby="select-213-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-214" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9m:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9m:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9m:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9m:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_cdb2b6nvh" class="leafygreen-ui-38lglc" id="_nhf8j81kq" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"System.out.println(\"Finding a document with regular (non-encrypted) client.\");\nDocument docRegular = mongoClientRegular.getDatabase(recordsDb).getCollection(recordsColl).find(eq(\"name\", \"Jon Doe\")).first();\nSystem.out.println(docRegular.toJson());\n\nSystem.out.println(\"Finding a document with encrypted client\");\nDocument docSecure = mongoClientSecure.getDatabase(recordsDb).getCollection(recordsColl).find(eq(\"name\", \"Jon Doe\")).first();\nSystem.out.println(docSecure.toJson());","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">System</span>.<span class="lg-highlight-property">out</span>.<span class="lg-highlight-title lg-highlight-function">println</span>(<span class="lg-highlight-string">"Finding a document with regular (non-encrypted) client."</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Document</span> docRegular = mongoClientRegular.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(recordsDb).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(recordsColl).<span class="lg-highlight-title lg-highlight-function">find</span>(<span class="lg-highlight-title lg-highlight-function">eq</span>(<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>)).<span class="lg-highlight-title lg-highlight-function">first</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">System</span>.<span class="lg-highlight-property">out</span>.<span class="lg-highlight-title lg-highlight-function">println</span>(docRegular.<span class="lg-highlight-title lg-highlight-function">toJson</span>());</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">System</span>.<span class="lg-highlight-property">out</span>.<span class="lg-highlight-title lg-highlight-function">println</span>(<span class="lg-highlight-string">"Finding a document with encrypted client"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Document</span> docSecure = mongoClientSecure.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(recordsDb).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(recordsColl).<span class="lg-highlight-title lg-highlight-function">find</span>(<span class="lg-highlight-title lg-highlight-function">eq</span>(<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>)).<span class="lg-highlight-title lg-highlight-function">first</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">System</span>.<span class="lg-highlight-property">out</span>.<span class="lg-highlight-title lg-highlight-function">println</span>(docSecure.<span class="lg-highlight-title lg-highlight-function">toJson</span>());</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-216-menu" aria-describedby="select-216-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-217" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9n:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9n:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9n:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9n:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_qojxa7bzt" class="" id="_8q7ntko1f" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"console.log(\"Finding a document with regular (non-encrypted) client.\");\nconsole.log(\n await regularClient.db(db).collection(coll).findOne({ name: /Jon/ })\n);\n\nconsole.log(\"Finding a document with encrypted client\");\nconsole.log(\n await secureClient.db(db).collection(coll).findOne({ name: /Jon/ })\n);","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(<span class="lg-highlight-string">"Finding a document with regular (non-encrypted) client."</span>)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">await</span> regularClient.<span class="lg-highlight-title lg-highlight-function">db</span>(<!-- -->db).<span class="lg-highlight-title lg-highlight-function">collection</span>(<!-- -->coll).<span class="lg-highlight-title lg-highlight-function">findOne</span>(<!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-regexp">/Jon/</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"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(<span class="lg-highlight-string">"Finding a document with encrypted client"</span>)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">await</span> secureClient.<span class="lg-highlight-title lg-highlight-function">db</span>(<!-- -->db).<span class="lg-highlight-title lg-highlight-function">collection</span>(<!-- -->coll).<span class="lg-highlight-title lg-highlight-function">findOne</span>(<!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-regexp">/Jon/</span> <!-- -->})</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-219-menu" aria-describedby="select-219-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-220" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9o:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9o:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9o:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9o:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_pwh1abytl" class="leafygreen-ui-38lglc" id="_3kd0j46y8" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"print(\"Finding a document with regular (non-encrypted) client.\")\nresult = regularClient.medicalRecords.patients.find_one({\"name\": \"Jon Doe\"})\npprint.pprint(result)\n\nprint(\"Finding a document with encrypted client\")\npprint.pprint(secureClient.medicalRecords.patients.find_one({\"name\": \"Jon Doe\"}))","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-function">print</span>(<span class="lg-highlight-string">"Finding a document with regular (non-encrypted) client."</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">result = regularClient.<span class="lg-highlight-property">medicalRecords</span>.<span class="lg-highlight-property">patients</span>.<span class="lg-highlight-title lg-highlight-function">find_one</span>({<span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"Jon Doe"</span>})</td></tr><tr class=""><td class="leafygreen-ui-7razhx">pprint.<span class="lg-highlight-title lg-highlight-function">pprint</span>(result)</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-function">print</span>(<span class="lg-highlight-string">"Finding a document with encrypted client"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">pprint.<span class="lg-highlight-title lg-highlight-function">pprint</span>(secureClient.<span class="lg-highlight-property">medicalRecords</span>.<span class="lg-highlight-property">patients</span>.<span class="lg-highlight-title lg-highlight-function">find_one</span>({<span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"Jon Doe"</span>}))</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-222-menu" aria-describedby="select-222-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-223" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9p:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9p:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9p:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9p:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <p class="leafygreen-ui-1kp3ins"> The output of the preceding code snippet should look like this: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Finding a document with regular (non-encrypted) client.\n\n{\n _id: new ObjectId(\"629a452e0861b3130887103a\"),\n name: 'Jon Doe',\n ssn: new Binary(Buffer.from(\"0217482732d8014cdd9ffdd6e2966e5e7910c20697e5f4fa95710aafc9153f0a3dc769c8a132a604b468732ff1f4d8349ded3244b59cbfb41444a210f28b21ea1b6c737508d9d30e8baa30c1d8070c4d5e26\", \"hex\"), 6),\n bloodType: new Binary(Buffer.from(\"0217482732d8014cdd9ffdd6e2966e5e79022e238536dfd8caadb4d7751ac940e0f195addd7e5c67b61022d02faa90283ab69e02303c7e4001d1996128428bf037dea8bbf59fbb20c583cbcff2bf3e2519b4\", \"hex\"), 6),\n 'key-id': 'demo-data-key',\n medicalRecords: new Binary(Buffer.from(\"0217482732d8014cdd9ffdd6e2966e5e790405163a3207cff175455106f57eef14e5610c49a99bcbd14a7db9c5284e45e3ee30c149354015f941440bf54725d6492fb3b8704bc7c411cff6c868e4e13c58233c3d5ed9593eca4e4d027d76d3705b6d1f3b3c9e2ceee195fd944b553eb27eee69e5e67c338f146f8445995664980bf0\", \"hex\"), 6),\n insurance: {\n policyNumber: new Binary(Buffer.from(\"0217482732d8014cdd9ffdd6e2966e5e79108decd85c05be3fec099e015f9d26d9234605dc959cc1a19b63072f7ffda99db38c7b487de0572a03b2139ac3ee163bcc40c8508f366ce92a5dd36e38b3c742f7\", \"hex\"), 6),\n provider: 'MaestCare'\n }\n}\n\nFinding a document with encrypted client\n\n{\n _id: new ObjectId(\"629a452e0861b3130887103a\"),\n name: 'Jon Doe',\n ssn: 241014209,\n bloodType: 'AB+',\n 'key-id': 'demo-data-key',\n medicalRecords: [ { weight: 180, bloodPressure: '120/80' } ],\n insurance: { policyNumber: 123142, provider: 'MaestCare' }\n}\n","programmingLanguage":"JSON"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">Finding a document with regular (non-encrypted) client.</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-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _id<span class="lg-highlight-punctuation">:</span> new ObjectId(<span class="lg-highlight-string">"629a452e0861b3130887103a"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> name<span class="lg-highlight-punctuation">:</span> 'Jon Doe'<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ssn<span class="lg-highlight-punctuation">:</span> new Binary(Buffer.from(<span class="lg-highlight-string">"0217482732d8014cdd9ffdd6e2966e5e7910c20697e5f4fa95710aafc9153f0a3dc769c8a132a604b468732ff1f4d8349ded3244b59cbfb41444a210f28b21ea1b6c737508d9d30e8baa30c1d8070c4d5e26"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-string">"hex"</span>)<span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-number">6</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> bloodType<span class="lg-highlight-punctuation">:</span> new Binary(Buffer.from(<span class="lg-highlight-string">"0217482732d8014cdd9ffdd6e2966e5e79022e238536dfd8caadb4d7751ac940e0f195addd7e5c67b61022d02faa90283ab69e02303c7e4001d1996128428bf037dea8bbf59fbb20c583cbcff2bf3e2519b4"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-string">"hex"</span>)<span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-number">6</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> 'key-id'<span class="lg-highlight-punctuation">:</span> 'demo-data-key'<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> medicalRecords<span class="lg-highlight-punctuation">:</span> new Binary(Buffer.from(<span class="lg-highlight-string">"0217482732d8014cdd9ffdd6e2966e5e790405163a3207cff175455106f57eef14e5610c49a99bcbd14a7db9c5284e45e3ee30c149354015f941440bf54725d6492fb3b8704bc7c411cff6c868e4e13c58233c3d5ed9593eca4e4d027d76d3705b6d1f3b3c9e2ceee195fd944b553eb27eee69e5e67c338f146f8445995664980bf0"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-string">"hex"</span>)<span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-number">6</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> insurance<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> policyNumber<span class="lg-highlight-punctuation">:</span> new Binary(Buffer.from(<span class="lg-highlight-string">"0217482732d8014cdd9ffdd6e2966e5e79108decd85c05be3fec099e015f9d26d9234605dc959cc1a19b63072f7ffda99db38c7b487de0572a03b2139ac3ee163bcc40c8508f366ce92a5dd36e38b3c742f7"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-string">"hex"</span>)<span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-number">6</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> provider<span class="lg-highlight-punctuation">:</span> 'MaestCare'</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">Finding a document with encrypted client</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-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _id<span class="lg-highlight-punctuation">:</span> new ObjectId(<span class="lg-highlight-string">"629a452e0861b3130887103a"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> name<span class="lg-highlight-punctuation">:</span> 'Jon Doe'<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ssn<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">241014209</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> bloodType<span class="lg-highlight-punctuation">:</span> 'AB+'<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> 'key-id'<span class="lg-highlight-punctuation">:</span> 'demo-data-key'<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> medicalRecords<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span> <span class="lg-highlight-punctuation">{</span> weight<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">180</span><span class="lg-highlight-punctuation">,</span> bloodPressure<span class="lg-highlight-punctuation">:</span> '<span class="lg-highlight-number">120</span>/<span class="lg-highlight-number">80</span>' <span class="lg-highlight-punctuation">}</span> <span class="lg-highlight-punctuation">]</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> insurance<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span> policyNumber<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">123142</span><span class="lg-highlight-punctuation">,</span> provider<span class="lg-highlight-punctuation">:</span> 'MaestCare' <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre> </div> </div> </div> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> See: Complete Code </strong> </h3> <div class="leafygreen-ui-9mycqc"> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-31"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_pn0edb5r3" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_v20wg1cjt" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_so3rgbsle" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_k78nop2od" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_am1xi2239" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_wezajtgmk" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_8wxyvrbmp" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_blqreermf" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_g6bc6wmuj" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_pyqmmp8ec" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_c7l7uqpjy" class="leafygreen-ui-38lglc" id="_8le87x1nu" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for finding a document with encrypted fields, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/dotnet/local/reader/CSFLE/InsertEncryptedDocument.cs" rel="noopener noreferrer"> <span> our Github repository </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> </p> </div> </div> </div> <div> <div aria-labelledby="_ij6g4p2yx" class="leafygreen-ui-38lglc" id="_ny5soksc7" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for finding a document with encrypted fields, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/go/local/reader/insert-encrypted-document.go" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_mr33a84uk" class="leafygreen-ui-38lglc" id="_0vvspuld2" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for finding a document with encrypted fields, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/java/local/reader/src/main/java/com/mongodb/csfle/InsertEncryptedDocument.java" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_tt5ngb6zr" class="" id="_ksejevbda" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for finding a document with encrypted fields, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/node/local/reader/insert_encrypted_document.js" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> <div> <div aria-labelledby="_i8lwkn8j5" class="leafygreen-ui-38lglc" id="_qt0tmuvo9" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To view the complete code for finding a document with encrypted fields, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/python/local/reader/insert_encrypted_document.py" rel="noopener noreferrer"> <span> our Github repository <!-- --> . </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> </p> </div> </div> </div> </div> </div> </div> </div> </section> </div> </div> </div> </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> <p class="leafygreen-ui-1kp3ins"> To view a tutorial on production-ready CSFLE with a remote KMS, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/tutorials/#std-label-csfle-tutorial-automatic-encryption"> Tutorials <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> To learn how CSFLE works, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/#std-label-csfle-fundamentals"> Fundamentals <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> To learn more about the topics mentioned in this guide, see the following links: </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/queryable-encryption/fundamentals/keys-key-vaults/#std-label-qe-reference-keys-key-vaults"> Customer Master Keys </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers"> Key Management System providers </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/keys-key-vaults/#std-label-qe-reference-keys-key-vaults"> Data Encryption Keys </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/keys-key-vaults/#std-label-qe-reference-keys-key-vaults"> Key Vault collections </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/encryption-schemas/#std-label-csfle-reference-encryption-schemas"> Encryption Schemas </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/install-library/#std-label-csfle-reference-mongocryptd"> mongocryptd </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/csfle-options-clients/#std-label-csfle-reference-mongo-client"> CSFLE-specific MongoClient settings </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/automatic-encryption/#std-label-csfle-fundamentals-automatic-encryption"> Automatic CSFLE Writes </a> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/core/queryable-encryption/tutorials/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Tutorials <a class="headerlink leafygreen-ui-1kepx47" href="#tutorials" 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="tutorials"> </div> </a> </h1> <p class="leafygreen-ui-1kp3ins"> Read the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/overview-enable-qe/#std-label-qe-overview-enable-qe"> Overview: Enable Queryable Encryption </a> section to set up your development environment and data keys, then the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/overview-use-qe/#std-label-qe-overview-use-qe"> Overview: Use Queryable Encryption </a> section to learn how to use Queryable Encryption with your preferred Key Management System. </p> <p class="leafygreen-ui-1kp3ins"> To learn how to use Queryable Encryption with a local key (not for production), see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/quick-start/#std-label-qe-quick-start"> Quick Start <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> To learn how to use explicit encryption with Queryable Encryption, read <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/tutorials/explicit-encryption/#std-label-qe-tutorials-manual-encryption"> Use Explicit Encryption <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Each tutorial provides a sample application in multiple languages for each supported Key Management System. </p> <p class="leafygreen-ui-1kp3ins"> Code samples for specific language drivers: </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://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/python/" rel="noopener noreferrer"> <span> Python </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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/node/" rel="noopener noreferrer"> <span> Node.js </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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/java/" rel="noopener noreferrer"> <span> Java </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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/go/" rel="noopener noreferrer"> <span> Go </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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/csharp/" rel="noopener noreferrer"> <span> C#/.NET </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> </p> </li> </ul> </section>
https://www.mongodb.com/docs/manual/core/queryable-encryption/quick-start/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Quick Start <a class="headerlink leafygreen-ui-1kepx47" href="#quick-start" 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="quick-start"> </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="#overview" target="_self"> <span> Overview </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#before-you-get-started" target="_self"> <span> Before You Get Started </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#full-application-code" target="_self"> <span> Full Application Code </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#procedure" target="_self"> <span> Procedure </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#assign-your-application-variables" target="_self"> <span> Assign Your Application Variables </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-your-encrypted-collection" target="_self"> <span> Create your Encrypted Collection </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#insert-a-document-with-encrypted-fields" target="_self"> <span> Insert a Document with Encrypted Fields </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#query-on-an-encrypted-field" target="_self"> <span> Query on an Encrypted Field </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Overview <a class="headerlink leafygreen-ui-1kepx47" href="#overview" 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="overview"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This guide shows you how to build an application that implements the MongoDB Queryable Encryption feature to automatically encrypt and decrypt document fields. </p> <p class="leafygreen-ui-1kp3ins"> Select your driver language in the dropdown menu on the right to learn how to create an application that automatically encrypts and decrypts document fields. </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Do Not Use this Sample Application In Production </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Because the instructions in this tutorial include storing an encryption key in an insecure environment, you should not use an unmodified version of this application in production. Using this application in production risks unauthorized access to the encryption key or loss of the key needed to decrypt your data. The purpose of this tutorial is to demonstrate how to use Queryable Encryption without needing to set up a Key Management System. </p> <p class="leafygreen-ui-1kp3ins"> You can use a Key Management System to securely store your encryption key in a production environment. A <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> is a remote service that securely stores and manages your encryption keys. To learn how to set up a Queryable Encryption enabled application that uses a <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> , see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/tutorials/#std-label-qe-tutorial-automatic-encryption"> Queryable Encryption Tutorials <!-- --> . </a> </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-guide-intro"> </span> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-create-a-master-key"> </span> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-download-example-qe-project"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Before You Get Started <a class="headerlink leafygreen-ui-1kepx47" href="#before-you-get-started" 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="before-you-get-started"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To complete and run the code in this guide, you need to set up your development environment as shown in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/install/#std-label-qe-install"> Install a Queryable Encryption Compatible Driver </a> page. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Full Application Code <a class="headerlink leafygreen-ui-1kepx47" href="#full-application-code" 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="full-application-code"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To see the complete code for the sample application, select your programming language in the language selector. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-7"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_ksvkwu3lh" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_cu29tx3ge" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_i8viib91e" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_o6gv2hh2r" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_xao0q3p91" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_3mntrvu0r" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_8b2yn71kd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_cjnfkonir" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_i9gfw1wk1" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_hze75wo3n" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_u83f6mcme" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_72m8ebmva" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_jqkz5lyyc" class="leafygreen-ui-38lglc" id="_1g9juqoxl" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/mongosh/" rel="noopener noreferrer"> <span> Complete mongosh Application </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> </p> </div> </div> </div> <div> <div aria-labelledby="_9tngk4gp1" class="leafygreen-ui-38lglc" id="_68h8qr4bu" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/csharp/" rel="noopener noreferrer"> <span> Complete C# Application </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> </p> </div> </div> </div> <div> <div aria-labelledby="_jimb3auh3" class="leafygreen-ui-38lglc" id="_infsdypdt" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/go/" rel="noopener noreferrer"> <span> Complete Go Application </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> </p> </div> </div> </div> <div> <div aria-labelledby="_eqkyaq5e0" class="leafygreen-ui-38lglc" id="_6da7nkthr" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/java/" rel="noopener noreferrer"> <span> Complete Java Application </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> </p> </div> </div> </div> <div> <div aria-labelledby="_e2gelsmxl" class="" id="_u4j4znqds" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/node/" rel="noopener noreferrer"> <span> Complete Node.js Application </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> </p> </div> </div> </div> <div> <div aria-labelledby="_qv4e7kid8" class="leafygreen-ui-38lglc" id="_430av6u7q" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/python/" rel="noopener noreferrer"> <span> Complete Python Application </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> </p> </div> </div> </div> </div> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Procedure <a class="headerlink leafygreen-ui-1kepx47" href="#procedure" 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="procedure"> </div> </a> </h2> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"The code samples in this tutorial use the following variables to perform\nthe Queryable Encryption workflow:kmsProviderName - The KMS you're using to store your Customer Master Key.\nSet this variable to \"local\" for this tutorial.uri - Your MongoDB deployment connection URI. Set your connection\nURI in the MONGODB_URI environment variable or replace the value\ndirectly.keyVaultDatabaseName - The database in MongoDB where your data\nencryption keys (DEKs) will be stored. Set this variable\nto \"encryption\".keyVaultCollectionName - The collection in MongoDB where your DEKs\nwill be stored. Set this variable to \"__keyVault\", which is the convention\nto help prevent mistaking it for a user collection.keyVaultNamespace - The namespace in MongoDB where your DEKs will\nbe stored. Set this variable to the values of the keyVaultDatabaseName\nand keyVaultCollectionName variables, separated by a period.encryptedDatabaseName - The database in MongoDB where your encrypted\ndata will be stored. Set this variable to \"medicalRecords\".encryptedCollectionName - The collection in MongoDB where your encrypted\ndata will be stored. Set this variable to \"patients\".You can declare these variables by using the following code:kmsProviderName - The KMS you're using to store your Customer Master Key.\nSet this value to \"local\" for this tutorial.keyVaultDatabaseName - The database in MongoDB where your data\nencryption keys (DEKs) will be stored. Set the value of keyVaultDatabaseName\nto \"encryption\".keyVaultCollectionName - The collection in MongoDB where your DEKs\nwill be stored. Set this variable to \"__keyVault\", which is the\nconvention to help prevent mistaking it for a user collection.keyVaultNamespace - The namespace in MongoDB where your DEKs will\nbe stored. Set keyVaultNamespace to a new CollectionNamespace object whose name\nis the values of the keyVaultDatabaseName and keyVaultCollectionName variables,\nseparated by a period.encryptedDatabaseName - The database in MongoDB where your encrypted\ndata will be stored. Set the value of encryptedDatabaseName to \"medicalRecords\".encryptedCollectionName - The collection in MongoDB where your encrypted\ndata will be stored. Set the value of encryptedCollectionName to \"patients\".uri - Your MongoDB deployment connection URI. Set your connection\nURI in the appsettings.json file or replace the value\ndirectly.You can declare these variables by using the following code:kmsProviderName - The KMS you're using to store your Customer Master Key.\nSet this variable to \"local\" for this tutorial.uri - Your MongoDB deployment connection URI. Set your connection\nURI in the MONGODB_URI environment variable or replace the value\ndirectly.keyVaultDatabaseName - The database in MongoDB where your data\nencryption keys (DEKs) will be stored. Set this variable\nto \"encryption\".keyVaultCollectionName - The collection in MongoDB where your DEKs\nwill be stored. Set this variable to \"__keyVault\", which is the convention\nto help prevent mistaking it for a user collection.keyVaultNamespace - The namespace in MongoDB where your DEKs will\nbe stored. Set this variable to the values of the keyVaultDatabaseName\nand keyVaultCollectionName variables, separated by a period.encryptedDatabaseName - The database in MongoDB where your encrypted\ndata will be stored. Set this variable to \"medicalRecords\".encryptedCollectionName - The collection in MongoDB where your encrypted\ndata will be stored. Set this variable to \"patients\".You can declare these variables by using the following code:kmsProviderName - The KMS you're using to store your Customer Master Key.\nSet this variable to \"local\" for this tutorial.uri - Your MongoDB deployment connection URI. Set your connection\nURI in the MONGODB_URI environment variable or replace the value\ndirectly.keyVaultDatabaseName - The database in MongoDB where your data\nencryption keys (DEKs) will be stored. Set this variable\nto \"encryption\".keyVaultCollectionName - The collection in MongoDB where your DEKs\nwill be stored. Set this variable to \"__keyVault\", which is the convention\nto help prevent mistaking it for a user collection.keyVaultNamespace - The namespace in MongoDB where your DEKs will\nbe stored. Set this variable to the values of the keyVaultDatabaseName\nand keyVaultCollectionName variables, separated by a period.encryptedDatabaseName - The database in MongoDB where your encrypted\ndata will be stored. Set this variable to \"medicalRecords\".encryptedCollectionName - The collection in MongoDB where your encrypted\ndata will be stored. Set this variable to \"patients\".You can declare these variables by using the following code:kmsProviderName - The KMS you're using to store your Customer Master Key.\nSet this variable to \"local\" for this tutorial.uri - Your MongoDB deployment connection URI. Set your connection\nURI in the MONGODB_URI environment variable or replace the value\ndirectly.keyVaultDatabaseName - The database in MongoDB where your data\nencryption keys (DEKs) will be stored. Set this variable\nto \"encryption\".keyVaultCollectionName - The collection in MongoDB where your DEKs\nwill be stored. Set this variable to \"__keyVault\", which is the convention\nto help prevent mistaking it for a user collection.keyVaultNamespace - The namespace in MongoDB where your DEKs will\nbe stored. Set this variable to the values of the keyVaultDatabaseName\nand keyVaultCollectionName variables, separated by a period.encryptedDatabaseName - The database in MongoDB where your encrypted\ndata will be stored. Set this variable to \"medicalRecords\".encryptedCollectionName - The collection in MongoDB where your encrypted\ndata will be stored. Set this variable to \"patients\".You can declare these variables by using the following code:kms_provider_name - The KMS you're using to store your Customer Master Key.\nSet this variable to \"local\" for this tutorial.uri - Your MongoDB deployment connection URI. Set your connection\nURI in the MONGODB_URI environment variable or replace the value\ndirectly.key_vault_database_name - The database in MongoDB where your data\nencryption keys (DEKs) will be stored. Set this variable\nto \"encryption\".key_vault_collection_name - The collection in MongoDB where your DEKs\nwill be stored. Set this variable to \"__keyVault\", which is the\nconvention to help prevent mistaking it for a user collection.key_vault_namespace - The namespace in MongoDB where your DEKs will\nbe stored. Set this variable to the values of the key_vault_database_name\nand key_vault_collection_name variables, separated by a period.encrypted_database_name - The database in MongoDB where your encrypted\ndata will be stored. Set this variable to \"medicalRecords\".encrypted_collection_name - The collection in MongoDB where your encrypted\ndata will be stored. Set this variable to \"patients\".You can declare these variables by using the following code:To complete this tutorial, the database user your application uses to connect to\nMongoDB must have dbAdmin permissions on the following namespaces:encryption.__keyVaultmedicalRecords databaseThe sample code in this tutorial references environment variables that\nyou need to set. Alternatively, you can replace the values directly in\nthe code.To learn how you can setup these environment variables, see the\nREADME.md file\nincluded in the sample application on GitHub.The sample code in this tutorial references environment variables that\nyou need to set. Alternatively, you can replace the values directly in\nthe code.To learn how you can setup these environment variables, see the\nREADME.md file\nincluded in the sample application on GitHub.The sample code in this tutorial references environment variables that\nyou need to set. Alternatively, you can replace the values directly in\nthe code.To learn how you can setup these environment variables, see the\nREADME.md file\nincluded in the sample application on GitHub.The sample code in this tutorial references environment variables that\nyou need to set. Alternatively, you can replace the values directly in\nthe code.To learn how you can setup these environment variables, see the\nREADME.md file\nincluded in the sample application on GitHub.The sample code in this tutorial references environment variables that\nyou need to set. Alternatively, you can replace the values directly in\nthe code.To learn how you can setup these environment variables, see the\nREADME.md file\nincluded in the sample application on GitHub.The sample code in this tutorial references environment variables that\nyou need to set. Alternatively, you can replace the values directly in\nthe code.To learn how you can setup these environment variables, see the\nREADME.md file\nincluded in the sample application on GitHub.","name":"Assign Your Application Variables"},{"@type":"HowToStep","text":"Create a Customer Master KeyYou must create a Customer Master Key (CMK (Customer Master Key)) to perform Queryable Encryption.Create a 96-byte Customer Master Key and save it to your filesystem as the\nfile customer-master-key.txt:We recommend storing your Customer Master Keys in a remote Key Management System (KMS (Key Management System)). To learn how to use\na remote KMS (Key Management System) in your Queryable Encryption implementation, see the\nTutorials guide.If you choose to use a local key provider in production, exercise great\ncaution and do not store it on the file system. Consider injecting the key\ninto your client application using a sidecar process, or use another\napproach that keeps the key secure.Use the following command to generate a CMK (Customer Master Key)\nfrom a Unix shell or PowerShell:Unix shell:PowerShell:Save the output of the preceding command to a file named customer-master-key.txt.Retrieve the Customer Master Key and Specify KMS Provider SettingsRetrieve the contents of the Customer Master Key file that you generated\nin the Create a Customer Master Key step of this guide.Use the CMK (Customer Master Key) value in your KMS provider settings. The\nclient uses these settings to discover the CMK (Customer Master Key). Set the\nprovider name to local to indicate that you are using a\nLocal Key Provider.Set Your Automatic Encryption OptionsCreate an autoEncryptionOptions object that contains the following\noptions:The namespace of your Key Vault collectionThe kmsProviderCredentials object, defined in the previous stepCreate an AutoEncryptionOptions object that contains the following\noptions:The namespace of your Key Vault collectionThe kmsProviderCredentials object, defined in the previous stepyour Automatic Encryption Shared LibraryCreate an AutoEncryption object that contains the following\noptions:The namespace of your Key Vault collectionThe kmsProviderCredentials object, defined in the previous stepyour Automatic Encryption Shared LibraryCreate an AutoEncryptionSettings object that contains the following\noptions:The namespace of your Key Vault collectionThe kmsProviderCredentials object, defined in the previous stepyour Automatic Encryption Shared LibraryCreate an autoEncryptionOptions object that contains the following\noptions:The namespace of your Key Vault collectionThe kmsProviders object, defined in the previous stepyour Automatic Encryption Shared LibraryCreate an AutoEncryptionOpts object that contains the following\noptions:The kms_provider_credentials object, defined in the previous stepThe namespace of your Key Vault collectionThe path to your Automatic Encryption Shared LibraryThe automatic encryption options provide configuration\ninformation to the Automatic Encryption Shared Library,\nwhich modifies the application's behavior when accessing encrypted fields.To learn more about the Automatic Encryption Shared Library, see\nthe Automatic Encryption Shared Library page.Create a Client to Set Up an Encrypted CollectionTo create a client used to encrypt and decrypt data in\nyour collection, instantiate a new MongoClient by using your\nconnection URI and your automatic encryption options.IMPORTANT: If you are using the .NET/C# Driver version 3.0 or later,\nyou must add the following code to your application before\ninstantiating a new MongoClient:Instantiate a new MongoClient by using your\nconnection URI and automatic encryption options:Specify Fields to EncryptTo encrypt a field, add it to the encryption schema.\nTo enable queries on a field, add the \"queries\"\nproperty. Create the encryption schema as follows:In the previous code sample, both the \"ssn\" and\n\"billing\" fields are encrypted, but only the \"ssn\"\nfield can be queried.Create the CollectionInstantiate ClientEncryption to access the API for the\nencryption helper methods.Because you are using a local Customer Master Key, you don't need to\nprovide Customer Master Key credentials. Create a variable\ncontaining an empty object to use in place of credentials when you\ncreate your encrypted collection.Create your encrypted collection by using the encryption\nhelper method accessed through the ClientEncryption class.\nThis method automatically generates data encryption keys for your\nencrypted fields and creates the encrypted collection:The C# version of this tutorial uses separate classes as data models\nto represent the document structure.\nAdd the following Patient, PatientRecord, and PatientBilling\nclasses to your project:After you've added these classes, create your encrypted collection by\nusing the encryption helper method accessed through the\nClientEncryption class.\nThis method automatically generates data encryption keys for your\nencrypted fields and creates the encrypted collection:The method that creates the encrypted collection requires a reference\nto a database object rather than the database name. You can\nobtain this reference by using a method on your client object.The Golang version of this tutorial uses data models to\nrepresent the document structure. Add the following\nstructs to your project to represent the data in your\ncollection:After you've added these classes, create your encrypted\ncollection by using the encryption helper method accessed\nthrough the ClientEncryption class.\nThis method automatically generates data encryption keys for your\nencrypted fields and creates the encrypted collection:The method that creates the encrypted collection requires a reference\nto a database object rather than the database name. You can\nobtain this reference by using a method on your client object.Create your encrypted collection by using the encryption\nhelper method accessed through the ClientEncryption class.\nThis method automatically generates data encryption keys for your\nencrypted fields and creates the encrypted collection:The method that creates the encrypted collection requires a reference\nto a database object rather than the database name. You can\nobtain this reference by using a method on your client object.Create your encrypted collection by using the encryption\nhelper method accessed through the ClientEncryption class.\nThis method automatically generates data encryption keys for your\nencrypted fields and creates the encrypted collection:When using the Node.js driver v6.0 and later, you must import\nClientEncryption from mongodb.For earlier driver versions, import ClientEncryption from\nmongodb-client-encryption.The method that creates the encrypted collection requires a reference\nto a database object rather than the database name. You can\nobtain this reference by using a method on your client object.Create your encrypted collection by using the encryption\nhelper method accessed through the ClientEncryption class.\nThis method automatically generates data encryption keys for your\nencrypted fields and creates the encrypted collection:The method that creates the encrypted collection requires a reference\nto a database object rather than the database name. You can\nobtain this reference by using a method on your client object.","name":"Create your Encrypted Collection"},{"@type":"HowToStep","text":"Create a sample document that describes a patient's personal information.\nUse the encrypted client to insert it into the patients collection,\nas shown in the following example:Create a sample document that describes a patient's personal information.\nUse the encrypted client to insert it into the patients collection,\nas shown in the following example:Create a sample document that describes a patient's personal information.\nUse the encrypted client to insert it into the patients collection,\nas shown in the following example:This tutorial uses POJOs as data models\nto represent the document structure. To set up your application to\nuse POJOs, add the following code:To learn more about Java POJOs, see the Plain Old Java Object\nwikipedia article.This tutorial uses the following POJOs:PatientPatientRecordPatientBillingYou can view these classes in the models package of the complete Java application.Add these POJO classes to your application. Then, create an instance\nof a Patient that describes a patient's personal information. Use\nthe encrypted client to insert it into the patients collection,\nas shown in the following example:Create a sample document that describes a patient's personal information.\nUse the encrypted client to insert it into the patients collection,\nas shown in the following example:Create a sample document that describes a patient's personal information.\nUse the encrypted client to insert it into the patients collection,\nas shown in the following example:","name":"Insert a Document with Encrypted Fields"},{"@type":"HowToStep","text":"The following code sample executes a find query on an encrypted field and\nprints the decrypted data:The output of the preceding code sample should look similar to the\nfollowing:The __safeContent__ field is essential to Queryable Encryption. Do not modify\nthe contents of this field.","name":"Query on an Encrypted Field"}],"name":"Procedure","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Assign Your Application Variables <a class="headerlink leafygreen-ui-1kepx47" href="#assign-your-application-variables" 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="assign-your-application-variables"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The code samples in this tutorial use the following variables to perform the Queryable Encryption workflow: </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-10"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_t72g57dro" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ms0nq6syt" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_euv9g2gb4" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_9dxwz7pmi" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_ctqebqxpa" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_4c9h0gc8u" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_41ugmgb41" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_8rio2uqkj" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_3003c26ur" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_f51tdh8r2" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_cl4ht3892" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_wj4j7h2l5" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_n0q3d0no0" class="leafygreen-ui-38lglc" id="_y1ohwssdm" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> kmsProviderName </strong> - The KMS you're using to store your Customer Master Key. Set this variable to <code class="leafygreen-ui-1l06pbn"> "local" </code> for this tutorial. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> uri </strong> - Your MongoDB deployment connection URI. Set your connection URI in the <code class="leafygreen-ui-1l06pbn"> MONGODB_URI </code> environment variable or replace the value directly. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultDatabaseName </strong> - The database in MongoDB where your data encryption keys (DEKs) will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "encryption" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultCollectionName </strong> - The collection in MongoDB where your DEKs will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "__keyVault" </code> , which is the convention to help prevent mistaking it for a user collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultNamespace </strong> - The namespace in MongoDB where your DEKs will be stored. Set this variable to the values of the <code class="leafygreen-ui-1l06pbn"> keyVaultDatabaseName </code> and <code class="leafygreen-ui-1l06pbn"> keyVaultCollectionName </code> variables, separated by a period. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encryptedDatabaseName </strong> - The database in MongoDB where your encrypted data will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "medicalRecords" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encryptedCollectionName </strong> - The collection in MongoDB where your encrypted data will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "patients" </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You can declare these variables by using the following code: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// KMS provider name should be one of the following: \"aws\", \"gcp\", \"azure\", \"kmip\" or \"local\"\nconst kmsProviderName = \"&lt;your&gt;\";\n\nconst uri = process.env.MONGODB_URI; // Your connection URI\n\nconst keyVaultDatabaseName = \"encryption\";\nconst keyVaultCollectionName = \"__keyVault\";\nconst keyVaultNamespace = `${keyVaultDatabaseName}.${keyVaultCollectionName}`;\nconst encryptedDatabaseName = \"medicalRecords\";\nconst encryptedCollectionName = \"patients\";","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">// KMS</span><span class="lg-highlight-comment"> provider name should </span><span class="lg-highlight-comment">be one of the following: "aws", "gcp", "azure", "kmip" or "local"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> kmsProviderName <!-- -->= <span class="lg-highlight-string">"&lt;Your KMS Provider Name&gt;"</span>;</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-keyword">const</span> uri <!-- -->= <!-- -->process.<span class="lg-highlight-property">env</span>.<span class="lg-highlight-property">MONGODB_URI</span>; <span class="lg-highlight-comment">// Your connection URI</span></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-keyword">const</span> keyVaultDatabaseName <!-- -->= <span class="lg-highlight-string">"encryption"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultCollectionName <!-- -->= <span class="lg-highlight-string">"__keyVault"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultNamespace <!-- -->= <span class="lg-highlight-string">`</span><span class="lg-highlight-subst lg-highlight-string">${keyVaultDatabaseName}</span><span class="lg-highlight-string">.</span><span class="lg-highlight-subst lg-highlight-string">${keyVaultCollectionName}</span><span class="lg-highlight-string">`</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> encryptedDatabaseName <!-- -->= <span class="lg-highlight-string">"medicalRecords"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> encryptedCollectionName <!-- -->= <span class="lg-highlight-string">"patients"</span>;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-30-menu" aria-describedby="select-30-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-31" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9c:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9c:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9c:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9c:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_gmtqq1tti" class="leafygreen-ui-38lglc" id="_mv5bd11ad" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> kmsProviderName </strong> - The KMS you're using to store your Customer Master Key. Set this value to <code class="leafygreen-ui-1l06pbn"> "local" </code> for this tutorial. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultDatabaseName </strong> - The database in MongoDB where your data encryption keys (DEKs) will be stored. Set the value of <code class="leafygreen-ui-1l06pbn"> keyVaultDatabaseName </code> to <code class="leafygreen-ui-1l06pbn"> "encryption" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultCollectionName </strong> - The collection in MongoDB where your DEKs will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "__keyVault" </code> , which is the convention to help prevent mistaking it for a user collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultNamespace </strong> - The namespace in MongoDB where your DEKs will be stored. Set <code class="leafygreen-ui-1l06pbn"> keyVaultNamespace </code> to a new <code class="leafygreen-ui-1l06pbn"> CollectionNamespace </code> object whose name is the values of the <code class="leafygreen-ui-1l06pbn"> keyVaultDatabaseName </code> and <code class="leafygreen-ui-1l06pbn"> keyVaultCollectionName </code> variables, separated by a period. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encryptedDatabaseName </strong> - The database in MongoDB where your encrypted data will be stored. Set the value of <code class="leafygreen-ui-1l06pbn"> encryptedDatabaseName </code> to <code class="leafygreen-ui-1l06pbn"> "medicalRecords" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encryptedCollectionName </strong> - The collection in MongoDB where your encrypted data will be stored. Set the value of <code class="leafygreen-ui-1l06pbn"> encryptedCollectionName </code> to <code class="leafygreen-ui-1l06pbn"> "patients" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> uri </strong> - Your MongoDB deployment connection URI. Set your connection URI in the <code class="leafygreen-ui-1l06pbn"> appsettings.json </code> file or replace the value directly. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You can declare these variables by using the following code: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// KMS provider name should be one of the following: \"aws\", \"gcp\", \"azure\", \"kmip\" or \"local\"\nconst string kmsProviderName = \"&lt;your&gt;\";\nconst string keyVaultDatabaseName = \"encryption\";\nconst string keyVaultCollectionName = \"__keyVault\";\nvar keyVaultNamespace =\n CollectionNamespace.FromFullName($\"{keyVaultDatabaseName}.{keyVaultCollectionName}\");\nconst string encryptedDatabaseName = \"medicalRecords\";\nconst string encryptedCollectionName = \"patients\";\n\nvar appSettings = new ConfigurationBuilder().AddJsonFile(\"appsettings.json\").Build();\nvar uri = appSettings[\"MongoDbUri\"];","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">// KMS</span><span class="lg-highlight-comment"> provider name should </span><span class="lg-highlight-comment">be one of the following: "aws", "gcp", "azure", "kmip" or "local"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> string kmsProviderName = <span class="lg-highlight-string">"&lt;your KMS provider name&gt;"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> string keyVaultDatabaseName = <span class="lg-highlight-string">"encryption"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> string keyVaultCollectionName = <span class="lg-highlight-string">"__keyVault"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> keyVaultNamespace =</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">CollectionNamespace</span>.<span class="lg-highlight-title lg-highlight-class">FromFullName</span>($<span class="lg-highlight-string">"{keyVaultDatabaseName}.{keyVaultCollectionName}"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> string encryptedDatabaseName = <span class="lg-highlight-string">"medicalRecords"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> string encryptedCollectionName = <span class="lg-highlight-string">"patients"</span>;</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-keyword">var</span> appSettings = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ConfigurationBuilder</span>().<span class="lg-highlight-title lg-highlight-class">AddJsonFile</span>(<span class="lg-highlight-string">"appsettings.json"</span>).<span class="lg-highlight-title lg-highlight-class">Build</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> uri = appSettings[<span class="lg-highlight-string">"MongoDbUri"</span>];</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-33-menu" aria-describedby="select-33-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-34" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9d:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9d:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9d:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9d:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_cf5fx9tfk" class="leafygreen-ui-38lglc" id="_qzouxnefc" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> kmsProviderName </strong> - The KMS you're using to store your Customer Master Key. Set this variable to <code class="leafygreen-ui-1l06pbn"> "local" </code> for this tutorial. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> uri </strong> - Your MongoDB deployment connection URI. Set your connection URI in the <code class="leafygreen-ui-1l06pbn"> MONGODB_URI </code> environment variable or replace the value directly. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultDatabaseName </strong> - The database in MongoDB where your data encryption keys (DEKs) will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "encryption" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultCollectionName </strong> - The collection in MongoDB where your DEKs will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "__keyVault" </code> , which is the convention to help prevent mistaking it for a user collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultNamespace </strong> - The namespace in MongoDB where your DEKs will be stored. Set this variable to the values of the <code class="leafygreen-ui-1l06pbn"> keyVaultDatabaseName </code> and <code class="leafygreen-ui-1l06pbn"> keyVaultCollectionName </code> variables, separated by a period. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encryptedDatabaseName </strong> - The database in MongoDB where your encrypted data will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "medicalRecords" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encryptedCollectionName </strong> - The collection in MongoDB where your encrypted data will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "patients" </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You can declare these variables by using the following code: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// KMS provider name should be one of the following: \"aws\", \"gcp\", \"azure\", \"kmip\" or \"local\"\nkmsProviderName := \"&lt;kms&gt;\"\n\nuri := os.Getenv(\"MONGODB_URI\") // Your connection URI\n\nkeyVaultDatabaseName := \"encryption\"\nkeyVaultCollectionName := \"__keyVault\"\nkeyVaultNamespace := keyVaultDatabaseName + \".\" + keyVaultCollectionName\n\nencryptedDatabaseName := \"medicalRecords\"\nencryptedCollectionName := \"patients\"","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">// KMS</span><span class="lg-highlight-comment"> provider name should </span><span class="lg-highlight-comment">be one of the following: "aws", "gcp", "azure", "kmip" or "local"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviderName <!-- -->:<!-- -->= <span class="lg-highlight-string">"&lt;KMS provider name&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">uri <!-- -->:<!-- -->= os.<span class="lg-highlight-title lg-highlight-class">Getenv</span>(<span class="lg-highlight-string">"MONGODB_URI"</span>) <span class="lg-highlight-comment">// Your connection URI</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultDatabaseName <!-- -->:<!-- -->= <span class="lg-highlight-string">"encryption"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultCollectionName <!-- -->:<!-- -->= <span class="lg-highlight-string">"__keyVault"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultNamespace <!-- -->:<!-- -->= keyVaultDatabaseName + <span class="lg-highlight-string">"."</span> + keyVaultCollectionName</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">encryptedDatabaseName <!-- -->:<!-- -->= <span class="lg-highlight-string">"medicalRecords"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">encryptedCollectionName <!-- -->:<!-- -->= <span class="lg-highlight-string">"patients"</span></td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-36-menu" aria-describedby="select-36-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-37" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9e:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9e:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9e:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9e:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_rfjuim0x8" class="leafygreen-ui-38lglc" id="_xoa67t951" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> kmsProviderName </strong> - The KMS you're using to store your Customer Master Key. Set this variable to <code class="leafygreen-ui-1l06pbn"> "local" </code> for this tutorial. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> uri </strong> - Your MongoDB deployment connection URI. Set your connection URI in the <code class="leafygreen-ui-1l06pbn"> MONGODB_URI </code> environment variable or replace the value directly. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultDatabaseName </strong> - The database in MongoDB where your data encryption keys (DEKs) will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "encryption" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultCollectionName </strong> - The collection in MongoDB where your DEKs will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "__keyVault" </code> , which is the convention to help prevent mistaking it for a user collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultNamespace </strong> - The namespace in MongoDB where your DEKs will be stored. Set this variable to the values of the <code class="leafygreen-ui-1l06pbn"> keyVaultDatabaseName </code> and <code class="leafygreen-ui-1l06pbn"> keyVaultCollectionName </code> variables, separated by a period. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encryptedDatabaseName </strong> - The database in MongoDB where your encrypted data will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "medicalRecords" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encryptedCollectionName </strong> - The collection in MongoDB where your encrypted data will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "patients" </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You can declare these variables by using the following code: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// KMS provider name should be one of the following: \"aws\", \"gcp\", \"azure\", \"kmip\" or \"local\"\nString kmsProviderName = \"&lt;kms&gt;\";\n\nString uri = QueryableEncryptionHelpers.getEnv(\"MONGODB_URI\"); // Your connection URI\n\nString keyVaultDatabaseName = \"encryption\";\nString keyVaultCollectionName = \"__keyVault\";\nString keyVaultNamespace = keyVaultDatabaseName + \".\" + keyVaultCollectionName;\nString encryptedDatabaseName = \"medicalRecords\";\nString encryptedCollectionName = \"patients\";","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">// KMS</span><span class="lg-highlight-comment"> provider name should </span><span class="lg-highlight-comment">be one of the following: "aws", "gcp", "azure", "kmip" or "local"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> kmsProviderName = <span class="lg-highlight-string">"&lt;KMS provider name&gt;"</span>;</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">String</span> uri = <span class="lg-highlight-title lg-highlight-class">QueryableEncryptionHelpers</span>.<span class="lg-highlight-title lg-highlight-function">getEnv</span>(<span class="lg-highlight-string">"MONGODB_URI"</span>); <span class="lg-highlight-comment">// Your connection URI</span></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">String</span> keyVaultDatabaseName = <span class="lg-highlight-string">"encryption"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> keyVaultCollectionName = <span class="lg-highlight-string">"__keyVault"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> keyVaultNamespace = keyVaultDatabaseName + <span class="lg-highlight-string">"."</span> + keyVaultCollectionName;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> encryptedDatabaseName = <span class="lg-highlight-string">"medicalRecords"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> encryptedCollectionName = <span class="lg-highlight-string">"patients"</span>;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-39-menu" aria-describedby="select-39-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-40" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9f:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9f:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9f:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9f:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_op2sfiqjr" class="" id="_kxwud9l00" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> kmsProviderName </strong> - The KMS you're using to store your Customer Master Key. Set this variable to <code class="leafygreen-ui-1l06pbn"> "local" </code> for this tutorial. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> uri </strong> - Your MongoDB deployment connection URI. Set your connection URI in the <code class="leafygreen-ui-1l06pbn"> MONGODB_URI </code> environment variable or replace the value directly. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultDatabaseName </strong> - The database in MongoDB where your data encryption keys (DEKs) will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "encryption" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultCollectionName </strong> - The collection in MongoDB where your DEKs will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "__keyVault" </code> , which is the convention to help prevent mistaking it for a user collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> keyVaultNamespace </strong> - The namespace in MongoDB where your DEKs will be stored. Set this variable to the values of the <code class="leafygreen-ui-1l06pbn"> keyVaultDatabaseName </code> and <code class="leafygreen-ui-1l06pbn"> keyVaultCollectionName </code> variables, separated by a period. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encryptedDatabaseName </strong> - The database in MongoDB where your encrypted data will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "medicalRecords" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encryptedCollectionName </strong> - The collection in MongoDB where your encrypted data will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "patients" </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You can declare these variables by using the following code: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// KMS provider name should be one of the following: \"aws\", \"gcp\", \"azure\", \"kmip\" or \"local\"\nconst kmsProviderName = \"&lt;your&gt;\";\n\nconst uri = process.env.MONGODB_URI; // Your connection URI\n\nconst keyVaultDatabaseName = \"encryption\";\nconst keyVaultCollectionName = \"__keyVault\";\nconst keyVaultNamespace = `${keyVaultDatabaseName}.${keyVaultCollectionName}`;\nconst encryptedDatabaseName = \"medicalRecords\";\nconst encryptedCollectionName = \"patients\";","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">// KMS</span><span class="lg-highlight-comment"> provider name should </span><span class="lg-highlight-comment">be one of the following: "aws", "gcp", "azure", "kmip" or "local"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> kmsProviderName <!-- -->= <span class="lg-highlight-string">"&lt;Your KMS Provider Name&gt;"</span>;</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-keyword">const</span> uri <!-- -->= <!-- -->process.<span class="lg-highlight-property">env</span>.<span class="lg-highlight-property">MONGODB_URI</span>; <span class="lg-highlight-comment">// Your connection URI</span></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-keyword">const</span> keyVaultDatabaseName <!-- -->= <span class="lg-highlight-string">"encryption"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultCollectionName <!-- -->= <span class="lg-highlight-string">"__keyVault"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultNamespace <!-- -->= <span class="lg-highlight-string">`</span><span class="lg-highlight-subst lg-highlight-string">${keyVaultDatabaseName}</span><span class="lg-highlight-string">.</span><span class="lg-highlight-subst lg-highlight-string">${keyVaultCollectionName}</span><span class="lg-highlight-string">`</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> encryptedDatabaseName <!-- -->= <span class="lg-highlight-string">"medicalRecords"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> encryptedCollectionName <!-- -->= <span class="lg-highlight-string">"patients"</span>;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-42-menu" aria-describedby="select-42-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-43" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9g:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9g:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9g:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9g:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_pupd0b2hx" class="leafygreen-ui-38lglc" id="_fpng8sux9" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> kms_provider_name </strong> - The KMS you're using to store your Customer Master Key. Set this variable to <code class="leafygreen-ui-1l06pbn"> "local" </code> for this tutorial. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> uri </strong> - Your MongoDB deployment connection URI. Set your connection URI in the <code class="leafygreen-ui-1l06pbn"> MONGODB_URI </code> environment variable or replace the value directly. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> key_vault_database_name </strong> - The database in MongoDB where your data encryption keys (DEKs) will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "encryption" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> key_vault_collection_name </strong> - The collection in MongoDB where your DEKs will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "__keyVault" </code> , which is the convention to help prevent mistaking it for a user collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> key_vault_namespace </strong> - The namespace in MongoDB where your DEKs will be stored. Set this variable to the values of the <code class="leafygreen-ui-1l06pbn"> key_vault_database_name </code> and <code class="leafygreen-ui-1l06pbn"> key_vault_collection_name </code> variables, separated by a period. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encrypted_database_name </strong> - The database in MongoDB where your encrypted data will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "medicalRecords" </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <strong> encrypted_collection_name </strong> - The collection in MongoDB where your encrypted data will be stored. Set this variable to <code class="leafygreen-ui-1l06pbn"> "patients" </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You can declare these variables by using the following code: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"# KMS provider name should be one of the following: \"aws\", \"gcp\", \"azure\", \"kmip\" or \"local\"\nkms_provider_name = \"&lt;kms&gt;\"\n\nuri = os.environ['MONGODB_URI'] # Your connection URI\n\nkey_vault_database_name = \"encryption\"\nkey_vault_collection_name = \"__keyVault\"\nkey_vault_namespace = f\"{key_vault_database_name}.{key_vault_collection_name}\"\nencrypted_database_name = \"medicalRecords\"\nencrypted_collection_name = \"patients\"","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"># <span class="lg-highlight-variable lg-highlight-constant">KMS</span> provider name should be one <span class="lg-highlight-keyword">of</span> the <span class="lg-highlight-attr">following</span>: <span class="lg-highlight-string">"aws"</span>, <span class="lg-highlight-string">"gcp"</span>, <span class="lg-highlight-string">"azure"</span>, <span class="lg-highlight-string">"kmip"</span> or <span class="lg-highlight-string">"local"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">kms_provider_name = <span class="lg-highlight-string">"&lt;KMS provider name&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">uri = os.<span class="lg-highlight-property">environ</span>[<span class="lg-highlight-string">'MONGODB_URI'</span>] # <span class="lg-highlight-title lg-highlight-class">Your</span> connection <span class="lg-highlight-variable lg-highlight-constant">URI</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_database_name = <span class="lg-highlight-string">"encryption"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_collection_name = <span class="lg-highlight-string">"__keyVault"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_namespace = f<span class="lg-highlight-string">"{key_vault_database_name}.{key_vault_collection_name}"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">encrypted_database_name = <span class="lg-highlight-string">"medicalRecords"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">encrypted_collection_name = <span class="lg-highlight-string">"patients"</span></td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-45-menu" aria-describedby="select-45-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-46" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9h:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9h:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9h:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9h:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Key Vault Collection Namespace Permissions </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> To complete this tutorial, the database user your application uses to connect to MongoDB must have <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-dbAdmin"> <code class="leafygreen-ui-1l06pbn"> dbAdmin </code> </a> permissions on the following namespaces: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> encryption.__keyVault </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> medicalRecords </code> database </p> </li> </ul> </div> </div> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-11"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_940el0b0l" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ahclx7l2c" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_jhjy9h07m" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_c5tyhce7k" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_urslb5nal" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_idvumapxd" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_ghehrk6ut" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_e7t4nxqqe" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_15l3io4te" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_cdcb3ua1q" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_jhhwzq9gu" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_dhg9a7ibj" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_9gvf9xbhw" class="leafygreen-ui-38lglc" id="_d3sjarvjm" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Environment Variables </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The sample code in this tutorial references environment variables that you need to set. Alternatively, you can replace the values directly in the code. </p> <p class="leafygreen-ui-1kp3ins"> To learn how you can setup these environment variables, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/node/README.md" rel="noopener noreferrer"> <span> README.md </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> file included in the sample application on GitHub. </p> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_kv93u7ov4" class="leafygreen-ui-38lglc" id="_f0w2be7ft" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Environment Variables </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The sample code in this tutorial references environment variables that you need to set. Alternatively, you can replace the values directly in the code. </p> <p class="leafygreen-ui-1kp3ins"> To learn how you can setup these environment variables, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/csharp/README.md" rel="noopener noreferrer"> <span> README.md </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> file included in the sample application on GitHub. </p> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_npqs8p15y" class="leafygreen-ui-38lglc" id="_nlopq1q6v" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Environment Variables </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The sample code in this tutorial references environment variables that you need to set. Alternatively, you can replace the values directly in the code. </p> <p class="leafygreen-ui-1kp3ins"> To learn how you can setup these environment variables, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/go/README.md" rel="noopener noreferrer"> <span> README.md </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> file included in the sample application on GitHub. </p> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_2m3b68bhk" class="leafygreen-ui-38lglc" id="_5e7j9jmhb" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Environment Variables </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The sample code in this tutorial references environment variables that you need to set. Alternatively, you can replace the values directly in the code. </p> <p class="leafygreen-ui-1kp3ins"> To learn how you can setup these environment variables, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/java/README.md" rel="noopener noreferrer"> <span> README.md </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> file included in the sample application on GitHub. </p> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_zd4n7wxjp" class="" id="_trepz129a" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Environment Variables </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The sample code in this tutorial references environment variables that you need to set. Alternatively, you can replace the values directly in the code. </p> <p class="leafygreen-ui-1kp3ins"> To learn how you can setup these environment variables, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/node/README.md" rel="noopener noreferrer"> <span> README.md </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> file included in the sample application on GitHub. </p> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_4u9nahp0g" class="leafygreen-ui-38lglc" id="_q30wm1lev" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Environment Variables </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The sample code in this tutorial references environment variables that you need to set. Alternatively, you can replace the values directly in the code. </p> <p class="leafygreen-ui-1kp3ins"> To learn how you can setup these environment variables, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/python/README.md" rel="noopener noreferrer"> <span> README.md </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> file included in the sample application on GitHub. </p> </div> </div> </div> </div> </div> </div> </div> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create your Encrypted Collection <a class="headerlink leafygreen-ui-1kepx47" href="#create-your-encrypted-collection" 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-your-encrypted-collection"> </div> </a> </h3> <ol class="leafygreen-ui-rioki0" type="a"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create a Customer Master Key </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-fle-create-a-master-key"> </span> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-quick-start-create-master-key"> </span> <p class="leafygreen-ui-1kp3ins"> You must create a Customer Master Key ( <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> ) to perform Queryable Encryption. </p> <p class="leafygreen-ui-1kp3ins"> Create a 96-byte Customer Master Key and save it to your filesystem as the file <code class="leafygreen-ui-1l06pbn"> customer-master-key.txt </code> : </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-13"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_9wx8r3vpq" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_cbt3xj2bg" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_ns3dpoalj" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_oise1pvkp" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_82g9j255g" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_xjz75j295" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_4a33ccapd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_rn6pzuzut" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_w3ozv3o9r" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_lnwh54slj" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_2pyszec4s" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_r4ql90h87" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_8d0fjjnwr" class="leafygreen-ui-38lglc" id="_09bop8wi9" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"customerMasterKeyPath = \"customer-master-key.txt\";\nif (!fs.existsSync(customerMasterKeyPath)) {\n fs.writeFileSync(customerMasterKeyPath, crypto.randomBytes(96));\n}","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">customerMasterKeyPath <!-- -->= <span class="lg-highlight-string">"customer-master-key.txt"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> <!-- -->(<!-- -->!<!-- -->fs.<span class="lg-highlight-title lg-highlight-function">existsSync</span>(<!-- -->customerMasterKeyPath)) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->fs.<span class="lg-highlight-title lg-highlight-function">writeFileSync</span>(<!-- -->customerMasterKeyPath<!-- -->, <!-- -->crypto.<span class="lg-highlight-title lg-highlight-function">randomBytes</span>(<span class="lg-highlight-number">96</span>))<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-48-menu" aria-describedby="select-48-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-49" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9i:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9i:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9i:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9i:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_npevof7ae" class="leafygreen-ui-38lglc" id="_71g9v8z99" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"using var randomNumberGenerator = RandomNumberGenerator.Create();\ntry\n{\n var bytes = new byte[96];\n randomNumberGenerator.GetBytes(bytes);\n var localCustomerMasterKeyBase64 = Convert.ToBase64String(bytes);\n File.WriteAllText(\"customer-master-key.txt\", localCustomerMasterKeyBase64);\n}\ncatch (Exception e)\n{\n throw new Exception(\"Unable to write Customer Master Key file due to the following error: \" + e.Message);\n}","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">using <span class="lg-highlight-keyword">var</span> randomNumberGenerator = <span class="lg-highlight-title lg-highlight-class">RandomNumberGenerator</span>.<span class="lg-highlight-title lg-highlight-class">Create</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">try</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> bytes = <span class="lg-highlight-keyword">new</span> byte[<span class="lg-highlight-number">96</span>];</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> randomNumberGenerator.<span class="lg-highlight-title lg-highlight-class">GetBytes</span>(bytes);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> localCustomerMasterKeyBase64 = <span class="lg-highlight-title lg-highlight-class">Convert</span>.<span class="lg-highlight-title lg-highlight-class">ToBase64String</span>(bytes);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">File</span>.<span class="lg-highlight-title lg-highlight-class">WriteAllText</span>(<span class="lg-highlight-string">"customer-master-key.txt"</span>, localCustomerMasterKeyBase64);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">catch</span> (<span class="lg-highlight-title lg-highlight-class">Exception</span> e)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">throw</span> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Exception</span>(<span class="lg-highlight-string">"Unable to write Customer Master Key file due to the following error: "</span> + e.<span class="lg-highlight-property">Message</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-51-menu" aria-describedby="select-51-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-52" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9j:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9j:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9j:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9j:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_i21be47wy" class="leafygreen-ui-38lglc" id="_q163e8hdi" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"key := make([]byte, 96)\nif _, err := rand.Read(key); err != nil {\n\tpanic(fmt.Sprintf(\"Unable to create a random 96 byte data key: %v\\n\", err))\n}\nif err := os.WriteFile(\"customer-master-key.txt\", key, 0644); err != nil {\n\tpanic(fmt.Sprintf(\"Unable to write key to file: %v\\n\", err))\n}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">key <!-- -->:<!-- -->= <span class="lg-highlight-title lg-highlight-function">make</span>([]byte, <span class="lg-highlight-number">96</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> _<!-- -->, <!-- -->err := rand.<span class="lg-highlight-title lg-highlight-class">Read</span>(key); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(fmt.<span class="lg-highlight-title lg-highlight-class">Sprintf</span>(<span class="lg-highlight-string">"Unable to create a random 96 byte data key: %v</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>, err))</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err <!-- -->:<!-- -->= os.<span class="lg-highlight-title lg-highlight-class">WriteFile</span>(<span class="lg-highlight-string">"customer-master-key.txt"</span>, key, <span class="lg-highlight-number">0644</span>); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(fmt.<span class="lg-highlight-title lg-highlight-class">Sprintf</span>(<span class="lg-highlight-string">"Unable to write key to file: %v</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>, err))</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-54-menu" aria-describedby="select-54-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-55" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9k:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9k:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9k:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9k:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_dai2qdin4" class="leafygreen-ui-38lglc" id="_5p2nw1ra6" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"byte[] localCustomerMasterKey = new byte[96];\nnew SecureRandom().nextBytes(localCustomerMasterKey);\ntry (FileOutputStream stream = new FileOutputStream(\"customer-master-key.txt\")) {\n stream.write(localCustomerMasterKey);\n\n // ...","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">byte[] localCustomerMasterKey = <span class="lg-highlight-keyword">new</span> byte[<span class="lg-highlight-number">96</span>];</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">SecureRandom</span>().<span class="lg-highlight-title lg-highlight-function">nextBytes</span>(localCustomerMasterKey);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">try</span> (<span class="lg-highlight-title lg-highlight-class">FileOutputStream</span> stream = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">FileOutputStream</span>(<span class="lg-highlight-string">"customer-master-key.txt"</span>)) {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> stream.<span class="lg-highlight-title lg-highlight-function">write</span>(localCustomerMasterKey);</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-comment">// ...</span></td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-57-menu" aria-describedby="select-57-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-58" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9l:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9l:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9l:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9l:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_53cnt11b8" class="" id="_a7j6lp7hw" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"if (!existsSync(\"./customer-master-key.txt\")) {\n try {\n writeFileSync(\"customer-master-key.txt\", randomBytes(96));\n } catch (err) {\n throw new Error(\n `Unable to write Customer Master Key to file due to the following error: ${err}`\n );\n }\n}","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">if</span> <!-- -->(<!-- -->!<span class="lg-highlight-title lg-highlight-function">existsSync</span>(<span class="lg-highlight-string">"./customer-master-key.txt"</span>)) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">try</span> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">writeFileSync</span>(<span class="lg-highlight-string">"customer-master-key.txt"</span>, <span class="lg-highlight-title lg-highlight-function">randomBytes</span>(<span class="lg-highlight-number">96</span>))<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->} <span class="lg-highlight-keyword">catch</span> <!-- -->(<!-- -->err) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">throw</span> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Error</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">`Unable to write Customer Master Key to file due to the following error: </span><span class="lg-highlight-subst lg-highlight-string">${err}</span><span class="lg-highlight-string">`</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-60-menu" aria-describedby="select-60-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-61" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9m:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9m:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9m:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9m:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_954ur32t0" class="leafygreen-ui-38lglc" id="_013joiets" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"path = \"customer-master-key.txt\"\nfile_bytes = os.urandom(96)\nwith open(path, \"wb\") as f:\n f.write(file_bytes)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">path = <span class="lg-highlight-string">"customer-master-key.txt"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">file_bytes = os.<span class="lg-highlight-title lg-highlight-function">urandom</span>(<span class="lg-highlight-number">96</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">with</span> <span class="lg-highlight-title lg-highlight-function">open</span>(path, <span class="lg-highlight-string">"wb"</span>) <span class="lg-highlight-keyword">as</span> <span class="lg-highlight-attr">f</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> f.<span class="lg-highlight-title lg-highlight-function">write</span>(file_bytes)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-63-menu" aria-describedby="select-63-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-64" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9n:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9n:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9n:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9n:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Secure your Local Key File in Production </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> We recommend storing your Customer Master Keys in a remote <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Key_management#Key_management_system" rel="noopener noreferrer"> <span> Key Management System </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> ( <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> ). To learn how to use a remote <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> in your Queryable Encryption implementation, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/tutorials/#std-label-qe-tutorial-automatic-encryption"> Tutorials </a> guide. </p> <p class="leafygreen-ui-1kp3ins"> If you choose to use a local key provider in production, exercise great caution and do not store it on the file system. Consider injecting the key into your client application using a sidecar process, or use another approach that keeps the key secure. </p> </div> </div> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Generate a CMK from the Command Line </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Use the following command to generate a <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> from a Unix shell or PowerShell: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Unix shell: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"echo $(head -c 96 /dev/urandom | base64 | tr -d '\\n')","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">echo $(head -c 96 /dev/urandom | base64 | tr -d '\n')</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> PowerShell: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"$r=[byte[]]::new(64);$g=[System.Security.Cryptography.RandomNumberGenerator]::Create();$g.GetBytes($r);[Convert]::ToBase64String($r)"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" 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">$r=[byte[]]::new(64);$g=[System.Security.Cryptography.RandomNumberGenerator]::Create();$g.GetBytes($r);[Convert]::ToBase64String($r)</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> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Save the output of the preceding command to a file named <code class="leafygreen-ui-1l06pbn"> customer-master-key.txt </code> . </p> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Retrieve the Customer Master Key and Specify KMS Provider Settings </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-field-level-encryption-data-key-create"> </span> <span class="leafygreen-ui-1qnjd6d" id="std-label-field-level-encryption-data-key-create"> </span> <p class="leafygreen-ui-1kp3ins"> Retrieve the contents of the Customer Master Key file that you generated in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-qe-quick-start-create-master-key" target="_self"> <span> Create a Customer Master Key </span> </a> step of this guide. </p> <p class="leafygreen-ui-1kp3ins"> Use the <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> value in your KMS provider settings. The client uses these settings to discover the <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> . Set the provider name to <code class="leafygreen-ui-1l06pbn"> local </code> to indicate that you are using a Local Key Provider. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-14"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_vfa16me45" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_7j9x88yv0" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_611cngcze" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_4b4pzr8yf" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_iifo8mowj" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_x9ur3d8sb" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_bovmt0i6a" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_vex9c7b8j" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_qaomof36b" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_uus9nbsyj" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_bq0i0jyvs" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_4e6u1v6ya" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_xut4dgcj8" class="leafygreen-ui-38lglc" id="_047bapfk4" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// WARNING: Do not use a local key file in a production application\nconst localMasterKey = fs.readFileSync(\"./customer-master-key.txt\");\n\nif (localMasterKey.length !== 96) {\n throw new Error(\n \"Expected the customer master key file to be 96 bytes.\"\n );\n}\n\nkmsProviderCredentials = {\n local: {\n key: localMasterKey,\n },\n};","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">// WARNING: Do</span><span class="lg-highlight-comment"> not use a </span><span class="lg-highlight-comment">local</span><span class="lg-highlight-comment"> key file in </span><span class="lg-highlight-comment">a production application</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> localMasterKey <!-- -->= <!-- -->fs.<span class="lg-highlight-title lg-highlight-function">readFileSync</span>(<span class="lg-highlight-string">"./customer-master-key.txt"</span>)<!-- -->;</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-keyword">if</span> <!-- -->(<!-- -->localMasterKey.<span class="lg-highlight-property">length</span> <!-- -->!<!-- -->== <span class="lg-highlight-number">96</span>) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">throw</span> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Error</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Expected the customer master key file to be 96 bytes."</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> )<!-- -->;</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="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">kmsProviderCredentials <!-- -->= <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">local</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->localMasterKey<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-68-menu" aria-describedby="select-68-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-69" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9o:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9o:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9o:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9o:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_br65aqjgg" class="leafygreen-ui-38lglc" id="_71v84cqkm" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// WARNING: Do not use a local key file in a production application\nvar kmsProviderCredentials = new Dictionary&lt;string,&gt;&gt;();\ntry\n{\n var localCustomerMasterKeyBase64 = File.ReadAllText(\"customer-master-key.txt\");\n var localCustomerMasterKeyBytes = Convert.FromBase64String(localCustomerMasterKeyBase64);\n\n if (localCustomerMasterKeyBytes.Length != 96)\n {\n throw new Exception(\"Expected the customer master key file to be 96 bytes.\");\n }\n\n var localOptions = new Dictionary&lt;string,&gt;\n {\n { \"key\", localCustomerMasterKeyBytes }\n };\n\n kmsProviderCredentials.Add(\"local\", localOptions);\n}","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">// WARNING: Do</span><span class="lg-highlight-comment"> not use a </span><span class="lg-highlight-comment">local</span><span class="lg-highlight-comment"> key file in </span><span class="lg-highlight-comment">a production application</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> kmsProviderCredentials = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span>&lt;string, <span class="lg-highlight-title lg-highlight-class">IReadOnlyDictionary</span>&lt;string, object&gt;&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">try</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> localCustomerMasterKeyBase64 = <span class="lg-highlight-title lg-highlight-class">File</span>.<span class="lg-highlight-title lg-highlight-class">ReadAllText</span>(<span class="lg-highlight-string">"customer-master-key.txt"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> localCustomerMasterKeyBytes = <span class="lg-highlight-title lg-highlight-class">Convert</span>.<span class="lg-highlight-title lg-highlight-class">FromBase64String</span>(localCustomerMasterKeyBase64);</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-keyword">if</span> (localCustomerMasterKeyBytes.<span class="lg-highlight-property">Length</span> != <span class="lg-highlight-number">96</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">throw</span> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Exception</span>(<span class="lg-highlight-string">"Expected the customer master key file to be 96 bytes."</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="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> localOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span>&lt;string, object&gt;</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> {</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"key"</span>, localCustomerMasterKeyBytes }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> };</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> kmsProviderCredentials.<span class="lg-highlight-title lg-highlight-class">Add</span>(<span class="lg-highlight-string">"local"</span>, localOptions);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-71-menu" aria-describedby="select-71-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-72" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9p:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9p:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9p:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9p:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_86laqdoak" class="leafygreen-ui-38lglc" id="_8r6t4pkod" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"key, err := os.ReadFile(\"customer-master-key.txt\")\nif err != nil {\n\tpanic(fmt.Sprintf(\"Could not read the Customer Master Key: %v\", err))\n}\nif len(key) != 96 {\n\tpanic(fmt.Sprintf(\"Expected the customer master key file to be 96 bytes.\"))\n}\nkmsProviderCredentials := map[string]map[string]interface{}{\"local\": {\"key\": key}}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">key<!-- -->, <!-- -->err := os.<span class="lg-highlight-title lg-highlight-class">ReadFile</span>(<span class="lg-highlight-string">"customer-master-key.txt"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(fmt.<span class="lg-highlight-title lg-highlight-class">Sprintf</span>(<span class="lg-highlight-string">"Could not read the Customer Master Key: %v"</span>, err))</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> <span class="lg-highlight-title lg-highlight-function">len</span>(key) != <span class="lg-highlight-number">96</span> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(fmt.<span class="lg-highlight-title lg-highlight-class">Sprintf</span>(<span class="lg-highlight-string">"Expected the customer master key file to be 96 bytes."</span>))</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">kmsProviderCredentials <!-- -->:<!-- -->= map[string]map[string]interface{}{<span class="lg-highlight-string">"local"</span>: {<span class="lg-highlight-string">"key"</span>: key}}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-74-menu" aria-describedby="select-74-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-75" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9q:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9q:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9q:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9q:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_i8mllc828" class="leafygreen-ui-38lglc" id="_yqp9s6tc9" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"byte[] localCustomerMasterKey = new byte[96];\n\ntry (FileInputStream fis = new FileInputStream(\"customer-master-key.txt\")) {\n if (fis.read(localCustomerMasterKey) != 96)\n throw new Exception(\"Expected the customer master key file to be 96 bytes.\");\n} catch (Exception e) {\n throw new Exception(\"Unable to read the Customer Master Key due to the following error: \" + e.getMessage());\n}\nMap&lt;string,&gt; keyMap = new HashMap&lt;string,&gt;();\nkeyMap.put(\"key\", localCustomerMasterKey);\n\nMap&lt;string,&gt;&gt; kmsProviderCredentials = new HashMap&lt;string,&gt;&gt;();\nkmsProviderCredentials.put(\"local\", keyMap);","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">byte[] localCustomerMasterKey = <span class="lg-highlight-keyword">new</span> byte[<span class="lg-highlight-number">96</span>];</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-keyword">try</span> (<span class="lg-highlight-title lg-highlight-class">FileInputStream</span> fis = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">FileInputStream</span>(<span class="lg-highlight-string">"customer-master-key.txt"</span>)) {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">if</span> (fis.<span class="lg-highlight-title lg-highlight-function">read</span>(localCustomerMasterKey) != <span class="lg-highlight-number">96</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">throw</span> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Exception</span>(<span class="lg-highlight-string">"Expected the customer master key file to be 96 bytes."</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} <span class="lg-highlight-keyword">catch</span> (<span class="lg-highlight-title lg-highlight-class">Exception</span> e) {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">throw</span> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Exception</span>(<span class="lg-highlight-string">"Unable to read the Customer Master Key due to the following error: "</span> + e.<span class="lg-highlight-title lg-highlight-function">getMessage</span>());</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt; keyMap = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt;();</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">keyMap.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"key"</span>, localCustomerMasterKey);</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt;&gt; kmsProviderCredentials = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt;&gt;();</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">kmsProviderCredentials.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"local"</span>, keyMap);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-77-menu" aria-describedby="select-77-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-78" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9r:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9r:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9r:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9r:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_wlouhkzbo" class="" id="_ogqnojysb" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// WARNING: Do not use a local key file in a production application\nconst localMasterKey = readFileSync(\"./customer-master-key.txt\");\n\nif (localMasterKey.length !== 96) {\n throw new Error(\n \"Expected the customer master key file to be 96 bytes.\"\n );\n}\n\nkmsProviders = {\n local: {\n key: localMasterKey,\n },\n};","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-comment">// WARNING: Do</span><span class="lg-highlight-comment"> not use a </span><span class="lg-highlight-comment">local</span><span class="lg-highlight-comment"> key file in </span><span class="lg-highlight-comment">a production application</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> localMasterKey <!-- -->= <span class="lg-highlight-title lg-highlight-function">readFileSync</span>(<span class="lg-highlight-string">"./customer-master-key.txt"</span>)<!-- -->;</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-keyword">if</span> <!-- -->(<!-- -->localMasterKey.<span class="lg-highlight-property">length</span> <!-- -->!<!-- -->== <span class="lg-highlight-number">96</span>) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">throw</span> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Error</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Expected the customer master key file to be 96 bytes."</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> )<!-- -->;</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="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">kmsProviders <!-- -->= <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">local</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->localMasterKey<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-80-menu" aria-describedby="select-80-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-81" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9s:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9s:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9s:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9s:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_ytuihy4yn" class="leafygreen-ui-38lglc" id="_j2dkvbjh2" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"path = \"./customer-master-key.txt\"\nwith open(path, \"rb\") as f:\n local_master_key = f.read()\n if len(local_master_key) != 96:\n raise Exception(\"Expected the customer master key file to be 96 bytes.\")\n kms_provider_credentials = {\n \"local\": {\n \"key\": local_master_key\n },\n }","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">path = <span class="lg-highlight-string">"./customer-master-key.txt"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">with</span> <span class="lg-highlight-title lg-highlight-function">open</span>(path, <span class="lg-highlight-string">"rb"</span>) <span class="lg-highlight-keyword">as</span> <span class="lg-highlight-attr">f</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> local_master_key = f.<span class="lg-highlight-title lg-highlight-function">read</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">if</span> <span class="lg-highlight-title lg-highlight-function">len</span>(local_master_key) != <span class="lg-highlight-number">96</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> raise <span class="lg-highlight-title lg-highlight-class">Exception</span>(<span class="lg-highlight-string">"Expected the customer master key file to be 96 bytes."</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> kms_provider_credentials = {</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"local"</span>: {</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"key"</span>: local_master_key</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> },</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> }</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-83-menu" aria-describedby="select-83-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-84" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9t:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9t:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9t:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9t:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Set Your Automatic Encryption Options </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-quick-start-shared-lib"> </span> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-15"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_mzyfqjiwn" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_rygkr8ovv" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_k8w2jxfiz" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_k9oydkh30" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_8pcquoiii" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_9p64t12gs" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_d7tzbq5w9" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_9m6pxze5u" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_np9wev9j2" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_ol3mb9cy7" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_xy2cqb6of" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_dbi61nwhw" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_xu4j6sw8b" class="leafygreen-ui-38lglc" id="_8i4z90o5d" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create an <code class="leafygreen-ui-1l06pbn"> autoEncryptionOptions </code> object that contains the following options: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The namespace of your Key Vault collection </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> kmsProviderCredentials </code> object, defined in the previous step </p> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const autoEncryptionOptions = {\n keyVaultNamespace: keyVaultNamespace,\n kmsProviders: kmsProviderCredentials,\n};","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> autoEncryptionOptions <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultNamespace</span>: <!-- -->keyVaultNamespace<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmsProviders</span>: <!-- -->kmsProviderCredentials<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-86-menu" aria-describedby="select-86-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-87" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9u:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9u:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9u:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9u:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_eequ0p1ew" class="leafygreen-ui-38lglc" id="_2khwozihw" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create an <code class="leafygreen-ui-1l06pbn"> AutoEncryptionOptions </code> object that contains the following options: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The namespace of your Key Vault collection </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> kmsProviderCredentials </code> object, defined in the previous step </p> </li> <li class="leafygreen-ui-d7p7b6"> <dl> <dt> The <code class="leafygreen-ui-1l06pbn"> extraOptions </code> object, which contains the path to </dt> <dd class="css-1ufxuu7"> your Automatic Encryption Shared Library </dd> </dl> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var extraOptions = new Dictionary&lt;string,&gt;\n{\n { \"cryptSharedLibPath\", _appSettings[\"CryptSharedLibPath\"] } // Path to your Automatic Encryption Shared Library\n};\n\nvar autoEncryptionOptions = new AutoEncryptionOptions(\n keyVaultNamespace,\n kmsProviderCredentials,\n extraOptions: extraOptions);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> extraOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span>&lt;string, object&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"cryptSharedLibPath"</span>, _appSettings[<span class="lg-highlight-string">"CryptSharedLibPath"</span>] } <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Path to your </span><span class="lg-highlight-comment">Automatic Encryption Shared Library</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="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> autoEncryptionOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">AutoEncryptionOptions</span>(</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> keyVaultNamespace,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> kmsProviderCredentials,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extraOptions</span>: extraOptions);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-89-menu" aria-describedby="select-89-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-90" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9v:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":r9v:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9v:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":r9v:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_k0dw0zuzi" class="leafygreen-ui-38lglc" id="_e7dkjwpuz" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create an <code class="leafygreen-ui-1l06pbn"> AutoEncryption </code> object that contains the following options: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The namespace of your Key Vault collection </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> kmsProviderCredentials </code> object, defined in the previous step </p> </li> <li class="leafygreen-ui-d7p7b6"> <dl> <dt> The <code class="leafygreen-ui-1l06pbn"> cryptSharedLibraryPath </code> object, which contains the path to </dt> <dd class="css-1ufxuu7"> your Automatic Encryption Shared Library </dd> </dl> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"cryptSharedLibraryPath := map[string]interface{}{\n\t\"cryptSharedLibPath\": os.Getenv(\"SHARED_LIB_PATH\"), // Path to your Automatic Encryption Shared Library\n}\n\nautoEncryptionOptions := options.AutoEncryption().\n\tSetKeyVaultNamespace(keyVaultNamespace).\n\tSetKmsProviders(kmsProviderCredentials).\n\tSetExtraOptions(cryptSharedLibraryPath)","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">cryptSharedLibraryPath <!-- -->:<!-- -->= map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"cryptSharedLibPath"</span>: os.<span class="lg-highlight-title lg-highlight-class">Getenv</span>(<span class="lg-highlight-string">"SHARED_LIB_PATH"</span>), <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Path to your </span><span class="lg-highlight-comment">Automatic Encryption Shared Library</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="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">autoEncryptionOptions <!-- -->:<!-- -->= options.<span class="lg-highlight-title lg-highlight-class">AutoEncryption</span>().</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKeyVaultNamespace</span>(keyVaultNamespace).</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKmsProviders</span>(kmsProviderCredentials).</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetExtraOptions</span>(cryptSharedLibraryPath)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-92-menu" aria-describedby="select-92-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-93" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra0:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ra0:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra0:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra0:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_839z4qvdx" class="leafygreen-ui-38lglc" id="_uoeqok28h" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create an <code class="leafygreen-ui-1l06pbn"> AutoEncryptionSettings </code> object that contains the following options: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The namespace of your Key Vault collection </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> kmsProviderCredentials </code> object, defined in the previous step </p> </li> <li class="leafygreen-ui-d7p7b6"> <dl> <dt> The <code class="leafygreen-ui-1l06pbn"> extraOptions </code> object, which contains the path to </dt> <dd class="css-1ufxuu7"> your Automatic Encryption Shared Library </dd> </dl> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Map&lt;string,&gt; extraOptions = new HashMap&lt;string,&gt;();\nextraOptions.put(\"cryptSharedLibPath\", getEnv(\"SHARED_LIB_PATH\")); // Path to your Automatic Encryption Shared Library\n\nAutoEncryptionSettings autoEncryptionSettings = AutoEncryptionSettings.builder()\n .keyVaultNamespace(keyVaultNamespace)\n .kmsProviders(kmsProviderCredentials)\n .extraOptions(extraOptions)\n .build();","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">Map</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt; extraOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span>&lt;<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>&gt;();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">extraOptions.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"cryptSharedLibPath"</span>, <span class="lg-highlight-title lg-highlight-function">getEnv</span>(<span class="lg-highlight-string">"SHARED_LIB_PATH"</span>)); <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Path to your </span><span class="lg-highlight-comment">Automatic Encryption Shared Library</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">AutoEncryptionSettings</span> autoEncryptionSettings = <span class="lg-highlight-title lg-highlight-class">AutoEncryptionSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">keyVaultNamespace</span>(keyVaultNamespace)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">kmsProviders</span>(kmsProviderCredentials)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">extraOptions</span>(extraOptions)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>();</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-95-menu" aria-describedby="select-95-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-96" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra1:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ra1:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra1:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra1:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_fegxnlqoy" class="" id="_0bn7rpfz2" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create an <code class="leafygreen-ui-1l06pbn"> autoEncryptionOptions </code> object that contains the following options: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The namespace of your Key Vault collection </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> kmsProviders </code> object, defined in the previous step </p> </li> <li class="leafygreen-ui-d7p7b6"> <dl> <dt> The <code class="leafygreen-ui-1l06pbn"> sharedLibraryPathOptions </code> object, which contains the path to </dt> <dd class="css-1ufxuu7"> your Automatic Encryption Shared Library </dd> </dl> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const extraOptions = {\n cryptSharedLibPath: process.env.SHARED_LIB_PATH, // Path to your Automatic Encryption Shared Library\n};\n\nconst autoEncryptionOptions = {\n keyVaultNamespace,\n kmsProviders,\n extraOptions,\n};","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> extraOptions <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cryptSharedLibPath</span>: <!-- -->process.<span class="lg-highlight-property">env</span>.<span class="lg-highlight-property">SHARED_LIB_PATH</span>, <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Path to your </span><span class="lg-highlight-comment">Automatic Encryption Shared Library</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="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> autoEncryptionOptions <!-- -->= <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->keyVaultNamespace<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->kmsProviders<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->extraOptions<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-98-menu" aria-describedby="select-98-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-99" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra2:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ra2:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra2:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra2:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_qj98ph6it" class="leafygreen-ui-38lglc" id="_0vkaiej0j" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create an <code class="leafygreen-ui-1l06pbn"> AutoEncryptionOpts </code> object that contains the following options: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> kms_provider_credentials </code> object, defined in the previous step </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The namespace of your Key Vault collection </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The path to your Automatic Encryption Shared Library </p> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"auto_encryption_options = AutoEncryptionOpts(\n kms_provider_credentials,\n key_vault_namespace,\n crypt_shared_lib_path=os.environ['SHARED_LIB_PATH'] # Path to your Automatic Encryption Shared Library&gt;\n)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">auto_encryption_options = <span class="lg-highlight-title lg-highlight-class">AutoEncryptionOpts</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kms_provider_credentials,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> key_vault_namespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> crypt_shared_lib_path=os.<span class="lg-highlight-property">environ</span>[<span class="lg-highlight-string">'SHARED_LIB_PATH'</span>] # <span class="lg-highlight-title lg-highlight-class">Path</span> to your <span class="lg-highlight-title lg-highlight-class">Automatic</span> <span class="lg-highlight-title lg-highlight-class">Encryption</span> <span class="lg-highlight-title lg-highlight-class">Shared</span> <span class="lg-highlight-title lg-highlight-class">Library</span>&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-101-menu" aria-describedby="select-101-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-102" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra3:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ra3:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra3:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra3:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Automatic Encryption Options </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The automatic encryption options provide configuration information to the Automatic Encryption Shared Library, which modifies the application's behavior when accessing encrypted fields. </p> <p class="leafygreen-ui-1kp3ins"> To learn more about the Automatic Encryption Shared Library, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/install-library/#std-label-qe-reference-shared-library"> Automatic Encryption Shared Library </a> page. </p> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create a Client to Set Up an Encrypted Collection </p> <p class="leafygreen-ui-1kp3ins"> To create a client used to encrypt and decrypt data in your collection, instantiate a new <code class="leafygreen-ui-1l06pbn"> MongoClient </code> by using your connection URI and your automatic encryption options. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-16"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_0aikvdm79" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_fqk7ucuoc" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_8tupz66j1" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_h64mjup6l" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_4lidycde7" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_h20n7n7nj" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_yl9b0hr4g" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_jgwouea32" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_0xbvhg6mw" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_6kij3czl0" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_p22tn7kds" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_81reobsl8" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_3h6v1n98w" class="leafygreen-ui-38lglc" id="_ryg4im277" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const encryptedClient = Mongo(uri, autoEncryptionOptions);","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-keyword">const</span> encryptedClient <!-- -->= <span class="lg-highlight-title lg-highlight-class">Mongo</span>(<!-- -->uri<!-- -->, <!-- -->autoEncryptionOptions)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-104-menu" aria-describedby="select-104-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-105" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra4:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ra4:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra4:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra4:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_8qnlwreqt" class="leafygreen-ui-38lglc" id="_jor9p968u" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> <strong class="css-rws738"> IMPORTANT: </strong> If you are using the .NET/C# Driver version 3.0 or later, you must add the following code to your application before instantiating a new <code class="leafygreen-ui-1l06pbn"> MongoClient </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoClientSettings.Extensions.AddAutoEncryption(); // .NET/C# Driver v3.0 or later only","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-property">Extensions</span>.<span class="lg-highlight-title lg-highlight-class">AddAutoEncryption</span>(); <span class="lg-highlight-comment">// .NET/C# Driver v3.0 or later only</span></td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-107-menu" aria-describedby="select-107-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-108" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra5:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ra5:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra5:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra5:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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"> Instantiate a new <code class="leafygreen-ui-1l06pbn"> MongoClient </code> by using your connection URI and automatic encryption options: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var clientSettings = MongoClientSettings.FromConnectionString(uri);\nclientSettings.AutoEncryptionOptions = qeHelpers.GetAutoEncryptionOptions(\n keyVaultNamespace,\n kmsProviderCredentials);\n\nvar encryptedClient = new MongoClient(clientSettings);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> clientSettings = <span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-class">FromConnectionString</span>(uri);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">clientSettings.<span class="lg-highlight-property">AutoEncryptionOptions</span> = qeHelpers.<span class="lg-highlight-title lg-highlight-class">GetAutoEncryptionOptions</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> keyVaultNamespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kmsProviderCredentials);</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-keyword">var</span> encryptedClient = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(clientSettings);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-110-menu" aria-describedby="select-110-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-111" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra6:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ra6:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra6:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra6:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_4wmhs4897" class="leafygreen-ui-38lglc" id="_zl1walvq9" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"encryptedClient, err := mongo.Connect(\n\tcontext.TODO(),\n\toptions.Client().ApplyURI(uri).SetAutoEncryptionOptions(autoEncryptionOptions),\n)\nif err != nil {\n\tpanic(fmt.Sprintf(\"Unable to connect to MongoDB: %v\\n\", err))\n}\ndefer func() {\n\t_ = encryptedClient.Disconnect(context.TODO())\n}()","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">encryptedClient<!-- -->, <!-- -->err := mongo.<span class="lg-highlight-title lg-highlight-class">Connect</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> options.<span class="lg-highlight-title lg-highlight-class">Client</span>().<span class="lg-highlight-title lg-highlight-class">ApplyURI</span>(uri).<span class="lg-highlight-title lg-highlight-class">SetAutoEncryptionOptions</span>(autoEncryptionOptions),</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(fmt.<span class="lg-highlight-title lg-highlight-class">Sprintf</span>(<span class="lg-highlight-string">"Unable to connect to MongoDB: %v</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>, err))</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">defer <span class="lg-highlight-title lg-highlight-function">func</span>() {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _ = encryptedClient.<span class="lg-highlight-title lg-highlight-class">Disconnect</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}()</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-113-menu" aria-describedby="select-113-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-114" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra7:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ra7:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra7:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra7:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_cbtwthlf9" class="leafygreen-ui-38lglc" id="_xulzdnbzn" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoClientSettings clientSettings = MongoClientSettings.builder()\n .applyConnectionString(new ConnectionString(uri))\n .autoEncryptionSettings(autoEncryptionSettings)\n .build();\n\ntry (MongoClient encryptedClient = MongoClients.create(clientSettings)) {","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span> clientSettings = <span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">applyConnectionString</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ConnectionString</span>(uri))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">autoEncryptionSettings</span>(autoEncryptionSettings)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>();</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-keyword">try</span> (<span class="lg-highlight-title lg-highlight-class">MongoClient</span> encryptedClient = <span class="lg-highlight-title lg-highlight-class">MongoClients</span>.<span class="lg-highlight-title lg-highlight-function">create</span>(clientSettings)) {</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-116-menu" aria-describedby="select-116-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-117" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra8:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ra8:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra8:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra8:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_k85pkdffw" class="" id="_0u1wxp7a4" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const encryptedClient = new MongoClient(uri, {\n autoEncryption: autoEncryptionOptions,\n});","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> encryptedClient <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(<!-- -->uri<!-- -->, <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">autoEncryption</span>: <!-- -->autoEncryptionOptions<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">})<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-119-menu" aria-describedby="select-119-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-120" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra9:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ra9:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra9:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ra9:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_y21gdczw2" class="leafygreen-ui-38lglc" id="_43ng09v5w" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"encrypted_client = MongoClient(\n uri, auto_encryption_opts=auto_encryption_options)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">encrypted_client = <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> uri, auto_encryption_opts=auto_encryption_options)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-122-menu" aria-describedby="select-122-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-123" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:raa:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":raa:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":raa:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":raa:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specify Fields to Encrypt </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-quickstart-encrypted-fields-map"> </span> <p class="leafygreen-ui-1kp3ins"> To encrypt a field, add it to the encryption schema. To enable queries on a field, add the "queries" property. Create the encryption schema as follows: </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-17"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_w4963wh56" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_kt5ndf26o" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_ho30zhsnm" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_t1mtvsxh1" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_hh3p5n0ug" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_rmq34xbvh" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_v7ktc65dw" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_skt1l5e5e" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_roxmixo5q" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_mevfcauw8" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_w4ahky669" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_cdkf3vu14" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_usf4hu0wx" class="leafygreen-ui-38lglc" id="_9jn9mcy0y" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const encryptedFieldsMap = {\n encryptedFields: {\n fields: [\n {\n path: \"patientRecord.ssn\",\n bsonType: \"string\",\n queries: { queryType: \"equality\" },\n },\n {\n path: \"patientRecord.billing\",\n bsonType: \"object\",\n },\n ],\n },\n};","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> encryptedFieldsMap <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encryptedFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">fields</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-string">"patientRecord.ssn"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"string"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">queries</span>: <!-- -->{ <span class="lg-highlight-attr">queryType</span>: <span class="lg-highlight-string">"equality"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-string">"patientRecord.billing"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-125-menu" aria-describedby="select-125-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-126" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rab:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rab:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rab:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rab:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_kj5q1n2yg" class="leafygreen-ui-38lglc" id="_eo44umq7b" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var encryptedFields = new BsonDocument\n{\n {\n \"fields\", new BsonArray\n {\n new BsonDocument\n {\n { \"keyId\", BsonNull.Value },\n { \"path\", \"patientRecord.ssn\" },\n { \"bsonType\", \"string\" },\n { \"queries\", new BsonDocument(\"queryType\", \"equality\") }\n },\n new BsonDocument\n {\n { \"keyId\", BsonNull.Value },\n { \"path\", \"patientRecord.billing\" },\n { \"bsonType\", \"object\" }\n }\n }\n }\n};","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> encryptedFields = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"fields"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonArray</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"keyId"</span>, <span class="lg-highlight-title lg-highlight-class">BsonNull</span>.<span class="lg-highlight-property">Value</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"path"</span>, <span class="lg-highlight-string">"patientRecord.ssn"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"string"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"queries"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"queryType"</span>, <span class="lg-highlight-string">"equality"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"keyId"</span>, <span class="lg-highlight-title lg-highlight-class">BsonNull</span>.<span class="lg-highlight-property">Value</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"path"</span>, <span class="lg-highlight-string">"patientRecord.billing"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"object"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">};</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-128-menu" aria-describedby="select-128-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-129" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rac:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rac:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rac:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rac:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_8fbanhct9" class="leafygreen-ui-38lglc" id="_y0g7s8w34" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"encryptedFieldsMap := bson.M{\n\t\"fields\": []bson.M{\n\t\tbson.M{\n\t\t\t\"keyId\": nil,\n\t\t\t\"path\": \"patientRecord.ssn\",\n\t\t\t\"bsonType\": \"string\",\n\t\t\t\"queries\": []bson.M{\n\t\t\t\t{\n\t\t\t\t\t\"queryType\": \"equality\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tbson.M{\n\t\t\t\"keyId\": nil,\n\t\t\t\"path\": \"patientRecord.billing\",\n\t\t\t\"bsonType\": \"object\",\n\t\t},\n\t},\n}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">encryptedFieldsMap <!-- -->:<!-- -->= bson.<span class="lg-highlight-property">M</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"fields"</span>: []bson.<span class="lg-highlight-property">M</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> bson.<span class="lg-highlight-property">M</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"keyId"</span>: nil,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"path"</span>: <span class="lg-highlight-string">"patientRecord.ssn"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"string"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"queries"</span>: []bson.<span class="lg-highlight-property">M</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"queryType"</span>: <span class="lg-highlight-string">"equality"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> bson.<span class="lg-highlight-property">M</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"keyId"</span>: nil,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"path"</span>: <span class="lg-highlight-string">"patientRecord.billing"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-131-menu" aria-describedby="select-131-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-132" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rad:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rad:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rad:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rad:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_ap2xgpemo" class="leafygreen-ui-38lglc" id="_j8zmz5tcg" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"BsonDocument encryptedFieldsMap = new BsonDocument().append(\"fields\",\n new BsonArray(Arrays.asList(\n new BsonDocument()\n .append(\"keyId\", new BsonNull())\n .append(\"path\", new BsonString(\"patientRecord.ssn\"))\n .append(\"bsonType\", new BsonString(\"string\"))\n .append(\"queries\", new BsonDocument()\n .append(\"queryType\", new BsonString(\"equality\"))),\n new BsonDocument()\n .append(\"keyId\", new BsonNull())\n .append(\"path\", new BsonString(\"patientRecord.billing\"))\n .append(\"bsonType\", new BsonString(\"object\")))));","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">BsonDocument</span> encryptedFieldsMap = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"fields"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonArray</span>(<span class="lg-highlight-title lg-highlight-class">Arrays</span>.<span class="lg-highlight-title lg-highlight-function">asList</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"keyId"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonNull</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"path"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonString</span>(<span class="lg-highlight-string">"patientRecord.ssn"</span>))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonString</span>(<span class="lg-highlight-string">"string"</span>))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"queries"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"queryType"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonString</span>(<span class="lg-highlight-string">"equality"</span>))),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"keyId"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonNull</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"path"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonString</span>(<span class="lg-highlight-string">"patientRecord.billing"</span>))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonString</span>(<span class="lg-highlight-string">"object"</span>)))));</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-134-menu" aria-describedby="select-134-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-135" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rae:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rae:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rae:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rae:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_lqhhkf1ba" class="" id="_ayo2xua95" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const encryptedFieldsMap = {\n encryptedFields: {\n fields: [\n {\n path: \"patientRecord.ssn\",\n bsonType: \"string\",\n queries: { queryType: \"equality\" },\n },\n {\n path: \"patientRecord.billing\",\n bsonType: \"object\",\n },\n ],\n },\n};","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> encryptedFieldsMap <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encryptedFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">fields</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-string">"patientRecord.ssn"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"string"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">queries</span>: <!-- -->{ <span class="lg-highlight-attr">queryType</span>: <span class="lg-highlight-string">"equality"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-string">"patientRecord.billing"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-137-menu" aria-describedby="select-137-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-138" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:raf:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":raf:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":raf:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":raf:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_m37h1bdpy" class="leafygreen-ui-38lglc" id="_wlm9xt0ub" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"encrypted_fields_map = {\n \"fields\": [\n {\n \"path\": \"patientRecord.ssn\",\n \"bsonType\": \"string\",\n \"queries\": [{\"queryType\": \"equality\"}]\n },\n {\n \"path\": \"patientRecord.billing\",\n \"bsonType\": \"object\",\n }\n ]\n}","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">encrypted_fields_map = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"fields"</span>: [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"path"</span>: <span class="lg-highlight-string">"patientRecord.ssn"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"string"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"queries"</span>: [{<span class="lg-highlight-string">"queryType"</span>: <span class="lg-highlight-string">"equality"</span>}]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"path"</span>: <span class="lg-highlight-string">"patientRecord.billing"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-140-menu" aria-describedby="select-140-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-141" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rag:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rag:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rag:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rag:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> In the previous code sample, both the "ssn" and "billing" fields are encrypted, but only the "ssn" field can be queried. </p> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create the Collection </p> <p class="leafygreen-ui-1kp3ins"> Instantiate <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> to access the API for the encryption helper methods. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-18"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_nbrrzwhh4" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_2enu80un7" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_xtoxr8e7k" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_pvsgaaksy" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_u7wsbzbfq" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_1p7w7qj9z" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_sgwf3zgw8" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_8v4odrwem" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_sy0yx9bta" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_h58eaacig" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_8z8bpxpny" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_wi9cq80xe" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_0se7rokoa" class="leafygreen-ui-38lglc" id="_32xenl9ot" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const clientEncryption = encryptedClient.getClientEncryption();","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-keyword">const</span> clientEncryption <!-- -->= <!-- -->encryptedClient.<span class="lg-highlight-title lg-highlight-function">getClientEncryption</span>(<!-- -->)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-143-menu" aria-describedby="select-143-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-144" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rah:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rah:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rah:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rah:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_yhtqrj35r" class="leafygreen-ui-38lglc" id="_7imsqxx1j" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var clientEncryptionOptions = new ClientEncryptionOptions(\n keyVaultClient: keyVaultClient,\n keyVaultNamespace: keyVaultNamespace,\n kmsProviders: kmsProviderCredentials\n);\nvar clientEncryption = new ClientEncryption(clientEncryptionOptions);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> clientEncryptionOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ClientEncryptionOptions</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultClient</span>: keyVaultClient,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultNamespace</span>: keyVaultNamespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmsProviders</span>: kmsProviderCredentials</td></tr><tr class=""><td class="leafygreen-ui-7razhx">);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> clientEncryption = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>(clientEncryptionOptions);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-146-menu" aria-describedby="select-146-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-147" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rai:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rai:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rai:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rai:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_avsv20ho7" class="leafygreen-ui-38lglc" id="_5nifopbk6" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"opts := options.ClientEncryption().\n\tSetKeyVaultNamespace(keyVaultNamespace).\n\tSetKmsProviders(kmsProviderCredentials)\n\nclientEncryption, err := mongo.NewClientEncryption(encryptedClient, opts)\nif err != nil {\n\tpanic(fmt.Sprintf(\"Unable to create a ClientEncryption instance due to the following error: %s\\n\", err))\n}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">opts <!-- -->:<!-- -->= options.<span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>().</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKeyVaultNamespace</span>(keyVaultNamespace).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKmsProviders</span>(kmsProviderCredentials)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">clientEncryption<!-- -->, <!-- -->err := mongo.<span class="lg-highlight-title lg-highlight-class">NewClientEncryption</span>(encryptedClient, opts)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(fmt.<span class="lg-highlight-title lg-highlight-class">Sprintf</span>(<span class="lg-highlight-string">"Unable to create a ClientEncryption instance due to the following error: %s</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>, err))</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-149-menu" aria-describedby="select-149-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-150" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:raj:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":raj:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":raj:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":raj:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_lcsr0fv1o" class="leafygreen-ui-38lglc" id="_ql8wylvk1" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder()\n .keyVaultMongoClientSettings(MongoClientSettings.builder()\n .applyConnectionString(new ConnectionString(uri))\n .build())\n .keyVaultNamespace(keyVaultNamespace)\n .kmsProviders(kmsProviderCredentials)\n .build();\nClientEncryption clientEncryption = ClientEncryptions.create(clientEncryptionSettings);","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">ClientEncryptionSettings</span> clientEncryptionSettings = <span class="lg-highlight-title lg-highlight-class">ClientEncryptionSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">keyVaultMongoClientSettings</span>(<span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">applyConnectionString</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ConnectionString</span>(uri))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">keyVaultNamespace</span>(keyVaultNamespace)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">kmsProviders</span>(kmsProviderCredentials)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">ClientEncryption</span> clientEncryption = <span class="lg-highlight-title lg-highlight-class">ClientEncryptions</span>.<span class="lg-highlight-title lg-highlight-function">create</span>(clientEncryptionSettings);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-152-menu" aria-describedby="select-152-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-153" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rak:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rak:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rak:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rak:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_k7v9eut7f" class="" id="_noaj2gd1t" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const clientEncryption = new ClientEncryption(\n encryptedClient,\n autoEncryptionOptions\n);","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> clientEncryption <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->encryptedClient<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->autoEncryptionOptions</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-155-menu" aria-describedby="select-155-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-156" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ral:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ral:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ral:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ral:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_b5pov496v" class="leafygreen-ui-38lglc" id="_q89uepms0" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"client_encryption = ClientEncryption(\n kms_providers=kms_provider_credentials,\n key_vault_namespace=key_vault_namespace,\n key_vault_client=encrypted_client,\n codec_options=CodecOptions(uuid_representation=STANDARD)\n)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">client_encryption = <span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kms_providers=kms_provider_credentials,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> key_vault_namespace=key_vault_namespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> key_vault_client=encrypted_client,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> codec_options=<span class="lg-highlight-title lg-highlight-class">CodecOptions</span>(uuid_representation=<span class="lg-highlight-variable lg-highlight-constant">STANDARD</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-158-menu" aria-describedby="select-158-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-159" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ram:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ram:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ram:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ram:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <p class="leafygreen-ui-1kp3ins"> Because you are using a local Customer Master Key, you don't need to provide Customer Master Key credentials. Create a variable containing an empty object to use in place of credentials when you create your encrypted collection. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-19"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_v7npvkf00" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_s060u0t5z" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_jr5f7h4om" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_7x480o84g" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_tyezuswxd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_023cnpvck" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_bfopdobb3" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_6ykdgspy1" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_sv88izf4m" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_e9lu7wa5i" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_8kcw27qca" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_pw1zzvh8p" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_lpei2vz7q" class="leafygreen-ui-38lglc" id="_bforhh38r" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"customerMasterKeyCredentials = {};","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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">customerMasterKeyCredentials <!-- -->= <!-- -->{<!-- -->}<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-161-menu" aria-describedby="select-161-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-162" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ran:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ran:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ran:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ran:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_sh4cja7gi" class="leafygreen-ui-38lglc" id="_e0s8rlcun" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var customerMasterKeyCredentials = new BsonDocument();","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-keyword">var</span> customerMasterKeyCredentials = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>();</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-164-menu" aria-describedby="select-164-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-165" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rao:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rao:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rao:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rao:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_irdm6panx" class="leafygreen-ui-38lglc" id="_sniqspu12" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"cmkCredentials := map[string]string{}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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">cmkCredentials <!-- -->:<!-- -->= map[string]string{}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-167-menu" aria-describedby="select-167-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-168" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rap:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rap:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rap:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rap:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_31suyyh42" class="leafygreen-ui-38lglc" id="_l7erchsf8" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"BsonDocument customerMasterKeyCredentials = new BsonDocument();","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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"><span class="lg-highlight-title lg-highlight-class">BsonDocument</span> customerMasterKeyCredentials = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>();</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-170-menu" aria-describedby="select-170-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-171" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:raq:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":raq:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":raq:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":raq:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_0mvcjon92" class="" id="_vp4okhych" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"customerMasterKeyCredentials = {};","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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">customerMasterKeyCredentials <!-- -->= <!-- -->{<!-- -->}<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-173-menu" aria-describedby="select-173-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-174" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rar:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rar:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rar:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rar:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_6pmb14cpr" class="leafygreen-ui-38lglc" id="_9h58pbo8c" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"customer_master_key_credentials = {}","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <pre class="leafygreen-ui-1q4bxgx" 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">customer_master_key_credentials = {}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-176-menu" aria-describedby="select-176-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-177" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ras:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":ras:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ras:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":ras:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-20"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_uwgy9rzgb" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_08yb7qlu4" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_nb2eup3q0" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_zx6y1mi6w" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_7zx344u6o" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_pnerfjby5" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_jeayci1bu" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_qvtfa0vkb" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_ibb667jql" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_g1xb9l4ov" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_mhjw27zar" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_tgtg90bbf" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_ghxh9nmtm" class="leafygreen-ui-38lglc" id="_o37xg3w3n" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create your encrypted collection by using the encryption helper method accessed through the <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> class. This method automatically generates data encryption keys for your encrypted fields and creates the encrypted collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"await clientEncryption.createEncryptedCollection(\n encryptedDatabaseName,\n encryptedCollectionName,\n {\n provider: kmsProviderName,\n createCollectionOptions: encryptedFieldsMap,\n masterKey: customerMasterKeyCredentials,\n }\n);","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">await</span> clientEncryption.<span class="lg-highlight-title lg-highlight-function">createEncryptedCollection</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->encryptedDatabaseName<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->encryptedCollectionName<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">provider</span>: <!-- -->kmsProviderName<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">createCollectionOptions</span>: <!-- -->encryptedFieldsMap<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">masterKey</span>: <!-- -->customerMasterKeyCredentials<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-179-menu" aria-describedby="select-179-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-180" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rat:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rat:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rat:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rat:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_e8oy945j9" class="leafygreen-ui-38lglc" id="_im87ouu6h" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> The C# version of this tutorial uses separate classes as data models to represent the document structure. Add the following <code class="leafygreen-ui-1l06pbn"> Patient </code> , <code class="leafygreen-ui-1l06pbn"> PatientRecord </code> , and <code class="leafygreen-ui-1l06pbn"> PatientBilling </code> classes to your project: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"using MongoDB.Bson;\nusing MongoDB.Bson.Serialization.Attributes;\n\n[BsonIgnoreExtraElements]\npublic class Patient\n{\n public ObjectId Id { get; set; }\n public string PatientName { get; set; }\n public PatientRecord PatientRecord { get; set; }\n}","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">using <span class="lg-highlight-title lg-highlight-class">MongoDB</span>.<span class="lg-highlight-property">Bson</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">using <span class="lg-highlight-title lg-highlight-class">MongoDB</span>.<span class="lg-highlight-property">Bson</span>.<span class="lg-highlight-property">Serialization</span>.<span class="lg-highlight-property">Attributes</span>;</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">BsonIgnoreExtraElements</span>]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">public <span class="lg-highlight-keyword lg-highlight-class">class</span> <span class="lg-highlight-title lg-highlight-class">Patient</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> public <span class="lg-highlight-title lg-highlight-class">ObjectId</span> <span class="lg-highlight-title lg-highlight-class">Id</span> { get; set; }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> public string <span class="lg-highlight-title lg-highlight-class">PatientName</span> { get; set; }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> public <span class="lg-highlight-title lg-highlight-class">PatientRecord</span> <span class="lg-highlight-title lg-highlight-class">PatientRecord</span> { get; set; }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-182-menu" aria-describedby="select-182-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-183" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rau:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rau:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rau:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rau:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"public class PatientRecord\n{\n public string Ssn { get; set; }\n public PatientBilling Billing { get; set; }\n public int BillAmount { get; set; }\n}","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">public <span class="lg-highlight-keyword lg-highlight-class">class</span> <span class="lg-highlight-title lg-highlight-class">PatientRecord</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> public string <span class="lg-highlight-title lg-highlight-class">Ssn</span> { get; set; }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> public <span class="lg-highlight-title lg-highlight-class">PatientBilling</span> <span class="lg-highlight-title lg-highlight-class">Billing</span> { get; set; }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> public int <span class="lg-highlight-title lg-highlight-class">BillAmount</span> { get; set; }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-185-menu" aria-describedby="select-185-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-186" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rav:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rav:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rav:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rav:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"public class PatientBilling\n{\n public string CardType { get; set; }\n public long CardNumber { get; set; }\n}","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">public <span class="lg-highlight-keyword lg-highlight-class">class</span> <span class="lg-highlight-title lg-highlight-class">PatientBilling</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> public string <span class="lg-highlight-title lg-highlight-class">CardType</span> { get; set; }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> public long <span class="lg-highlight-title lg-highlight-class">CardNumber</span> { get; set; }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-188-menu" aria-describedby="select-188-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-189" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rb0:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rb0:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb0:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb0:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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"> After you've added these classes, create your encrypted collection by using the encryption helper method accessed through the <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> class. This method automatically generates data encryption keys for your encrypted fields and creates the encrypted collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var createCollectionOptions = new CreateCollectionOptions&lt;patient&gt;\n{\n EncryptedFields = encryptedFields\n};\n\nclientEncryption.CreateEncryptedCollection(patientDatabase,\n encryptedCollectionName,\n createCollectionOptions,\n kmsProviderName,\n customerMasterKeyCredentials);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> createCollectionOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">CreateCollectionOptions</span>&lt;<span class="lg-highlight-title lg-highlight-class">Patient</span>&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">EncryptedFields</span> = encryptedFields</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">clientEncryption.<span class="lg-highlight-title lg-highlight-class">CreateEncryptedCollection</span>(patientDatabase,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> encryptedCollectionName,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> createCollectionOptions,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kmsProviderName,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> customerMasterKeyCredentials);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-191-menu" aria-describedby="select-191-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-192" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rb1:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rb1:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb1:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb1:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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"> The method that creates the encrypted collection requires a reference to a database <em> object </em> rather than the database <em> name </em> . You can obtain this reference by using a method on your client object. </p> </div> </div> </div> <div> <div aria-labelledby="_ppv83hrzf" class="leafygreen-ui-38lglc" id="_ixnkbqw1c" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> The Golang version of this tutorial uses data models to represent the document structure. Add the following structs to your project to represent the data in your collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"type PatientDocument struct {\n\tPatientName string `bson:\"patientName\"`\n\tPatientID int32 `bson:\"patientId\"`\n\tPatientRecord PatientRecord `bson:\"patientRecord\"`\n}\n","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">type <span class="lg-highlight-title lg-highlight-class">PatientDocument</span> struct {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">PatientName</span> string <span class="lg-highlight-string">`bson:"patientName"`</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">PatientID</span> int32 <span class="lg-highlight-string">`bson:"patientId"`</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">PatientRecord</span> <span class="lg-highlight-title lg-highlight-class">PatientRecord</span> <span class="lg-highlight-string">`bson:"patientRecord"`</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-194-menu" aria-describedby="select-194-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-195" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rb2:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rb2:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb2:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb2:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"type PatientRecord struct {\n\tSSN string `bson:\"ssn\"`\n\tBilling PaymentInfo `bson:\"billing\"`\n\tBillAmount int `bson:\"billAmount\"`\n}\n","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">type <span class="lg-highlight-title lg-highlight-class">PatientRecord</span> struct {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable lg-highlight-constant">SSN</span> string <span class="lg-highlight-string">`bson:"ssn"`</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Billing</span> <span class="lg-highlight-title lg-highlight-class">PaymentInfo</span> <span class="lg-highlight-string">`bson:"billing"`</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">BillAmount</span> int <span class="lg-highlight-string">`bson:"billAmount"`</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-197-menu" aria-describedby="select-197-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-198" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rb3:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rb3:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb3:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb3:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"type PaymentInfo struct {\n\tType string `bson:\"type\"`\n\tNumber string `bson:\"number\"`\n}\n","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">type <span class="lg-highlight-title lg-highlight-class">PaymentInfo</span> struct {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Type</span> string <span class="lg-highlight-string">`bson:"type"`</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Number</span> string <span class="lg-highlight-string">`bson:"number"`</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-200-menu" aria-describedby="select-200-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-201" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rb4:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rb4:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb4:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb4:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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"> After you've added these classes, create your encrypted collection by using the encryption helper method accessed through the <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> class. This method automatically generates data encryption keys for your encrypted fields and creates the encrypted collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"createCollectionOptions := options.CreateCollection().SetEncryptedFields(encryptedFieldsMap)\n_, _, err =\n\tclientEncryption.CreateEncryptedCollection(\n\t\tcontext.TODO(),\n\t\tencryptedClient.Database(encryptedDatabaseName),\n\t\tencryptedCollectionName,\n\t\tcreateCollectionOptions,\n\t\tkmsProviderName,\n\t\tcustomerMasterKey,\n\t)","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">createCollectionOptions <!-- -->:<!-- -->= options.<span class="lg-highlight-title lg-highlight-class">CreateCollection</span>().<span class="lg-highlight-title lg-highlight-class">SetEncryptedFields</span>(encryptedFieldsMap)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">_, _, err =</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> clientEncryption.<span class="lg-highlight-title lg-highlight-class">CreateEncryptedCollection</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> encryptedClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(encryptedDatabaseName),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> encryptedCollectionName,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> createCollectionOptions,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kmsProviderName,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> customerMasterKey,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> )</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-203-menu" aria-describedby="select-203-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-204" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rb5:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rb5:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb5:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb5:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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"> The method that creates the encrypted collection requires a reference to a database <em> object </em> rather than the database <em> name </em> . You can obtain this reference by using a method on your client object. </p> </div> </div> </div> <div> <div aria-labelledby="_4pt2lnuix" class="leafygreen-ui-38lglc" id="_nqurp4zwh" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create your encrypted collection by using the encryption helper method accessed through the <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> class. This method automatically generates data encryption keys for your encrypted fields and creates the encrypted collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"CreateCollectionOptions createCollectionOptions = new CreateCollectionOptions().encryptedFields(encryptedFieldsMap);\n\nCreateEncryptedCollectionParams encryptedCollectionParams = new CreateEncryptedCollectionParams(kmsProviderName);\nencryptedCollectionParams.masterKey(customerMasterKeyCredentials);\n\ntry {\n clientEncryption.createEncryptedCollection(\n encryptedClient.getDatabase(encryptedDatabaseName),\n encryptedCollectionName,\n createCollectionOptions,\n encryptedCollectionParams);\n} ","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">CreateCollectionOptions</span> createCollectionOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">CreateCollectionOptions</span>().<span class="lg-highlight-title lg-highlight-function">encryptedFields</span>(encryptedFieldsMap);</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">CreateEncryptedCollectionParams</span> encryptedCollectionParams = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">CreateEncryptedCollectionParams</span>(kmsProviderName);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">encryptedCollectionParams.<span class="lg-highlight-title lg-highlight-function">masterKey</span>(customerMasterKeyCredentials);</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-keyword">try</span> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> clientEncryption.<span class="lg-highlight-title lg-highlight-function">createEncryptedCollection</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> encryptedClient.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(encryptedDatabaseName),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> encryptedCollectionName,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> createCollectionOptions,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> encryptedCollectionParams);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} </td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-206-menu" aria-describedby="select-206-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-207" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rb6:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rb6:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb6:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb6:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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"> The method that creates the encrypted collection requires a reference to a database <em> object </em> rather than the database <em> name </em> . You can obtain this reference by using a method on your client object. </p> </div> </div> </div> <div> <div aria-labelledby="_rjdx05bzy" class="" id="_36tfocwvl" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create your encrypted collection by using the encryption helper method accessed through the <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> class. This method automatically generates data encryption keys for your encrypted fields and creates the encrypted collection: </p> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Import ClientEncryption </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> When using the Node.js driver v6.0 and later, you must import <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> from <code class="leafygreen-ui-1l06pbn"> mongodb </code> . </p> <p class="leafygreen-ui-1kp3ins"> For earlier driver versions, import <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> from <code class="leafygreen-ui-1l06pbn"> mongodb-client-encryption </code> . </p> </div> </div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"await clientEncryption.createEncryptedCollection(\n encryptedDatabase,\n encryptedCollectionName,\n {\n provider: kmsProviderName,\n createCollectionOptions: encryptedFieldsMap,\n masterKey: customerMasterKeyCredentials,\n }\n);","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">await</span> clientEncryption.<span class="lg-highlight-title lg-highlight-function">createEncryptedCollection</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->encryptedDatabase<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->encryptedCollectionName<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">provider</span>: <!-- -->kmsProviderName<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">createCollectionOptions</span>: <!-- -->encryptedFieldsMap<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">masterKey</span>: <!-- -->customerMasterKeyCredentials<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-209-menu" aria-describedby="select-209-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-210" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rb7:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rb7:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb7:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb7:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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"> The method that creates the encrypted collection requires a reference to a database <em> object </em> rather than the database <em> name </em> . You can obtain this reference by using a method on your client object. </p> </div> </div> </div> <div> <div aria-labelledby="_oabdh2fyi" class="leafygreen-ui-38lglc" id="_3fmpfzuwl" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create your encrypted collection by using the encryption helper method accessed through the <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> class. This method automatically generates data encryption keys for your encrypted fields and creates the encrypted collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"client_encryption.create_encrypted_collection(\n encrypted_client[encrypted_database_name],\n encrypted_collection_name,\n encrypted_fields_map,\n kms_provider_name,\n customer_master_key_credentials,\n)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">client_encryption.<span class="lg-highlight-title lg-highlight-function">create_encrypted_collection</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> encrypted_client[encrypted_database_name],</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> encrypted_collection_name,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> encrypted_fields_map,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kms_provider_name,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> customer_master_key_credentials,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-212-menu" aria-describedby="select-212-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-213" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rb8:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rb8:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb8:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb8:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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"> The method that creates the encrypted collection requires a reference to a database <em> object </em> rather than the database <em> name </em> . You can obtain this reference by using a method on your client object. </p> </div> </div> </div> </div> </div> </li> </ol> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Insert a Document with Encrypted Fields <a class="headerlink leafygreen-ui-1kepx47" href="#insert-a-document-with-encrypted-fields" 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-a-document-with-encrypted-fields"> </div> </a> </h3> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-22"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_g9dao8oxg" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_wd5r4ncz3" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_baaoe3ftn" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_wa7vo4gsm" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_ff41vuwh3" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_5yzha6x5i" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_64snk7f64" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_m5tov8bd4" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_yqicfz83e" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_b60q1dovz" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_neg3iwenc" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_39qg90w6s" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_d4huie42u" class="leafygreen-ui-38lglc" id="_8jtemfz6a" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create a sample document that describes a patient's personal information. Use the encrypted client to insert it into the <code class="leafygreen-ui-1l06pbn"> patients </code> collection, as shown in the following example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const patientDocument = {\n patientName: \"Jon Doe\",\n patientId: 12345678,\n patientRecord: {\n ssn: \"987-65-4320\",\n billing: {\n type: \"Visa\",\n number: \"4111111111111111\",\n },\n billAmount: 1500,\n },\n};\n\nconst encryptedCollection = encryptedClient\n .getDB(encryptedDatabaseName)\n .getCollection(encryptedCollectionName);\n\nconst insertResult = await encryptedCollection.insertOne(patientDocument);","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> patientDocument <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">patientName</span>: <span class="lg-highlight-string">"Jon Doe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">patientId</span>: <span class="lg-highlight-number">12345678</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">patientRecord</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ssn</span>: <span class="lg-highlight-string">"987-65-4320"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">billing</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Visa"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-string">"4111111111111111"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">billAmount</span>: <span class="lg-highlight-number">1500</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</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"><span class="lg-highlight-keyword">const</span> encryptedCollection <!-- -->= <!-- -->encryptedClient</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">getDB</span>(<!-- -->encryptedDatabaseName)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">getCollection</span>(<!-- -->encryptedCollectionName)<!-- -->;</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-keyword">const</span> insertResult <!-- -->= <span class="lg-highlight-keyword">await</span> encryptedCollection.<span class="lg-highlight-title lg-highlight-function">insertOne</span>(<!-- -->patientDocument)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-215-menu" aria-describedby="select-215-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-216" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rb9:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rb9:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb9:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rb9:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_ji5v0ztna" class="leafygreen-ui-38lglc" id="_yy28b5hdf" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create a sample document that describes a patient's personal information. Use the encrypted client to insert it into the <code class="leafygreen-ui-1l06pbn"> patients </code> collection, as shown in the following example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var patient = new Patient\n{\n PatientName = \"Jon Doe\",\n Id = new ObjectId(),\n PatientRecord = new PatientRecord\n {\n Ssn = \"987-65-4320\",\n Billing = new PatientBilling\n {\n CardType = \"Visa\",\n CardNumber = 4111111111111111,\n },\n BillAmount = 1500\n }\n};\n\nvar encryptedCollection = encryptedClient.GetDatabase(encryptedDatabaseName).\n GetCollection&lt;patient&gt;(encryptedCollectionName);\n\nencryptedCollection.InsertOne(patient);","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> patient = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Patient</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">PatientName</span> = <span class="lg-highlight-string">"Jon Doe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Id</span> = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">PatientRecord</span> = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">PatientRecord</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Ssn</span> = <span class="lg-highlight-string">"987-65-4320"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Billing</span> = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">PatientBilling</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">CardType</span> = <span class="lg-highlight-string">"Visa"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">CardNumber</span> = <span class="lg-highlight-number">4111111111111111</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">BillAmount</span> = <span class="lg-highlight-number">1500</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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"><span class="lg-highlight-keyword">var</span> encryptedCollection = encryptedClient.<span class="lg-highlight-title lg-highlight-class">GetDatabase</span>(encryptedDatabaseName).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">GetCollection</span>&lt;<span class="lg-highlight-title lg-highlight-class">Patient</span>&gt;(encryptedCollectionName);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">encryptedCollection.<span class="lg-highlight-title lg-highlight-class">InsertOne</span>(patient);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-218-menu" aria-describedby="select-218-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-219" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rba:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rba:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rba:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rba:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_wqtqz1i2y" class="leafygreen-ui-38lglc" id="_lgww28tem" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create a sample document that describes a patient's personal information. Use the encrypted client to insert it into the <code class="leafygreen-ui-1l06pbn"> patients </code> collection, as shown in the following example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"patientDocument := &amp;PatientDocument{\n\tPatientName: \"Jon Doe\",\n\tPatientID: 12345678,\n\tPatientRecord: PatientRecord{\n\t\tSSN: \"987-65-4320\",\n\t\tBilling: PaymentInfo{\n\t\t\tType: \"Visa\",\n\t\t\tNumber: \"4111111111111111\",\n\t\t},\n\t\tBillAmount: 1500,\n\t},\n}\n\ncoll := encryptedClient.Database(encryptedDatabaseName).Collection(encryptedCollectionName)\n\n_, err = coll.InsertOne(context.TODO(), patientDocument)\nif err != nil {\n\tpanic(fmt.Sprintf(\"Unable to insert the patientDocument: %s\", err))\n}","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">patientDocument <!-- -->:<!-- -->= &amp;<span class="lg-highlight-title lg-highlight-class">PatientDocument</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">PatientName</span>: <span class="lg-highlight-string">"Jon Doe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">PatientID</span>: <span class="lg-highlight-number">12345678</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">PatientRecord</span>: <span class="lg-highlight-title lg-highlight-class">PatientRecord</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">SSN</span>: <span class="lg-highlight-string">"987-65-4320"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Billing</span>: <span class="lg-highlight-title lg-highlight-class">PaymentInfo</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Type</span>: <span class="lg-highlight-string">"Visa"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Number</span>: <span class="lg-highlight-string">"4111111111111111"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">BillAmount</span>: <span class="lg-highlight-number">1500</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</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">coll <!-- -->:<!-- -->= encryptedClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(encryptedDatabaseName).<span class="lg-highlight-title lg-highlight-class">Collection</span>(encryptedCollectionName)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">_, err = coll.<span class="lg-highlight-title lg-highlight-class">InsertOne</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), patientDocument)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(fmt.<span class="lg-highlight-title lg-highlight-class">Sprintf</span>(<span class="lg-highlight-string">"Unable to insert the patientDocument: %s"</span>, err))</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-221-menu" aria-describedby="select-221-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-222" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rbb:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rbb:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbb:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbb:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_3lq2pv9pl" class="leafygreen-ui-38lglc" id="_i929mgu8n" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> This tutorial uses POJOs as data models to represent the document structure. To set up your application to use POJOs, add the following code: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"CodecProvider pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build();\nCodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), fromProviders(pojoCodecProvider));","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">CodecProvider</span> pojoCodecProvider = <span class="lg-highlight-title lg-highlight-class">PojoCodecProvider</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>().<span class="lg-highlight-title lg-highlight-function">automatic</span>(<span class="lg-highlight-literal">true</span>).<span class="lg-highlight-title lg-highlight-function">build</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">CodecRegistry</span> pojoCodecRegistry = <span class="lg-highlight-title lg-highlight-function">fromRegistries</span>(<span class="lg-highlight-title lg-highlight-function">getDefaultCodecRegistry</span>(), <span class="lg-highlight-title lg-highlight-function">fromProviders</span>(pojoCodecProvider));</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-224-menu" aria-describedby="select-224-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-225" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rbc:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rbc:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbc:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbc:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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 learn more about Java POJOs, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Plain_old_Java_object" rel="noopener noreferrer"> <span> Plain Old Java Object wikipedia article <!-- --> . </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> </p> <p class="leafygreen-ui-1kp3ins"> This tutorial uses the following POJOs: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> Patient </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> PatientRecord </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> PatientBilling </code> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You can view these classes in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/qe-tutorials/java/src/main/java/com/mongodb/tutorials/qe/models" rel="noopener noreferrer"> <span> models package of the complete Java application <!-- --> . </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> </p> <p class="leafygreen-ui-1kp3ins"> Add these POJO classes to your application. Then, create an instance of a <code class="leafygreen-ui-1l06pbn"> Patient </code> that describes a patient's personal information. Use the encrypted client to insert it into the <code class="leafygreen-ui-1l06pbn"> patients </code> collection, as shown in the following example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoDatabase encryptedDb = encryptedClient.getDatabase(encryptedDatabaseName).withCodecRegistry(pojoCodecRegistry);\nMongoCollection&lt;patient&gt; collection = encryptedDb.getCollection(encryptedCollectionName, Patient.class);\n\nPatientBilling patientBilling = new PatientBilling(\"Visa\", \"4111111111111111\");\nPatientRecord patientRecord = new PatientRecord(\"987-65-4320\", patientBilling, 1500);\nPatient patientDocument = new Patient(\"Jon Doe\", patientRecord);\n\nInsertOneResult result = collection.insertOne(patientDocument);","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">MongoDatabase</span> encryptedDb = encryptedClient.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(encryptedDatabaseName).<span class="lg-highlight-title lg-highlight-function">withCodecRegistry</span>(pojoCodecRegistry);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">MongoCollection</span>&lt;<span class="lg-highlight-title lg-highlight-class">Patient</span>&gt; collection = encryptedDb.<span class="lg-highlight-title lg-highlight-function">getCollection</span>(encryptedCollectionName, <span class="lg-highlight-title lg-highlight-class">Patient</span>.<span class="lg-highlight-property lg-highlight-class">class</span>);</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">PatientBilling</span> patientBilling = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">PatientBilling</span>(<span class="lg-highlight-string">"Visa"</span>, <span class="lg-highlight-string">"4111111111111111"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">PatientRecord</span> patientRecord = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">PatientRecord</span>(<span class="lg-highlight-string">"987-65-4320"</span>, patientBilling, <span class="lg-highlight-number">1500</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Patient</span> patientDocument = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Patient</span>(<span class="lg-highlight-string">"Jon Doe"</span>, patientRecord);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">InsertOneResult</span> result = collection.<span class="lg-highlight-title lg-highlight-function">insertOne</span>(patientDocument);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-227-menu" aria-describedby="select-227-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-228" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rbd:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rbd:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbd:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbd:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_7usl4fs1r" class="" id="_vvjd6ofls" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create a sample document that describes a patient's personal information. Use the encrypted client to insert it into the <code class="leafygreen-ui-1l06pbn"> patients </code> collection, as shown in the following example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const patientDocument = {\n patientName: \"Jon Doe\",\n patientId: 12345678,\n patientRecord: {\n ssn: \"987-65-4320\",\n billing: {\n type: \"Visa\",\n number: \"4111111111111111\",\n },\n billAmount: 1500,\n },\n};\n\nconst encryptedCollection = encryptedClient\n .db(encryptedDatabaseName)\n .collection(encryptedCollectionName);\n\nconst result = await encryptedCollection.insertOne(patientDocument);","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> patientDocument <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">patientName</span>: <span class="lg-highlight-string">"Jon Doe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">patientId</span>: <span class="lg-highlight-number">12345678</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">patientRecord</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ssn</span>: <span class="lg-highlight-string">"987-65-4320"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">billing</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Visa"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-string">"4111111111111111"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">billAmount</span>: <span class="lg-highlight-number">1500</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</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"><span class="lg-highlight-keyword">const</span> encryptedCollection <!-- -->= <!-- -->encryptedClient</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">db</span>(<!-- -->encryptedDatabaseName)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">collection</span>(<!-- -->encryptedCollectionName)<!-- -->;</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> result <!-- -->= <span class="lg-highlight-keyword">await</span> encryptedCollection.<span class="lg-highlight-title lg-highlight-function">insertOne</span>(<!-- -->patientDocument)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-230-menu" aria-describedby="select-230-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-231" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rbe:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rbe:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbe:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbe:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_chryxzyyp" class="leafygreen-ui-38lglc" id="_ex8pwquf4" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create a sample document that describes a patient's personal information. Use the encrypted client to insert it into the <code class="leafygreen-ui-1l06pbn"> patients </code> collection, as shown in the following example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"patient_document = {\n \"patientName\": \"Jon Doe\",\n \"patientId\": 12345678,\n \"patientRecord\": {\n \"ssn\": \"987-65-4320\",\n \"billing\": {\n \"type\": \"Visa\",\n \"number\": \"4111111111111111\",\n },\n \"billAmount\": 1500,\n },\n}\n\nencrypted_collection = encrypted_client[encrypted_database_name][encrypted_collection_name]\n\nresult = encrypted_collection.insert_one(patient_document)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">patient_document = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"patientName"</span>: <span class="lg-highlight-string">"Jon Doe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"patientId"</span>: <span class="lg-highlight-number">12345678</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"patientRecord"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ssn"</span>: <span class="lg-highlight-string">"987-65-4320"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"billing"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span>: <span class="lg-highlight-string">"Visa"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"number"</span>: <span class="lg-highlight-string">"4111111111111111"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"billAmount"</span>: <span class="lg-highlight-number">1500</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</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">encrypted_collection = encrypted_client[encrypted_database_name][encrypted_collection_name]</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">result = encrypted_collection.<span class="lg-highlight-title lg-highlight-function">insert_one</span>(patient_document)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-233-menu" aria-describedby="select-233-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-234" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rbf:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rbf:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbf:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbf:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Query on an Encrypted Field <a class="headerlink leafygreen-ui-1kepx47" href="#query-on-an-encrypted-field" 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="query-on-an-encrypted-field"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following code sample executes a find query on an encrypted field and prints the decrypted data: </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-24"> <div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_flz10tcc9" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_4nalve18y" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> MongoDB Shell </div> </button> <button aria-controls="_lxlg1rq18" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_4o2bjplki" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> C# </div> </button> <button aria-controls="_xulfuxeeo" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ezxq4h2kq" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Go </div> </button> <button aria-controls="_syvzjrf58" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_murk8pkd7" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Java (Sync) </div> </button> <button aria-controls="_5dz1r7ybf" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_c5ye3fyy7" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Node.js </div> </button> <button aria-controls="_93zbcmobs" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_3uby6v56u" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Python </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="_nrqaftbvb" class="leafygreen-ui-38lglc" id="_2xo6xln0q" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const findResult = await encryptedCollection.findOne({\n \"patientRecord.ssn\": \"987-65-4320\",\n});\nconsole.log(findResult);","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> findResult <!-- -->= <span class="lg-highlight-keyword">await</span> encryptedCollection.<span class="lg-highlight-title lg-highlight-function">findOne</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"patientRecord.ssn"</span>: <span class="lg-highlight-string">"987-65-4320"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">})<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(<!-- -->findResult)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-236-menu" aria-describedby="select-236-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-237" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rbg:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rbg:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbg:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbg:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_i4khzov7m" class="leafygreen-ui-38lglc" id="_n7azq1msg" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var ssnFilter = Builders&lt;patient&gt;.Filter.Eq(\"patientRecord.ssn\", patient.PatientRecord.Ssn);\nvar findResult = await encryptedCollection.Find(ssnFilter).ToCursorAsync();\n\nConsole.WriteLine(findResult.FirstOrDefault().ToJson());","programmingLanguage":"C#"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> ssnFilter = <span class="lg-highlight-title lg-highlight-class">Builders</span>&lt;<span class="lg-highlight-title lg-highlight-class">Patient</span>&gt;.<span class="lg-highlight-property">Filter</span>.<span class="lg-highlight-title lg-highlight-class">Eq</span>(<span class="lg-highlight-string">"patientRecord.ssn"</span>, patient.<span class="lg-highlight-property">PatientRecord</span>.<span class="lg-highlight-property">Ssn</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> findResult = <span class="lg-highlight-keyword">await</span> encryptedCollection.<span class="lg-highlight-title lg-highlight-class">Find</span>(ssnFilter).<span class="lg-highlight-title lg-highlight-class">ToCursorAsync</span>();</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">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>(findResult.<span class="lg-highlight-title lg-highlight-class">FirstOrDefault</span>().<span class="lg-highlight-title lg-highlight-class">ToJson</span>());</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-239-menu" aria-describedby="select-239-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-240" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rbh:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rbh:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbh:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbh:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_kb3hlync1" class="leafygreen-ui-38lglc" id="_glv0v6usy" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var findResult PatientDocument\nerr = coll.FindOne(\n\tcontext.TODO(),\n\tbson.M{\"patientRecord.ssn\": \"987-65-4320\"},\n).Decode(&amp;findResult)","programmingLanguage":"Golang"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">var</span> findResult <span class="lg-highlight-title lg-highlight-class">PatientDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">err = coll.<span class="lg-highlight-title lg-highlight-class">FindOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> bson.<span class="lg-highlight-property">M</span>{<span class="lg-highlight-string">"patientRecord.ssn"</span>: <span class="lg-highlight-string">"987-65-4320"</span>},</td></tr><tr class=""><td class="leafygreen-ui-7razhx">).<span class="lg-highlight-title lg-highlight-class">Decode</span>(&amp;findResult)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-242-menu" aria-describedby="select-242-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-243" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rbi:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rbi:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbi:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbi:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_7tvmgkjni" class="leafygreen-ui-38lglc" id="_kq6orso6a" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Patient findResult = collection.find(\n new BsonDocument()\n .append(\"patientRecord.ssn\", new BsonString(\"987-65-4320\")))\n .first();\n \nSystem.out.println(findResult);","programmingLanguage":"Java"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-title lg-highlight-class">Patient</span> findResult = collection.<span class="lg-highlight-title lg-highlight-function">find</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"patientRecord.ssn"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonString</span>(<span class="lg-highlight-string">"987-65-4320"</span>)))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">first</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> </td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">System</span>.<span class="lg-highlight-property">out</span>.<span class="lg-highlight-title lg-highlight-function">println</span>(findResult);</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-245-menu" aria-describedby="select-245-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-246" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rbj:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rbj:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbj:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbj:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_4cjcyko11" class="" id="_zwbs1v7jk" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const findResult = await encryptedCollection.findOne({\n \"patientRecord.ssn\": \"987-65-4320\",\n});\nconsole.log(findResult);","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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"><span class="lg-highlight-keyword">const</span> findResult <!-- -->= <span class="lg-highlight-keyword">await</span> encryptedCollection.<span class="lg-highlight-title lg-highlight-function">findOne</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"patientRecord.ssn"</span>: <span class="lg-highlight-string">"987-65-4320"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">})<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(<!-- -->findResult)<!-- -->;</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-248-menu" aria-describedby="select-248-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-249" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rbk:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rbk:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbk:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbk:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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="_o3nl6en6z" class="leafygreen-ui-38lglc" id="_62ei3n343" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"find_result = encrypted_collection.find_one({\n \"patientRecord.ssn\": \"987-65-4320\"\n})\n\nprint(find_result)","programmingLanguage":"Python"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-9lvdmr"> <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">find_result = encrypted_collection.<span class="lg-highlight-title lg-highlight-function">find_one</span>({</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"patientRecord.ssn"</span>: <span class="lg-highlight-string">"987-65-4320"</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"><span class="lg-highlight-title lg-highlight-function">print</span>(find_result)</td></tr></tbody></table></code></pre> <div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel"> <div class="leafygreen-ui-148abs6"> <div class="leafygreen-ui-omjz13" data-lgid="lg-select"> <button aria-controls="select-251-menu" aria-describedby="select-251-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-252" type="button" value="Node.js"> <div class="leafygreen-ui-v038xi"> </div> <div class="leafygreen-ui-16tr4y"> <svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_2131_12968)"> <mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask0_2131_12968)"> <mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6"> <path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white"> </path> </mask> <g mask="url(#mask1_2131_12968)"> <path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black"> </path> <path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black"> </path> <path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black"> </path> <path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd"> </path> <path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd"> </path> <path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black"> </path> <path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black"> </path> <path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rbl:paint2)"> </path> </g> </g> </g> <defs> <lineargradient gradientunits="userSpaceOnUse" id=":rbl:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331"> <stop stop-color="#3F873F"> </stop> <stop offset="0.3296" stop-color="#3F8B3D"> </stop> <stop offset="0.6367" stop-color="#3E9638"> </stop> <stop offset="0.9341" stop-color="#3DA92E"> </stop> <stop offset="1" stop-color="#3DAE2B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbl:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932"> <stop offset="0.1376" stop-color="#3F873F"> </stop> <stop offset="0.4016" stop-color="#52A044"> </stop> <stop offset="0.7129" stop-color="#64B749"> </stop> <stop offset="0.9081" stop-color="#6ABF4B"> </stop> </lineargradient> <lineargradient gradientunits="userSpaceOnUse" id=":rbl:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874"> <stop offset="0.0919165" stop-color="#6ABF4B"> </stop> <stop offset="0.2871" stop-color="#64B749"> </stop> <stop offset="0.5984" stop-color="#52A044"> </stop> <stop offset="0.8624" stop-color="#3F873F"> </stop> </lineargradient> <clippath id="clip0_2131_12968"> <rect fill="white" height="18.427" transform="translate(0 6)" width="30"> </rect> </clippath> </defs> </svg> <div class="leafygreen-ui-obh8q1"> <div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text"> Node.js </div> </div> <svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16"> <path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor"> </path> </svg> </div> </button> <div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback"> </div> </div> </div> <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> <p class="leafygreen-ui-1kp3ins"> The output of the preceding code sample should look similar to the following: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\": {\n \"$oid\": \"648b384a722cb9b8392df76a\"\n },\n \"name\": \"Jon Doe\",\n \"record\": {\n \"ssn\": \"987-65-4320\",\n \"billing\": {\n \"type\": \"Visa\",\n \"number\": \"4111111111111111\"\n },\n \"billAmount\": 1500\n },\n \"__safeContent__\": [\n {\n \"$binary\": {\n \"base64\": \"L1NsYItk0Sg+oL66DBj6IYHbX7tveANQyrU2cvMzD9Y=\",\n \"subType\": \"00\"\n }\n }\n ]\n}\n","programmingLanguage":"JSON"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"_id"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$oid"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"648b384a722cb9b8392df76a"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"name"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"Jon Doe"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"record"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"ssn"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"987-65-4320"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"billing"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"type"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"Visa"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"number"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"4111111111111111"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"billAmount"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1500</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"__safeContent__"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$binary"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"base64"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"L1NsYItk0Sg+oL66DBj6IYHbX7tveANQyrU2cvMzD9Y="</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"subType"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"00"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">]</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre> </div> </div> </div> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Do not Modify the __safeContent__ Field </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> __safeContent__ </code> field is essential to Queryable Encryption. Do not modify the contents of this field. </p> </div> </div> </section> </div> </div> </div> </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> <p class="leafygreen-ui-1kp3ins"> To view a tutorial on production-ready Queryable Encryption with a remote KMS, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/tutorials/#std-label-qe-tutorial-automatic-encryption"> Tutorials <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> To learn how Queryable Encryption works, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/#std-label-qe-fundamentals"> Fundamentals <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> To learn more about the topics mentioned in this guide, see the following links: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Learn more about Queryable Encryption components on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/reference/#std-label-qe-reference"> Reference </a> page. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Learn how Customer Master Keys and Data Encryption Keys work on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/keys-key-vaults/#std-label-qe-reference-keys-key-vaults"> Encryption Keys and Key Vaults </a> page. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> See how KMS Providers manage your Queryable Encryption keys on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers"> KMS Providers </a> page. </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $lte (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-lte--aggregation-" 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="-lte--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="expression"> <dt> <code class="leafygreen-ui-1l06pbn"> $lte </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-lte" title="Permalink to this definition"> <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="mongodb-expression-exp.-lte"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Compares two values and returns: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> true </code> when the first value is <em> less than or equivalent to </em> the second value. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> false </code> when the first value is <em> greater than </em> the second value. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-lte" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $lte </code> </span> </a> compares both value and type, using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-type-comparison-order/#std-label-bson-types-comparison-order"> specified BSON comparison order </a> for values of different types. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-lte" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $lte </code> </span> </a> has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $lte: [ &lt;expression1&gt;, &lt;expression2&gt; ] }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$lte</span>: <!-- -->[ &lt;<!-- -->expression1<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->expression2<!-- -->&gt; <!-- -->] }</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"> For more information on expressions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> Expression Operators <!-- --> . </a> </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Consider an <code class="leafygreen-ui-1l06pbn"> inventory </code> collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.insertMany( [\n { _id : 1, item : \"abc1\", description: \"product 1\", qty: 300 },\n { _id : 2, item : \"abc2\", description: \"product 2\", qty: 200 },\n { _id : 3, item : \"xyz1\", description: \"product 3\", qty: 250 },\n { _id : 4, item : \"VWZ1\", description: \"product 4\", qty: 300 },\n { _id : 5, item : \"VWZ2\", description: \"product 5\", qty: 180 }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">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"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">1</span>, <!-- -->item <!-- -->: <span class="lg-highlight-string">"abc1"</span>, <span class="lg-highlight-attr">description</span>: <span class="lg-highlight-string">"product 1"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">300</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">2</span>, <!-- -->item <!-- -->: <span class="lg-highlight-string">"abc2"</span>, <span class="lg-highlight-attr">description</span>: <span class="lg-highlight-string">"product 2"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">200</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">3</span>, <!-- -->item <!-- -->: <span class="lg-highlight-string">"xyz1"</span>, <span class="lg-highlight-attr">description</span>: <span class="lg-highlight-string">"product 3"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">250</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">4</span>, <!-- -->item <!-- -->: <span class="lg-highlight-string">"VWZ1"</span>, <span class="lg-highlight-attr">description</span>: <span class="lg-highlight-string">"product 4"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">300</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">5</span>, <!-- -->item <!-- -->: <span class="lg-highlight-string">"VWZ2"</span>, <span class="lg-highlight-attr">description</span>: <span class="lg-highlight-string">"product 5"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">180</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> <p class="leafygreen-ui-1kp3ins"> The following operation uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-lte" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $lte </code> </span> </a> operator to determine if <code class="leafygreen-ui-1l06pbn"> qty </code> is less than or equal to <code class="leafygreen-ui-1l06pbn"> 250 </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.aggregate(\n [\n {\n $project:\n {\n item: 1,\n qty: 1,\n qtyLte250: { $lte: [ \"$qty\", 250 ] },\n _id: 0\n }\n }\n ]\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">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qtyLte250</span>: <!-- -->{ <span class="lg-highlight-attr">$lte</span>: <!-- -->[ <span class="lg-highlight-string">"$qty"</span>, <span class="lg-highlight-number">250</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"item\" : \"abc1\", \"qty\" : 300, \"qtyLte250\" : false }\n{ \"item\" : \"abc2\", \"qty\" : 200, \"qtyLte250\" : true }\n{ \"item\" : \"xyz1\", \"qty\" : 250, \"qtyLte250\" : true }\n{ \"item\" : \"VWZ1\", \"qty\" : 300, \"qtyLte250\" : false }\n{ \"item\" : \"VWZ2\", \"qty\" : 180, \"qtyLte250\" : true }","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">{ <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc1"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">300</span>, <span class="lg-highlight-string">"qtyLte250"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc2"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">200</span>, <span class="lg-highlight-string">"qtyLte250"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"xyz1"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">250</span>, <span class="lg-highlight-string">"qtyLte250"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"VWZ1"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">300</span>, <span class="lg-highlight-string">"qtyLte250"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"VWZ2"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">180</span>, <span class="lg-highlight-string">"qtyLte250"</span> <!-- -->: <span class="lg-highlight-literal">true</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> </section> </section>
https://www.mongodb.com/docs/manual/reference/aggregation-commands-comparison/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Aggregation Commands Comparison <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-commands-comparison" 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="aggregation-commands-comparison"> </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="#aggregation-commands-comparison-table" target="_self"> <span> Aggregation Commands Comparison Table </span> </a> </li> </ul> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Aggregation Pipeline as Alternative to Map-Reduce </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce"> map-reduce </a> is deprecated: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Instead of <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce"> map-reduce </a> , you should use an <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipeline </a> . Aggregation pipelines provide better performance and usability than map-reduce. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You can rewrite map-reduce operations using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference"> aggregation pipeline stages </a> , such as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> , and others. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For map-reduce operations that require custom functionality, you can use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator"> <code class="leafygreen-ui-1l06pbn"> $accumulator </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function"> <code class="leafygreen-ui-1l06pbn"> $function </code> </a> aggregation operators. You can use those operators to define custom aggregation expressions in JavaScript. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For examples of aggregation pipeline alternatives to map-reduce, see: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/map-reduce-to-aggregation-pipeline/"> Map-Reduce to Aggregation Pipeline </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/map-reduce-examples/"> Map-Reduce Examples </a> </p> </li> </ul> </div> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Aggregation Commands Comparison Table <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-commands-comparison-table" 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="aggregation-commands-comparison-table"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following table provides a brief overview of the features of the MongoDB aggregation commands. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:40%"/> <col style="width:40%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate"> <code class="leafygreen-ui-1l06pbn"> aggregate </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce"> <code class="leafygreen-ui-1l06pbn"> mapReduce </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.mapReduce/#mongodb-method-db.collection.mapReduce"> <code class="leafygreen-ui-1l06pbn"> db.collection.mapReduce() </code> </a> </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Description </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Designed with specific goals of improving performance and usability for aggregation tasks. </p> <p class="leafygreen-ui-1kp3ins"> Uses a "pipeline" approach where objects are transformed as they pass through a series of pipeline operators such as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/"> Aggregation Operators </a> for more information on the pipeline operators. </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Implements the Map-Reduce aggregation for processing large data sets. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Key Features </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Pipeline operators can be repeated as needed. </p> <p class="leafygreen-ui-1kp3ins"> Pipeline operators need not produce one output document for every input document. </p> <p class="leafygreen-ui-1kp3ins"> Can also generate new documents or filter out documents. </p> <p class="leafygreen-ui-1kp3ins"> Using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> stage, you can create on-demand materialized views, where the content of the output collection can be updated incrementally the pipeline is run. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> can incorporate results (insert new documents, merge documents, replace documents, keep existing documents, fail the operation, process documents with a custom update pipeline) into an existing collection. </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> In addition to grouping operations, can perform complex aggregation tasks as well as perform incremental aggregation on continuously growing datasets. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/map-reduce-examples/"> Map-Reduce Examples </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/perform-incremental-map-reduce/"> Perform Incremental Map-Reduce <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Flexibility </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> You can define custom aggregation expressions with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator"> <code class="leafygreen-ui-1l06pbn"> $accumulator </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function"> <code class="leafygreen-ui-1l06pbn"> $function </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> You can also add computed fields, create new virtual sub-objects, and extract sub-fields into the top-level of results by using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> pipeline operator. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> for more information as well as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/"> Aggregation Operators </a> for more information on all the available pipeline operators. </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Custom <code class="leafygreen-ui-1l06pbn"> map </code> , <code class="leafygreen-ui-1l06pbn"> reduce </code> and <code class="leafygreen-ui-1l06pbn"> finalize </code> JavaScript functions offer flexibility to aggregation logic. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce"> <code class="leafygreen-ui-1l06pbn"> mapReduce </code> </a> for details and restrictions on the functions. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Output Results </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns results as a cursor. If the pipeline includes the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out"> <code class="leafygreen-ui-1l06pbn"> $out </code> </a> stage or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> stage, the cursor is empty. </p> <p class="leafygreen-ui-1kp3ins"> With <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out"> <code class="leafygreen-ui-1l06pbn"> $out </code> </a> , you can replace an existing output collection completely or output to a new collection. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out"> <code class="leafygreen-ui-1l06pbn"> $out </code> </a> for details. </p> <p class="leafygreen-ui-1kp3ins"> With <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> , you can output to a new or existing collection. For existing cllections, you can specify how to incorporate the results into the output collection (insert new documents, merge documents, replace documents, keep existing documents, fail the operation, process documents with a custom update pipeline). See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> for details. </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns results in various options (inline, new collection, merge, replace, reduce). See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce"> <code class="leafygreen-ui-1l06pbn"> mapReduce </code> </a> for details on the output options. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Sharding </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Supports non-sharded and sharded input collections. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> can output to a non-sharded or sharded collection. </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Supports non-sharded and sharded input collections. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> More Information </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> Aggregation Pipeline </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate"> <code class="leafygreen-ui-1l06pbn"> aggregate </code> </a> </p> </li> </ul> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/"> Map-Reduce </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.mapReduce/#mongodb-method-db.collection.mapReduce"> <code class="leafygreen-ui-1l06pbn"> db.collection.mapReduce() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce"> <code class="leafygreen-ui-1l06pbn"> mapReduce </code> . </a> </p> </li> </ul> </div> </div> </td> </tr> </tbody> </table> </div> <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/reference/map-reduce-to-aggregation-pipeline/"> Map-Reduce to Aggregation Pipeline </a> </p> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/core/sharding-change-a-shard-key/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Change a Shard Key <a class="headerlink leafygreen-ui-1kepx47" href="#change-a-shard-key" 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-a-shard-key"> </div> </a> </h1> <p class="leafygreen-ui-1kp3ins"> The ideal shard key allows MongoDB to distribute documents evenly throughout the cluster while facilitating common query patterns. A suboptimal shard key can lead to uneven data distribution and the following problems: </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/sharding-troubleshooting-shard-keys/#std-label-sharding-troubleshooting-jumbo-chunks"> Jumbo chunks </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-troubleshooting-shard-keys/#std-label-sharding-troubleshooting-monotonicity"> Uneven load distribution </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-troubleshooting-shard-keys/#std-label-sharding-troubleshooting-scatter-gather"> Decreased query performance over time </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> To address these issues, MongoDB allows you to change your shard key: </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"> Data distribution fixes are most effective when you reshard a collection. If you want to improve data distribution and your cluster meets the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-reshard-requirements"> criteria to reshard </a> , you should reshard the collection instead of refining the shard key. If your cluster doesn't meet the criteria to reshard, you should refine the shard key. </p> <p class="leafygreen-ui-1kp3ins"> For more information on common performance and scaling issues and advice on how to fix them, read <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-troubleshooting-shard-keys/#std-label-shardkey-troubleshoot-shard-keys"> Troubleshoot Shard Keys <!-- --> . </a> </p> </section>
https://www.mongodb.com/docs/manual/core/query-shapes/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Query Shapes <a class="headerlink leafygreen-ui-1kepx47" href="#query-shapes" 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="query-shapes"> </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="#examples" target="_self"> <span> Examples </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#get-started" target="_self"> <span> Get Started </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> <div> <p> <em> Changed <!-- --> in version <!-- --> 8.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> A query shape is a set of specifications that group similar queries together. Specifications can include filters, sorts, projections, aggregation pipeline stages, a namespace, and others. Queries that have similar specifications have the same query shape. </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, the pre-existing query shape is renamed to the <strong> plan cache query shape </strong> , and the <code class="leafygreen-ui-1l06pbn"> queryHash </code> field is renamed <code class="leafygreen-ui-1l06pbn"> planCacheShapeHash </code> . For the components of a command that differentiate plan cache query shapes, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-plan-cache-query-shape"> plan cache query shape </a> definition. MongoDB 8.0 uses the new query shape and the existing plan cache query shape as shown on this page. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> In MongoDB 8.0 and earlier versions, the existing plan cache query shape supports: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> query planning in <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-cache-entry-state"> plan cache </a> scenarios. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> deprecated <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-index-filters"> index filters </a> . (Starting in MongoDB 8.0, use the new query settings for the new query shape.) </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> a subset of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> Aggregation Pipeline <!-- --> . </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 8.0, the new query shape supports: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> query settings, which you can add with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setQuerySettings/#mongodb-dbcommand-dbcmd.setQuerySettings"> <code class="leafygreen-ui-1l06pbn"> setQuerySettings </code> </a> . (As you'll see later on this page, query settings specify indexes and execution settings for a query shape.) </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/queryStats/#std-label-queryStats-queryShape"> $queryStats query shape statistics <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the fields and operations also supported by the plan cache query shape. Examples: <code class="leafygreen-ui-1l06pbn"> filter </code> , <code class="leafygreen-ui-1l06pbn"> sort </code> , and <code class="leafygreen-ui-1l06pbn"> projection </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the majority of the fields and operands available for the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/find/#mongodb-dbcommand-dbcmd.find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/distinct/#mongodb-dbcommand-dbcmd.distinct"> <code class="leafygreen-ui-1l06pbn"> distinct </code> </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate"> <code class="leafygreen-ui-1l06pbn"> aggregate </code> </a> commands. To view the fields and operands for the commands, see the Syntax sections on each command page. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the overall structure of the <code class="leafygreen-ui-1l06pbn"> find </code> , <code class="leafygreen-ui-1l06pbn"> aggregation </code> , and <code class="leafygreen-ui-1l06pbn"> distinct </code> commands, which support a wider range of query shapes than the existing plan cache query shape. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/operation-rejection-filters/#std-label-operation-rejection-filters"> operation rejection filters </a> to block <code class="leafygreen-ui-1l06pbn"> find </code> , <code class="leafygreen-ui-1l06pbn"> aggregation </code> , and <code class="leafygreen-ui-1l06pbn"> distinct </code> commands that have a specified query shape. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> the entire aggregation pipeline. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 8.0, you can use a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/querySettings/#mongodb-pipeline-pipe.-querySettings"> <code class="leafygreen-ui-1l06pbn"> $querySettings </code> </a> pipeline stage to return query settings specified for each query shape. </p> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following sections show examples with query shapes for the following example <code class="leafygreen-ui-1l06pbn"> pizzaOrders </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.pizzaOrders.insertMany( [\n { _id: 0, type: \"pepperoni\", size: \"small\", price: 19,\n totalNumber: 10, orderDate: ISODate( \"2023-03-13T08:14:30Z\" ) },\n { _id: 1, type: \"pepperoni\", size: \"medium\", price: 20,\n totalNumber: 20, orderDate: ISODate( \"2023-03-13T09:13:24Z\" ) },\n { _id: 2, type: \"pepperoni\", size: \"large\", price: 21,\n totalNumber: 30, orderDate: ISODate( \"2023-03-17T09:22:12Z\" ) },\n { _id: 3, type: \"cheese\", size: \"small\", price: 12,\n totalNumber: 15, orderDate: ISODate( \"2023-03-13T11:21:39.736Z\" ) }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">pizzaOrders</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"pepperoni"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"small"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">19</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">totalNumber</span>: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2023-03-13T08:14:30Z"</span> ) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"pepperoni"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"medium"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">20</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">totalNumber</span>: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2023-03-13T09:13:24Z"</span> ) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"pepperoni"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"large"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">21</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">totalNumber</span>: <span class="lg-highlight-number">30</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2023-03-17T09:22:12Z"</span> ) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"cheese"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"small"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">12</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">totalNumber</span>: <span class="lg-highlight-number">15</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2023-03-13T11:21:39.736Z"</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> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Matching Query Shapes <a class="headerlink leafygreen-ui-1kepx47" href="#matching-query-shapes" 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="matching-query-shapes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following example query shape shows specifications for a <code class="leafygreen-ui-1l06pbn"> find </code> command on the <code class="leafygreen-ui-1l06pbn"> pizzaOrders </code> collection in the default <code class="leafygreen-ui-1l06pbn"> test </code> database: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"find: \"pizzaOrders\",\nfilter: {\n orderDate: { $gt: ISODate( \"2023-01-20T00:00:00Z\" ) }\n},\nsort: {\n totalNumber: 1\n},\n$db: \"test\"","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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"><span class="lg-highlight-attr">find</span>: <span class="lg-highlight-string">"pizzaOrders"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">filter</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">orderDate</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2023-01-20T00:00:00Z"</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>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">totalNumber</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"><span class="lg-highlight-attr">$db</span>: <span class="lg-highlight-string">"test"</span></td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> The example filter limits the documents to those with an order date greater than the specified date. The example has an ascending sort on the total number of pizzas ordered. </p> <p class="leafygreen-ui-1kp3ins"> To view the MongoDB 8.0 <code class="leafygreen-ui-1l06pbn"> queryShapeHash </code> and <code class="leafygreen-ui-1l06pbn"> planCacheShapeHash </code> hexadecimal strings, you can use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/explain/#mongodb-dbcommand-dbcmd.explain"> <code class="leafygreen-ui-1l06pbn"> explain </code> </a> command. </p> <p class="leafygreen-ui-1kp3ins"> The following <code class="leafygreen-ui-1l06pbn"> explain </code> examples contain queries with the same query shape: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.pizzaOrders.explain().find(\n { orderDate: { $gt: ISODate( \"2024-05-10T05:15:35Z\" ) } } ).\n sort( { totalNumber: 1 }\n)\n\ndb.pizzaOrders.explain().find(\n { orderDate: { $gt: ISODate( \"2024-02-05T07:07:16Z\" ) } } ).\n sort( { totalNumber: 1 }\n)\n\ndb.pizzaOrders.explain().find(\n { orderDate: { $gt: ISODate( \"2023-03-08T08:12:25Z\" ) } } ).\n sort( { totalNumber: 1 }\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">pizzaOrders</span>.<span class="lg-highlight-title lg-highlight-function">explain</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">find</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">orderDate</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2024-05-10T05:15:35Z"</span> ) } } ).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">totalNumber</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">db.<span class="lg-highlight-property">pizzaOrders</span>.<span class="lg-highlight-title lg-highlight-function">explain</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">find</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">orderDate</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2024-02-05T07:07:16Z"</span> ) } } ).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">totalNumber</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">db.<span class="lg-highlight-property">pizzaOrders</span>.<span class="lg-highlight-title lg-highlight-function">explain</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">find</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">orderDate</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2023-03-08T08:12:25Z"</span> ) } } ).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">totalNumber</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> <p class="leafygreen-ui-1kp3ins"> Because the query shapes are the same, the <code class="leafygreen-ui-1l06pbn"> explain </code> output has the same <code class="leafygreen-ui-1l06pbn"> queryShapeHash </code> for each of the examples, and the same <code class="leafygreen-ui-1l06pbn"> planCacheShapeHash </code> for each. For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"queryShapeHash: 'AB8ECADEE8F0EB0F447A30744EB4813AE7E0BFEF523B0870CA10FCBC87F5D8F1'\nplanCacheShapeHash: '48E51110'","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">queryShapeHash</span>: <span class="lg-highlight-string">'AB8ECADEE8F0EB0F447A30744EB4813AE7E0BFEF523B0870CA10FCBC87F5D8F1'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">planCacheShapeHash</span>: <span class="lg-highlight-string">'48E51110'</span></td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Different Query Shape <a class="headerlink leafygreen-ui-1kepx47" href="#different-query-shape" 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="different-query-shape"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> A query has a different shape if the query has different specifications. For example, if a query has a different filter, sort, projection, namespace, or aggregation pipeline stages. </p> <p class="leafygreen-ui-1kp3ins"> In the example in the previous section, the example sorts by the <code class="leafygreen-ui-1l06pbn"> totalNumber </code> field. If you change the query sort from <code class="leafygreen-ui-1l06pbn"> totalNumber </code> to a different field, the query has a different query shape. </p> <p class="leafygreen-ui-1kp3ins"> For example, sorting by pizza <code class="leafygreen-ui-1l06pbn"> price </code> changes the query shape: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.pizzaOrders.explain().find(\n { orderDate: { $gt: ISODate( \"2023-01-20T00:00:00Z\" ) } } ).\n sort( { price: 1 }\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">pizzaOrders</span>.<span class="lg-highlight-title lg-highlight-function">explain</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">find</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">orderDate</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2023-01-20T00:00:00Z"</span> ) } } ).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">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> <p class="leafygreen-ui-1kp3ins"> Because the query shape is different from the shape in the previous section, the <code class="leafygreen-ui-1l06pbn"> explain </code> output has a different <code class="leafygreen-ui-1l06pbn"> queryShapeHash </code> from the previous example, and a different <code class="leafygreen-ui-1l06pbn"> planCacheShapeHash </code> . For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"queryShapeHash: 'AC1ECADBE8F1EB0F417A30741AB4813BE7E0BFEF523B0870CA11FCBC87F1A8B2'\nplanCacheShapeHash: '31A52130'","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">queryShapeHash</span>: <span class="lg-highlight-string">'AC1ECADBE8F1EB0F417A30741AB4813BE7E0BFEF523B0870CA11FCBC87F1A8B2'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">planCacheShapeHash</span>: <span class="lg-highlight-string">'31A52130'</span></td></tr></tbody></table></code></pre> </div> </div> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 8.0, add query settings for query shapes instead of <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-index-filters"> index filters </a> for collections. Index filters are deprecated starting in MongoDB 8.0. Query settings have more functionality than index filters, and index filters aren't persistent after cluster shutdown. </p> <p class="leafygreen-ui-1kp3ins"> Query settings allow you to use an index for all executions of a query shape in a cluster. Also, to prevent an operation from causing excessive cluster workload, you can reject all operations associated with a query shape using an operation rejection filter. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-query-optimizer"> query optimizer </a> uses the query settings as an additional input during query planning. The query settings affect the plan selected to run a query that has a matching query shape. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-query-shape-get-started"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Get Started <a class="headerlink leafygreen-ui-1kepx47" href="#get-started" 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="get-started"> </div> </a> </h2> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To add query settings for a query shape, use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setQuerySettings/#mongodb-dbcommand-dbcmd.setQuerySettings"> <code class="leafygreen-ui-1l06pbn"> setQuerySettings </code> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To delete query settings, use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/removeQuerySettings/#mongodb-dbcommand-dbcmd.removeQuerySettings"> <code class="leafygreen-ui-1l06pbn"> removeQuerySettings </code> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To retrieve query settings, use a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/querySettings/#mongodb-pipeline-pipe.-querySettings"> <code class="leafygreen-ui-1l06pbn"> $querySettings </code> </a> stage in an aggregation pipeline. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To block a query shape, use an <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/operation-rejection-filters/#std-label-operation-rejection-filters"> operation rejection filter <!-- --> . </a> </p> </li> </ul> </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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-query-plans-query-optimization"> Query Plans </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/queryStats/#std-label-queryStats-queryShape"> Query shape statistics </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/indexes/#std-label-indexes"> Indexes </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> Aggregation Pipeline </a> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $first (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-first--aggregation-" 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="-first--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behaviors" target="_self"> <span> Behaviors </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="group"> <dt> <code class="leafygreen-ui-1l06pbn"> $first </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-group-grp.-first" title="Permalink to this definition"> <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="mongodb-group-grp.-first"> </div> </a> </dt> <dd> </dd> </dl> <div> <p> <em> Changed <!-- --> in version <!-- --> 5.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Returns the result of an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> expression </a> for the first document in a group of documents. Only meaningful when documents are in a defined order. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-first" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $first </code> </span> </a> is available in these stages: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/bucket/#mongodb-pipeline-pipe.-bucket"> <code class="leafygreen-ui-1l06pbn"> $bucket </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/bucketAuto/#mongodb-pipeline-pipe.-bucketAuto"> <code class="leafygreen-ui-1l06pbn"> $bucketAuto </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> </a> (Available starting in MongoDB 5.0) </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $first </code> syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $first: &lt;expression&gt; }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$first</span>: &lt;<!-- -->expression<!-- -->&gt; <!-- -->}</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behaviors <a class="headerlink leafygreen-ui-1kepx47" href="#behaviors" 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="behaviors"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Defining Document Order <a class="headerlink leafygreen-ui-1kepx47" href="#defining-document-order" 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="defining-document-order"> </div> </a> </h3> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To define the document order for <code class="leafygreen-ui-1l06pbn"> $first </code> in a <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> , set the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-sortBy"> sortBy </a> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To define the document order for <code class="leafygreen-ui-1l06pbn"> $first </code> in other pipeline stages, add a preceding <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> stage. </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Array Operator <a class="headerlink leafygreen-ui-1kepx47" href="#array-operator" 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="array-operator"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If the expression resolves to an array: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For a group of documents, <code class="leafygreen-ui-1l06pbn"> $first </code> returns the entire array from the first document. It does not traverse array elements. This is the case with stages like <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For an individual document, <code class="leafygreen-ui-1l06pbn"> $first </code> returns the first element of the array. This is the case with stages like <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> . </a> </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Missing Values <a class="headerlink leafygreen-ui-1kepx47" href="#missing-values" 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="missing-values"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Documents in a group may be missing fields or may have fields with missing values. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If there are no documents from the prior pipeline stage, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage returns nothing. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the field that the <code class="leafygreen-ui-1l06pbn"> $first </code> accumulator is processing is missing, <code class="leafygreen-ui-1l06pbn"> $first </code> returns <code class="leafygreen-ui-1l06pbn"> null </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> When used with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> </a> , <code class="leafygreen-ui-1l06pbn"> $first </code> returns <code class="leafygreen-ui-1l06pbn"> null </code> for empty windows. For example, when you have a <code class="leafygreen-ui-1l06pbn"> { documents:[ -1, -1] } </code> <code class="leafygreen-ui-1l06pbn"> documents </code> window on the first document of a partition. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For more information, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-first-missing-values-example" target="_self"> <span> Missing Data </span> </a> example later in this topic. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <span class="leafygreen-ui-1qnjd6d" id="std-label-first-accumulator-group-example"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Use in <code class="leafygreen-ui-1l06pbn"> $group </code> Stage <a class="headerlink leafygreen-ui-1kepx47" href="#use-in--group-stage" 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="use-in--group-stage"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Create the <code class="leafygreen-ui-1l06pbn"> sales </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.insertMany( [\n { \"_id\" : 1, \"item\" : \"abc\", \"price\" : 10, \"quantity\" : 2, \"date\" : ISODate(\"2014-01-01T08:00:00Z\") },\n { \"_id\" : 2, \"item\" : \"jkl\", \"price\" : 20, \"quantity\" : 1, \"date\" : ISODate(\"2014-02-03T09:00:00Z\") },\n { \"_id\" : 3, \"item\" : \"xyz\", \"price\" : 5, \"quantity\" : 5, \"date\" : ISODate(\"2014-02-03T09:05:00Z\") },\n { \"_id\" : 4, \"item\" : \"abc\", \"price\" : 10, \"quantity\" : 10, \"date\" : ISODate(\"2014-02-15T08:00:00Z\") },\n { \"_id\" : 5, \"item\" : \"xyz\", \"price\" : 5, \"quantity\" : 10, \"date\" : ISODate(\"2014-02-15T09:05:00Z\") },\n { \"_id\" : 6, \"item\" : \"xyz\", \"price\" : 5, \"quantity\" : 5, \"date\" : ISODate(\"2014-02-15T12:05:10Z\") },\n { \"_id\" : 7, \"item\" : \"xyz\", \"price\" : 5, \"quantity\" : 10, \"date\" : ISODate(\"2014-02-15T14:12:12Z\") }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales</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">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-01-01T08:00:00Z"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"jkl"</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>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-02-03T09:00:00Z"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"xyz"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-02-03T09:05:00Z"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-02-15T08:00:00Z"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"xyz"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-02-15T09:05:00Z"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"xyz"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-02-15T12:05:10Z"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">7</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"xyz"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-02-15T14:12:12Z"</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> <p class="leafygreen-ui-1kp3ins"> Grouping the documents by the <code class="leafygreen-ui-1l06pbn"> item </code> field, the following operation uses the <code class="leafygreen-ui-1l06pbn"> $first </code> accumulator to return the first sales date for each item: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.aggregate(\n [\n { $sort: { item: 1, date: 1 } },\n {\n $group:\n {\n _id: \"$item\",\n firstSale: { $first: \"$date\" }\n }\n }\n ]\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">db.<span class="lg-highlight-property">sales</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</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">item</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">date</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"> <span class="lg-highlight-attr">$group</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$item"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">firstSale</span>: <!-- -->{ <span class="lg-highlight-attr">$first</span>: <span class="lg-highlight-string">"$date"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: 'jkl', firstSale: ISODate(\"2014-02-03T09:00:00.000Z\") },\n { _id: 'xyz', firstSale: ISODate(\"2014-02-03T09:05:00.000Z\") },\n { _id: 'abc', firstSale: ISODate(\"2014-01-01T08:00:00.000Z\") }\n]","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'jkl'</span>, <span class="lg-highlight-attr">firstSale</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-02-03T09:00:00.000Z"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'xyz'</span>, <span class="lg-highlight-attr">firstSale</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-02-03T09:05:00.000Z"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'abc'</span>, <span class="lg-highlight-attr">firstSale</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-01-01T08:00:00.000Z"</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-first-missing-values-example"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Missing Data <a class="headerlink leafygreen-ui-1kepx47" href="#missing-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="missing-data"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Some documents in the <code class="leafygreen-ui-1l06pbn"> badData </code> collection are missing fields, other documents are missing values. </p> <p class="leafygreen-ui-1kp3ins"> Create the <code class="leafygreen-ui-1l06pbn"> badData </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.badData.insertMany( [\n { \"_id\": 1, \"price\": 6, \"quantity\": 6 },\n { \"_id\": 2, \"item\": \"album\", \"price\": 5 , \"quantity\": 5 },\n { \"_id\": 7, \"item\": \"tape\", \"price\": 6, \"quantity\": 6 },\n { \"_id\": 8, \"price\": 5, \"quantity\": 5 },\n { \"_id\": 9, \"item\": \"album\", \"price\": 3, \"quantity\": '' },\n { \"_id\": 10, \"item\": \"tape\", \"price\": 3, \"quantity\": 4 },\n { \"_id\": 12, \"item\": \"cd\", \"price\": 7 }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">badData</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">"_id"</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"price"</span>: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span>: <span class="lg-highlight-string">"album"</span>, <span class="lg-highlight-string">"price"</span>: <span class="lg-highlight-number">5</span> <!-- -->, <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-number">5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-number">7</span>, <span class="lg-highlight-string">"item"</span>: <span class="lg-highlight-string">"tape"</span>, <span class="lg-highlight-string">"price"</span>: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-number">8</span>, <span class="lg-highlight-string">"price"</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-number">5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-number">9</span>, <span class="lg-highlight-string">"item"</span>: <span class="lg-highlight-string">"album"</span>, <span class="lg-highlight-string">"price"</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-string">''</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"item"</span>: <span class="lg-highlight-string">"tape"</span>, <span class="lg-highlight-string">"price"</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-number">12</span>, <span class="lg-highlight-string">"item"</span>: <span class="lg-highlight-string">"cd"</span>, <span class="lg-highlight-string">"price"</span>: <span class="lg-highlight-number">7</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> <p class="leafygreen-ui-1kp3ins"> Query the <code class="leafygreen-ui-1l06pbn"> badData </code> collection, grouping the output on the <code class="leafygreen-ui-1l06pbn"> item </code> field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.badData.aggregate( [\n { $sort: { item: 1, price: 1 } },\n { $group:\n {\n _id: \"$item\",\n inStock: { $first: \"$quantity\" }\n }\n }\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">db.<span class="lg-highlight-property">badData</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">$sort</span>: <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">1</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$item"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">inStock</span>: <!-- -->{ <span class="lg-highlight-attr">$first</span>: <span class="lg-highlight-string">"$quantity"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $sort </code> stage orders the documents and passes them to the <code class="leafygreen-ui-1l06pbn"> $group </code> stage. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: null, inStock: 5 },\n { _id: 'album', inStock: '' },\n { _id: 'cd', inStock: null },\n { _id: 'tape', inStock: 4 }\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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-attr">inStock</span>: <span class="lg-highlight-number">5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'album'</span>, <span class="lg-highlight-attr">inStock</span>: <span class="lg-highlight-string">''</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'cd'</span>, <span class="lg-highlight-attr">inStock</span>: <span class="lg-highlight-literal">null</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'tape'</span>, <span class="lg-highlight-attr">inStock</span>: <span class="lg-highlight-number">4</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> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $first </code> selects the first document from each output group: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> _id: null </code> group is included. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> When the accumulator field, <code class="leafygreen-ui-1l06pbn"> $quantity </code> in this example, is missing, <code class="leafygreen-ui-1l06pbn"> $first </code> returns <code class="leafygreen-ui-1l06pbn"> null </code> . </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-first-accumulator-window-example"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Use in <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> Stage <a class="headerlink leafygreen-ui-1kepx47" href="#use-in--setwindowfields-stage" 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="use-in--setwindowfields-stage"> </div> </a> </h3> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Create a <code class="leafygreen-ui-1l06pbn"> cakeSales </code> collection that contains cake sales in the states of California ( <code class="leafygreen-ui-1l06pbn"> CA </code> ) and Washington ( <code class="leafygreen-ui-1l06pbn"> WA </code> ): </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeSales.insertMany( [\n { _id: 0, type: \"chocolate\", orderDate: new Date(\"2020-05-18T14:10:30Z\"),\n state: \"CA\", price: 13, quantity: 120 },\n { _id: 1, type: \"chocolate\", orderDate: new Date(\"2021-03-20T11:30:05Z\"),\n state: \"WA\", price: 14, quantity: 140 },\n { _id: 2, type: \"vanilla\", orderDate: new Date(\"2021-01-11T06:31:15Z\"),\n state: \"CA\", price: 12, quantity: 145 },\n { _id: 3, type: \"vanilla\", orderDate: new Date(\"2020-02-08T13:13:23Z\"),\n state: \"WA\", price: 13, quantity: 104 },\n { _id: 4, type: \"strawberry\", orderDate: new Date(\"2019-05-18T16:09:01Z\"),\n state: \"CA\", price: 41, quantity: 162 },\n { _id: 5, type: \"strawberry\", orderDate: new Date(\"2019-01-08T06:12:03Z\"),\n state: \"WA\", price: 43, quantity: 134 }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">cakeSales</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-05-18T14:10:30Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">120</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2021-03-20T11:30:05Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">14</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">140</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2021-01-11T06:31:15Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">12</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">145</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-02-08T13:13:23Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">104</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2019-05-18T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">41</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">162</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2019-01-08T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">43</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">134</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> <p class="leafygreen-ui-1kp3ins"> This example uses <code class="leafygreen-ui-1l06pbn"> $first </code> in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> </a> stage to output the first cake sales order <code class="leafygreen-ui-1l06pbn"> type </code> for each <code class="leafygreen-ui-1l06pbn"> state </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeSales.aggregate( [\n {\n $setWindowFields: {\n partitionBy: \"$state\",\n sortBy: { orderDate: 1 },\n output: {\n firstOrderTypeForState: {\n $first: \"$type\",\n window: {\n documents: [ \"unbounded\", \"current\" ]\n }\n }\n }\n }\n }\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">db.<span class="lg-highlight-property">cakeSales</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$setWindowFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">partitionBy</span>: <span class="lg-highlight-string">"$state"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sortBy</span>: <!-- -->{ <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">output</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">firstOrderTypeForState</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$first</span>: <span class="lg-highlight-string">"$type"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">window</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">documents</span>: <!-- -->[ <span class="lg-highlight-string">"unbounded"</span>, <span class="lg-highlight-string">"current"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> In the example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> partitionBy: "$state" </code> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-partitionBy"> partitions </a> the documents in the collection by <code class="leafygreen-ui-1l06pbn"> state </code> . There are partitions for <code class="leafygreen-ui-1l06pbn"> CA </code> and <code class="leafygreen-ui-1l06pbn"> WA </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> sortBy: { orderDate: 1 } </code> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-sortBy"> sorts </a> the documents in each partition by <code class="leafygreen-ui-1l06pbn"> orderDate </code> in ascending order ( <code class="leafygreen-ui-1l06pbn"> 1 </code> ), so the earliest <code class="leafygreen-ui-1l06pbn"> orderDate </code> is first. </p> </li> </ul> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> output </code> sets the <code class="leafygreen-ui-1l06pbn"> firstOrderTypeForState </code> field to the first order <code class="leafygreen-ui-1l06pbn"> type </code> from the <code class="leafygreen-ui-1l06pbn"> documents </code> window. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> window </code> contains documents between an <code class="leafygreen-ui-1l06pbn"> unbounded </code> lower limit and the <code class="leafygreen-ui-1l06pbn"> current </code> document in the output. This means <code class="leafygreen-ui-1l06pbn"> $first </code> returns the first order <code class="leafygreen-ui-1l06pbn"> type </code> for the documents between the beginning of the partition and the current document. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> In this output, the first order <code class="leafygreen-ui-1l06pbn"> type </code> value for <code class="leafygreen-ui-1l06pbn"> CA </code> and <code class="leafygreen-ui-1l06pbn"> WA </code> is shown in the <code class="leafygreen-ui-1l06pbn"> firstOrderTypeForState </code> field: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 4, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2019-05-18T16:09:01Z\"),\n \"state\" : \"CA\", \"price\" : 41, \"quantity\" : 162, \"firstOrderTypeForState\" : \"strawberry\" }\n{ \"_id\" : 0, \"type\" : \"chocolate\", \"orderDate\" : ISODate(\"2020-05-18T14:10:30Z\"),\n \"state\" : \"CA\", \"price\" : 13, \"quantity\" : 120, \"firstOrderTypeForState\" : \"strawberry\" }\n{ \"_id\" : 2, \"type\" : \"vanilla\", \"orderDate\" : ISODate(\"2021-01-11T06:31:15Z\"),\n \"state\" : \"CA\", \"price\" : 12, \"quantity\" : 145, \"firstOrderTypeForState\" : \"strawberry\" }\n{ \"_id\" : 5, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2019-01-08T06:12:03Z\"),\n \"state\" : \"WA\", \"price\" : 43, \"quantity\" : 134, \"firstOrderTypeForState\" : \"strawberry\" }\n{ \"_id\" : 3, \"type\" : \"vanilla\", \"orderDate\" : ISODate(\"2020-02-08T13:13:23Z\"),\n \"state\" : \"WA\", \"price\" : 13, \"quantity\" : 104, \"firstOrderTypeForState\" : \"strawberry\" }\n{ \"_id\" : 1, \"type\" : \"chocolate\", \"orderDate\" : ISODate(\"2021-03-20T11:30:05Z\"),\n \"state\" : \"WA\", \"price\" : 14, \"quantity\" : 140, \"firstOrderTypeForState\" : \"strawberry\" }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-05-18T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">41</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">162</span>, <span class="lg-highlight-string">"firstOrderTypeForState"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-05-18T14:10:30Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">120</span>, <span class="lg-highlight-string">"firstOrderTypeForState"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-01-11T06:31:15Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</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">145</span>, <span class="lg-highlight-string">"firstOrderTypeForState"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-01-08T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">43</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">134</span>, <span class="lg-highlight-string">"firstOrderTypeForState"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-02-08T13:13:23Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">104</span>, <span class="lg-highlight-string">"firstOrderTypeForState"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-20T11:30:05Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">14</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">140</span>, <span class="lg-highlight-string">"firstOrderTypeForState"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/setClusterParameter/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> setClusterParameter <a class="headerlink leafygreen-ui-1kepx47" href="#setclusterparameter" 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="setclusterparameter"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="dbcommand"> <dt> <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.setClusterParameter" title="Permalink to this definition"> <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="mongodb-dbcommand-dbcmd.setClusterParameter"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.setClusterParameter" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> </span> </a> is an administrative command for modifying values of <strong> cluster parameters </strong> . Cluster parameters are configurable parameters which affect all nodes in a replica set or sharded cluster. </p> <p class="leafygreen-ui-1kp3ins"> You must issue the <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> command against the <code class="leafygreen-ui-1l06pbn"> admin </code> database. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This command is available in deployments hosted 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> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self"> <span> Unsupported Commands <!-- --> . </span> </a> </p> </div> </div> <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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n setClusterParameter: { &lt;parameter&gt;: &lt;value&gt; }\n }\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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">setClusterParameter</span>: <!-- -->{ &lt;<!-- -->parameter<!-- -->&gt;<!-- -->: &lt;<!-- -->value<!-- -->&gt; <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> For the available cluster parameters, including examples, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/cluster-parameters/#std-label-cluster-parameters"> Cluster Parameters for a Self-Managed Deployment <!-- --> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You can only run <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> on the <code class="leafygreen-ui-1l06pbn"> admin </code> database. If you run the command on any other database, MongoDB returns an error. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You can only run <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> on a replica set primary or on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You <strong> cannot </strong> run <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> on a standalone deployment. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> accepts only one parameter at a time. </p> </li> </ul> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Accesss Control <a class="headerlink leafygreen-ui-1kepx47" href="#accesss-control" 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="accesss-control"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> When <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication"> authentication </a> is enabled, <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> only works when authenticated as a user with a role that has access to the <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> action. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Persistence <a class="headerlink leafygreen-ui-1kepx47" href="#persistence" 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="persistence"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The parameter modifications made using <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> are persisted on replica sets and sharded clusters. This ensures that parameter modifications made using <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> survive restarts. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Stable API <a class="headerlink leafygreen-ui-1kepx47" href="#stable-api" 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="stable-api"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> When using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/stable-api/#std-label-stable-api"> Stable API </a> V1 with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/stable-api/#std-label-api-strict-desc"> apiStrict </a> set to <code class="leafygreen-ui-1l06pbn"> true </code> , you cannot use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.setClusterParameter" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> setClusterParameter </code> </span> </a> to modify cluster parameters. </p> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/dropDatabase/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> dropDatabase <a class="headerlink leafygreen-ui-1kepx47" href="#dropdatabase" 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="dropdatabase"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self"> <span> Command Fields </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="dbcommand"> <dt> <code class="leafygreen-ui-1l06pbn"> dropDatabase </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.dropDatabase" title="Permalink to this definition"> <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="mongodb-dbcommand-dbcmd.dropDatabase"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dropDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dropDatabase </code> </span> </a> command drops the current database, deleting the associated data files. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This command is available in deployments hosted 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> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self"> <span> Unsupported Commands <!-- --> . </span> </a> </p> </div> </div> <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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n dropDatabase: 1,\n writeConcern: &lt;document&gt;,\n comment: &lt;any&gt;\n }\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">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dropDatabase</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">writeConcern</span>: &lt;<span class="lg-highlight-variable lg-highlight-language">document</span>&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: &lt;<!-- -->any<!-- -->&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Command Fields <a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" 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="command-fields"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command takes the following optional fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> writeConcern </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A document expressing the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/"> write concern </a> to use if greater than <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ w: &lt;value&gt;, j: &lt;boolean&gt;, wtimeout: &lt;number&gt; }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">w</span>: &lt;<!-- -->value<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">j</span>: &lt;<!-- -->boolean<!-- -->&gt;<!-- -->,<!-- --> <span class="lg-highlight-attr">wtimeout</span>: &lt;<!-- -->number<!-- -->&gt; <!-- -->}</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"> Omit to use the default/minimum write concern of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> When issued on a replica set, if the specified write concern results in fewer member acknowledgments than write concern <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> , the operation uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> . Otherwise, the specified write concern is used. </p> <p class="leafygreen-ui-1kp3ins"> When issued on a sharded cluster, MongoDB converts the specified <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern"> write concern </a> to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> See also <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-dropDatabase-wc" target="_self"> <span> Behavior <!-- --> . </span> </a> </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> comment </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref"> mongod log messages </a> , in the <code class="leafygreen-ui-1l06pbn"> attr.command.cursor.comment </code> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler"> Database profiler </a> output, in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#mongodb-data-system.profile.command"> <code class="leafygreen-ui-1l06pbn"> command.comment </code> </a> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp"> <code class="leafygreen-ui-1l06pbn"> currentOp </code> </a> output, in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.command"> <code class="leafygreen-ui-1l06pbn"> command.comment </code> </a> field. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> A comment can be any valid <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types"> BSON type </a> (string, integer, object, array, etc). </p> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> <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> also provides the helper method <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.dropDatabase/#mongodb-method-db.dropDatabase"> <code class="leafygreen-ui-1l06pbn"> db.dropDatabase() </code> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Locks <a class="headerlink leafygreen-ui-1kepx47" href="#locks" 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="locks"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The operation takes an exclusive (X) database lock only. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> User Management <a class="headerlink leafygreen-ui-1kepx47" href="#user-management" 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="user-management"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> This command does not delete the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-users/#std-label-authentication-client-users"> users </a> associated with the current database. To drop the associated users, run the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/dropAllUsersFromDatabase/#mongodb-dbcommand-dbcmd.dropAllUsersFromDatabase"> <code class="leafygreen-ui-1l06pbn"> dropAllUsersFromDatabase </code> </a> command in the database you are deleting. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Indexes <a class="headerlink leafygreen-ui-1kepx47" href="#indexes" 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="indexes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.dropDatabase/#mongodb-method-db.dropDatabase"> <code class="leafygreen-ui-1l06pbn"> db.dropDatabase() </code> </a> method and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dropDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dropDatabase </code> </span> </a> command abort any in-progress index builds on collections in the target database before dropping the database. Aborting an index build has the same effect as dropping the built index. </p> <p class="leafygreen-ui-1kp3ins"> For replica sets or shard replica sets, aborting an index on the primary does not simultaneously abort secondary index builds. MongoDB attempts to abort the in-progress builds for the specified indexes on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary"> primary </a> and if successful creates an associated <code class="leafygreen-ui-1l06pbn"> abort </code> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> entry. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary"> Secondary </a> members with replicated in-progress builds wait for a commit or abort oplog entry from the primary before either committing or aborting the index build. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-dropDatabase-wc"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Replica Set and Sharded Clusters <a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-and-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="replica-set-and-sharded-clusters"> </div> </a> </h3> <dl> <dt> Replica Sets </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> At minimum, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dropDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dropDatabase </code> </span> </a> waits until all collections drops in the database have propagated to a majority of the replica set members (i.e. uses the write concern <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> ). </p> <p class="leafygreen-ui-1kp3ins"> If you specify a write concern that requires acknowledgment from fewer than the majority, the command uses write concern <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> If you specify a write concern that requires acknowledgment from more than the majority, the command uses the specified write concern. </p> </dd> <dt> Sharded Clusters </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> When issued on a sharded cluster, MongoDB converts the specified <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern"> write concern </a> to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> If you intend to create a new database with the same name as the dropped database, you must run the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dropDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dropDatabase </code> </span> </a> command on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> This ensures that all cluster nodes refresh their metadata cache, which includes the location of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-shards/#std-label-primary-shard"> primary shard </a> for the new database. Otherwise, you may miss data on reads, and may not write data to the correct shard. To recover, you must manually intervene. </p> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dropDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dropDatabase </code> </span> </a> command and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.dropDatabase/#mongodb-method-db.dropDatabase"> <code class="leafygreen-ui-1l06pbn"> db.dropDatabase() </code> </a> method return an error if you try to drop the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-admin-database"> admin database </a> or the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-config-database"> config database </a> from a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> . </a> </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Dropping the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-admin-database"> admin database </a> or the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-config-database"> config database </a> can leave your cluster in an unusable state. </p> </div> </div> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" 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> </h3> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.dropDatabase/#mongodb-method-db.dropDatabase"> <code class="leafygreen-ui-1l06pbn"> db.dropDatabase() </code> </a> method and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dropDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dropDatabase </code> </span> </a> create an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/change-events/invalidate/#std-label-change-event-invalidate"> invalidate </a> for any <a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/"> Change Streams </a> opened on the dropped database or opened on the collections in the dropped database. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following example in <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> uses the <code class="leafygreen-ui-1l06pbn"> use &lt;database&gt; </code> operation to switch the current database to the <code class="leafygreen-ui-1l06pbn"> temp </code> database and then uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dropDatabase" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> dropDatabase </code> </span> </a> command to drop the <code class="leafygreen-ui-1l06pbn"> temp </code> database: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use temp\ndb.runCommand( { dropDatabase: 1 } )","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">use temp</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>( <!-- -->{ <span class="lg-highlight-attr">dropDatabase</span>: <span class="lg-highlight-number">1</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 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/reference/command/dropAllUsersFromDatabase/#mongodb-dbcommand-dbcmd.dropAllUsersFromDatabase"> <code class="leafygreen-ui-1l06pbn"> dropAllUsersFromDatabase </code> </a> </p> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $linearFill (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-linearfill--aggregation-" 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="-linearfill--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#restrictions" target="_self"> <span> Restrictions </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="group"> <dt> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-group-grp.-linearFill" title="Permalink to this definition"> <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="mongodb-group-grp.-linearFill"> </div> </a> </dt> <dd> <div> <p> <em> New <!-- --> in version <!-- --> 5.3 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Fills <code class="leafygreen-ui-1l06pbn"> null </code> and missing fields in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-window"> window </a> using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Linear_interpolation" rel="noopener noreferrer"> <span> linear interpolation </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> based on surrounding field values. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> is only available in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> </a> stage. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> expression has this syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $linearFill: &lt;expression&gt; }"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ $linearFill: &lt;expression&gt; }</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"> For more information on expressions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> Expression Operators <!-- --> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> fills <code class="leafygreen-ui-1l06pbn"> null </code> and missing fields using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Linear_interpolation" rel="noopener noreferrer"> <span> linear interpolation </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> based on surrounding non- <code class="leafygreen-ui-1l06pbn"> null </code> field values. The surrounding field values are determined by the sort order specified in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> . </a> </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="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> fills <code class="leafygreen-ui-1l06pbn"> null </code> and missing values proportionally spanning the value range between surrounding non- <code class="leafygreen-ui-1l06pbn"> null </code> values. To determine the values for missing fields, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> uses: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The difference of surrounding non- <code class="leafygreen-ui-1l06pbn"> null </code> values. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The number of <code class="leafygreen-ui-1l06pbn"> null </code> fields to fill between the surrounding values. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> can fill multiple consecutive <code class="leafygreen-ui-1l06pbn"> null </code> values if those values are preceded and followed by non- <code class="leafygreen-ui-1l06pbn"> null </code> values according to the sort order specified in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> . </a> </p> <div class="leafygreen-ui-vg7qwp" role="note"> <h2 class="leafygreen-ui-2xicti"> Example </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> If a collection contains these documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ index: 0, value: 0 },\n{ index: 1, value: null },\n{ index: 2, value: null },\n{ index: 3, value: null },\n{ index: 4, value: 10 }","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">{ <span class="lg-highlight-attr">index</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">index</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-literal">null</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">index</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-literal">null</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">index</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-literal">null</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">index</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">10</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> <p class="leafygreen-ui-1kp3ins"> After using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> to fill the <code class="leafygreen-ui-1l06pbn"> null </code> values, the documents become: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ index: 0, value: 0 },\n{ index: 1, value: 2.5 },\n{ index: 2, value: 5 },\n{ index: 3, value: 7.5 },\n{ index: 4, value: 10 }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{ <span class="lg-highlight-attr">index</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">index</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">2.5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">index</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">index</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">7.5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">index</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">10</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> For a complete example, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-linearFill-example" target="_self"> <span> Examples <!-- --> . </span> </a> </p> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> null </code> values that are not preceded and followed by non- <code class="leafygreen-ui-1l06pbn"> null </code> values remain <code class="leafygreen-ui-1l06pbn"> null </code> . </p> </li> </ul> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Comparison of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/fill/#mongodb-pipeline-pipe.-fill"> <code class="leafygreen-ui-1l06pbn"> $fill </code> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> <a class="headerlink leafygreen-ui-1kepx47" href="#comparison-of--and" 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="comparison-of--and"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To fill missing field values using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Linear_interpolation" rel="noopener noreferrer"> <span> linear interpolation </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> , you can use: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/fill/#mongodb-pipeline-pipe.-fill"> <code class="leafygreen-ui-1l06pbn"> $fill </code> </a> stage with <code class="leafygreen-ui-1l06pbn"> { method: "linear" } </code> . </p> <p class="leafygreen-ui-1kp3ins"> When you use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/fill/#mongodb-pipeline-pipe.-fill"> <code class="leafygreen-ui-1l06pbn"> $fill </code> </a> stage, the field you specify in the output is the same field used as the source data. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/fill/#std-label-fill-example-linear"> Fill Missing Field Values with Linear Interpolation <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> operator inside of a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> </a> stage. </p> <p class="leafygreen-ui-1kp3ins"> When you use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> operator, you can set values for a different field than the field used as the source data. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-linearFill-example-multiple-methods" target="_self"> <span> Use Multiple Fill Methods in a Single Stage <!-- --> . </span> </a> </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-linearFill-example"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The examples on this page use a <code class="leafygreen-ui-1l06pbn"> stock </code> collection that contains tracks a single company's stock price at hourly intervals: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.stock.insertMany( [\n {\n time: ISODate(\"2021-03-08T09:00:00.000Z\"),\n price: 500\n },\n {\n time: ISODate(\"2021-03-08T10:00:00.000Z\"),\n },\n {\n time: ISODate(\"2021-03-08T11:00:00.000Z\"),\n price: 515\n },\n {\n time: ISODate(\"2021-03-08T12:00:00.000Z\")\n },\n {\n time: ISODate(\"2021-03-08T13:00:00.000Z\")\n },\n {\n time: ISODate(\"2021-03-08T14:00:00.000Z\"),\n price: 485\n }\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">db.<span class="lg-highlight-property">stock</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T09:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">500</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T10:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T11:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">515</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T12:00:00.000Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T13:00:00.000Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T14:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">485</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> price </code> field is missing for some of the documents in the collection. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Fill Missing Values with Linear Interpolation <a class="headerlink leafygreen-ui-1kepx47" href="#fill-missing-values-with-linear-interpolation" 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="fill-missing-values-with-linear-interpolation"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To populate the missing <code class="leafygreen-ui-1l06pbn"> price </code> values using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Linear_interpolation" rel="noopener noreferrer"> <span> linear interpolation </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> , use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> inside of a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> </a> stage: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.stock.aggregate( [\n {\n $setWindowFields:\n {\n sortBy: { time: 1 },\n output:\n {\n price: { $linearFill: \"$price\" }\n }\n }\n }\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">db.<span class="lg-highlight-property">stock</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$setWindowFields</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sortBy</span>: <!-- -->{ <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">output</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <!-- -->{ <span class="lg-highlight-attr">$linearFill</span>: <span class="lg-highlight-string">"$price"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> In the example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> sortBy: { time: 1 } </code> sorts the documents by the <code class="leafygreen-ui-1l06pbn"> time </code> field in ascending order, from earliest to latest. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-output"> output </a> specifies: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> price </code> as the field for which to fill in missing values. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { $linearFill: "$price" } </code> as the value for the missing field. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> fills missing <code class="leafygreen-ui-1l06pbn"> price </code> values using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Linear_interpolation" rel="noopener noreferrer"> <span> linear interpolation </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> based on the surrounding <code class="leafygreen-ui-1l06pbn"> price </code> values in the sequence. </p> </li> </ul> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Example output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: ObjectId(\"620ad555394d47411658b5ef\"),\n time: ISODate(\"2021-03-08T09:00:00.000Z\"),\n price: 500\n },\n {\n _id: ObjectId(\"620ad555394d47411658b5f0\"),\n time: ISODate(\"2021-03-08T10:00:00.000Z\"),\n price: 507.5\n },\n {\n _id: ObjectId(\"620ad555394d47411658b5f1\"),\n time: ISODate(\"2021-03-08T11:00:00.000Z\"),\n price: 515\n },\n {\n _id: ObjectId(\"620ad555394d47411658b5f2\"),\n time: ISODate(\"2021-03-08T12:00:00.000Z\"),\n price: 505\n },\n {\n _id: ObjectId(\"620ad555394d47411658b5f3\"),\n time: ISODate(\"2021-03-08T13:00:00.000Z\"),\n price: 495\n },\n {\n _id: ObjectId(\"620ad555394d47411658b5f4\"),\n time: ISODate(\"2021-03-08T14:00:00.000Z\"),\n price: 485\n }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5ef"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T09:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">500</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5f0"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T10:00:00.000Z"</span>)<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">507.5</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5f1"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T11:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">515</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5f2"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T12:00:00.000Z"</span>)<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">505</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5f3"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T13:00:00.000Z"</span>)<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">495</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5f4"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T14:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">485</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-linearFill-example-multiple-methods"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Use Multiple Fill Methods in a Single Stage <a class="headerlink leafygreen-ui-1kepx47" href="#use-multiple-fill-methods-in-a-single-stage" 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="use-multiple-fill-methods-in-a-single-stage"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> When you use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> </a> stage to fill missing values, you can set values for a different field than the field you fill from. As a result, you can use multiple fill methods in a single <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> </a> stage and output the results in distinct fields. </p> <p class="leafygreen-ui-1kp3ins"> The following pipeline populates missing <code class="leafygreen-ui-1l06pbn"> price </code> fields using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Linear_interpolation" rel="noopener noreferrer"> <span> linear interpolation </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> and the last-observation-carried-forward method: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.stock.aggregate( [\n {\n $setWindowFields:\n {\n sortBy: { time: 1 },\n output:\n {\n linearFillPrice: { $linearFill: \"$price\" },\n locfPrice: { $locf: \"$price\" }\n }\n }\n }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">stock</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$setWindowFields</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sortBy</span>: <!-- -->{ <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">output</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">linearFillPrice</span>: <!-- -->{ <span class="lg-highlight-attr">$linearFill</span>: <span class="lg-highlight-string">"$price"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">locfPrice</span>: <!-- -->{ <span class="lg-highlight-attr">$locf</span>: <span class="lg-highlight-string">"$price"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> In the example: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> sortBy: { time: 1 } </code> sorts the documents by the <code class="leafygreen-ui-1l06pbn"> time </code> field in ascending order, from earliest to latest. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-output"> output </a> specifies: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> linearFillPrice </code> as a target field to be filled. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { $linearFill: "$price" } </code> is the value for the <code class="leafygreen-ui-1l06pbn"> linearFillPrice </code> field. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> fills missing <code class="leafygreen-ui-1l06pbn"> price </code> values using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Linear_interpolation" rel="noopener noreferrer"> <span> linear interpolation </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> based on the surrounding <code class="leafygreen-ui-1l06pbn"> price </code> values in the sequence. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> locfPrice </code> as a target field to be filled. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> { $locf: "$price" } </code> is the value for the <code class="leafygreen-ui-1l06pbn"> locfPrice </code> field. <code class="leafygreen-ui-1l06pbn"> locf </code> stands for last observation carried forward. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/locf/#mongodb-group-grp.-locf"> <code class="leafygreen-ui-1l06pbn"> $locf </code> </a> fills missing <code class="leafygreen-ui-1l06pbn"> price </code> values with the value from the previous document in the sequence. </p> </li> </ul> </li> </ul> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Example output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: ObjectId(\"620ad555394d47411658b5ef\"),\n time: ISODate(\"2021-03-08T09:00:00.000Z\"),\n price: 500,\n linearFillPrice: 500,\n locfPrice: 500\n },\n {\n _id: ObjectId(\"620ad555394d47411658b5f0\"),\n time: ISODate(\"2021-03-08T10:00:00.000Z\"),\n linearFillPrice: 507.5,\n locfPrice: 500\n },\n {\n _id: ObjectId(\"620ad555394d47411658b5f1\"),\n time: ISODate(\"2021-03-08T11:00:00.000Z\"),\n price: 515,\n linearFillPrice: 515,\n locfPrice: 515\n },\n {\n _id: ObjectId(\"620ad555394d47411658b5f2\"),\n time: ISODate(\"2021-03-08T12:00:00.000Z\"),\n linearFillPrice: 505,\n locfPrice: 515\n },\n {\n _id: ObjectId(\"620ad555394d47411658b5f3\"),\n time: ISODate(\"2021-03-08T13:00:00.000Z\"),\n linearFillPrice: 495,\n locfPrice: 515\n },\n {\n _id: ObjectId(\"620ad555394d47411658b5f4\"),\n time: ISODate(\"2021-03-08T14:00:00.000Z\"),\n price: 485,\n linearFillPrice: 485,\n locfPrice: 485\n }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5ef"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T09:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">500</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">linearFillPrice</span>: <span class="lg-highlight-number">500</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">locfPrice</span>: <span class="lg-highlight-number">500</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5f0"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T10:00:00.000Z"</span>)<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">linearFillPrice</span>: <span class="lg-highlight-number">507.5</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">locfPrice</span>: <span class="lg-highlight-number">500</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5f1"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T11:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">515</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">linearFillPrice</span>: <span class="lg-highlight-number">515</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">locfPrice</span>: <span class="lg-highlight-number">515</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5f2"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T12:00:00.000Z"</span>)<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">linearFillPrice</span>: <span class="lg-highlight-number">505</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">locfPrice</span>: <span class="lg-highlight-number">515</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5f3"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T13:00:00.000Z"</span>)<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">linearFillPrice</span>: <span class="lg-highlight-number">495</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">locfPrice</span>: <span class="lg-highlight-number">515</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"620ad555394d47411658b5f4"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-08T14:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">485</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">linearFillPrice</span>: <span class="lg-highlight-number">485</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">locfPrice</span>: <span class="lg-highlight-number">485</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Restrictions <a class="headerlink leafygreen-ui-1kepx47" href="#restrictions" 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="restrictions"> </div> </a> </h2> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> , you must use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-sortBy"> sortBy </a> field to sort your data. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> When using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-linearFill" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $linearFill </code> </span> </a> window function, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> </a> returns an error if there are any repeated values in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-sortBy"> sortBy </a> field in a single <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-partitionBy"> partition <!-- --> . </a> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $sample (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-sample--aggregation-" 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="-sample--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="pipeline"> <dt> <code class="leafygreen-ui-1l06pbn"> $sample </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-pipeline-pipe.-sample" title="Permalink to this definition"> <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="mongodb-pipeline-pipe.-sample"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Randomly selects the specified number of documents from the input documents. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-sample" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $sample </code> </span> </a> stage syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $sample: { size: &lt;positive&gt; } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$sample</span>: <!-- -->{ <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-tag lg-highlight-xml">&lt;</span><span class="lg-highlight-name lg-highlight-tag lg-highlight-xml">positive</span><span class="lg-highlight-tag lg-highlight-xml"> </span><span class="lg-highlight-attr lg-highlight-tag lg-highlight-xml">integer</span><span class="lg-highlight-tag lg-highlight-xml"> </span><span class="lg-highlight-attr lg-highlight-tag lg-highlight-xml">N</span><span class="lg-highlight-tag lg-highlight-xml">&gt;</span><span class="lg-highlight-xml"> } }</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> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> N </code> is the number of documents to randomly select. Set <code class="leafygreen-ui-1l06pbn"> N </code> to an integer greater than or equal to <code class="leafygreen-ui-1l06pbn"> 1 </code> . </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> If all of the following conditions are true, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-sample" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $sample </code> </span> </a> uses a pseudo-random cursor to select the <code class="leafygreen-ui-1l06pbn"> N </code> documents: </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="#mongodb-pipeline-pipe.-sample" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $sample </code> </span> </a> is the first stage of the pipeline. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> N </code> is less than 5% of the total documents in 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"> You can't configure the threshold that <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-sample" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $sample </code> </span> </a> uses to determine when to scan the entire collection. The thresholds is 5%. If the size is greater than 5% of the total number of documents in the collection, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-sample" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $sample </code> </span> </a> performs a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#std-label-sort-limit-results"> top-k </a> sort by a generated random value. The top-k sort could spill to disk if the sample documents are larger than 100MB. </p> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The collection contains more than 100 documents. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> If any of the previous conditions are false, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-sample" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $sample </code> : </span> </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Reads all documents that are output from a preceding aggregation stage or a collection scan. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Performs a random sort to select <code class="leafygreen-ui-1l06pbn"> N </code> documents. Random sorts are subject to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#std-label-sort-memory-limit"> sort memory restrictions <!-- --> . </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"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page"> Views </a> are the result of aggregation pipelines. When you use <code class="leafygreen-ui-1l06pbn"> $sample </code> on a view, MongoDB appends the stage to the end of the view's aggregation pipeline syntax. Therefore, the <code class="leafygreen-ui-1l06pbn"> $sample </code> stage on a view is never the first stage and always results in a collection scan. </p> </div> </div> </li> </ul> <p class="leafygreen-ui-1kp3ins"> If you use <code class="leafygreen-ui-1l06pbn"> $sample </code> in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster </a> , each shard performs the sample operation independently. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> samples the merged result of each shard's sample operation and returns the requested number of documents. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This section shows an aggregation pipeline example that uses the following <code class="leafygreen-ui-1l06pbn"> users </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.users.insertMany( [\n { _id : 1, name : \"dave123\", q1 : true, q2 : true },\n { _id : 2, name : \"dave2\", q1 : false, q2 : false },\n { _id : 3, name : \"ahn\", q1 : true, q2 : true },\n { _id : 4, name : \"li\", q1 : true, q2 : false },\n { _id : 5, name : \"annT\", q1 : false, q2 : true },\n { _id : 6, name : \"li\", q1 : true, q2 : true },\n { _id : 7, name : \"ty\", q1 : false, q2 : true }\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">db.<span class="lg-highlight-property">users</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">1</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"dave123"</span>, <!-- -->q1 <!-- -->: <span class="lg-highlight-literal">true</span>, <!-- -->q2 <!-- -->: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">2</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"dave2"</span>, <!-- -->q1 <!-- -->: <span class="lg-highlight-literal">false</span>, <!-- -->q2 <!-- -->: <span class="lg-highlight-literal">false</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">3</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"ahn"</span>, <!-- -->q1 <!-- -->: <span class="lg-highlight-literal">true</span>, <!-- -->q2 <!-- -->: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">4</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"li"</span>, <!-- -->q1 <!-- -->: <span class="lg-highlight-literal">true</span>, <!-- -->q2 <!-- -->: <span class="lg-highlight-literal">false</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">5</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"annT"</span>, <!-- -->q1 <!-- -->: <span class="lg-highlight-literal">false</span>, <!-- -->q2 <!-- -->: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">6</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"li"</span>, <!-- -->q1 <!-- -->: <span class="lg-highlight-literal">true</span>, <!-- -->q2 <!-- -->: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">7</span>, <!-- -->name <!-- -->: <span class="lg-highlight-string">"ty"</span>, <!-- -->q1 <!-- -->: <span class="lg-highlight-literal">false</span>, <!-- -->q2 <!-- -->: <span class="lg-highlight-literal">true</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation randomly selects <code class="leafygreen-ui-1l06pbn"> 3 </code> documents from the collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.users.aggregate(\n [ { $sample: { size: 3 } } ]\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">db.<span class="lg-highlight-property">users</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">$sample</span>: <!-- -->{ <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-number">3</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> <p class="leafygreen-ui-1kp3ins"> The operation returns three random documents. </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/reference/operator/aggregation/rand/#mongodb-expression-exp.-rand"> <code class="leafygreen-ui-1l06pbn"> $rand (aggregation) </code> </a> </p> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/cursor.tailable/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> cursor.tailable() <a class="headerlink leafygreen-ui-1kepx47" href="#cursor.tailable--" 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="cursor.tailable--"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> cursor.tailable() </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-cursor.tailable" title="Permalink to this definition"> <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="mongodb-method-cursor.tailable"> </div> </a> </dt> <dd> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> mongosh Method </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This page documents a <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> method. This is <em> not </em> the documentation for a language-specific driver, such as Node.js. </p> <p class="leafygreen-ui-1kp3ins"> For MongoDB API drivers, refer to the language-specific <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> MongoDB driver documentation <!-- --> . </span> </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Marks the cursor as <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/tailable-cursors/#std-label-tailable-cursors-landing-page"> tailable </a> keeping it open even when the client exhausts all results. </p> <p class="leafygreen-ui-1kp3ins"> For use against a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/capped-collections/#std-label-manual-capped-collection"> capped collection </a> only. Using <code class="leafygreen-ui-1l06pbn"> ~cursor.tailable() </code> against a non-capped collection returns an error. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.tailable" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> cursor.tailable() </code> </span> </a> uses the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"cursor.tailable( { awaitData : &lt;boolean&gt; } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">cursor.<span class="lg-highlight-title lg-highlight-function">tailable</span>( <!-- -->{ <!-- -->awaitData <!-- -->: &lt;<!-- -->boolean<!-- -->&gt; <!-- -->} )</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"> <code class="leafygreen-ui-1l06pbn"> ~cursor.tailable() </code> has the following parameter: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Parameter </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> awaitData </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> boolean </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Optional. For use with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.addOption/#mongodb-data-DBQuery.Option.tailable"> <code class="leafygreen-ui-1l06pbn"> DBQuery.Option.tailable </code> </a> . Sets the cursor to block the query thread when no data is available and await data for a set time instead of immediately returning no data. The cursor returns no data only if the timeout expires. </p> <p class="leafygreen-ui-1kp3ins"> By default, if <code class="leafygreen-ui-1l06pbn"> maxTimeMS </code> is set on the command that created the cursor, then the timeout for <code class="leafygreen-ui-1l06pbn"> awaitData </code> is the remaining time. Otherwise, the default timeout is 1000 milliseconds. </p> <p class="leafygreen-ui-1kp3ins"> You can set a timeout when running <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getMore/#mongodb-dbcommand-dbcmd.getMore"> <code class="leafygreen-ui-1l06pbn"> getMore </code> </a> on a cursor with <code class="leafygreen-ui-1l06pbn"> awaitData </code> enabled. </p> <p class="leafygreen-ui-1kp3ins"> Defaults to <code class="leafygreen-ui-1l06pbn"> false </code> . </p> </div> </div> </td> </tr> </tbody> </table> </div> <table class="css-11h39yh e1nex8bq0"> <colgroup> <col class="field-name"/> <col class="field-body"/> </colgroup> <tbody> <tr class="css-x8snli"> <th> Returns <!-- --> : </th> <td> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-cursor"> cursor </a> that <code class="leafygreen-ui-1l06pbn"> ~cursor.tailable() </code> is attached to. </td> </tr> </tbody> </table> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> A tailable cursor performs a collection scan over a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/capped-collections/#std-label-manual-capped-collection"> capped collection </a> . It remains open even after reaching the end of the collection. Applications can continue to iterate the tailable cursor as new data is inserted into the collection. </p> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> awaitData </code> is <code class="leafygreen-ui-1l06pbn"> true </code> , when the cursor reaches the end of the capped collection, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-program-mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> blocks the query thread for the timeout interval and waits for new data to arrive. When new data is inserted into the capped collection, <code class="leafygreen-ui-1l06pbn"> mongod </code> signals the blocked thread to wake and return the next batch to the client. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/tailable-cursors/#std-label-tailable-cursors-landing-page"> Tailable Cursors <!-- --> . </a> </p> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/cursor.isClosed/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> cursor.isClosed() <a class="headerlink leafygreen-ui-1kepx47" href="#cursor.isclosed--" 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="cursor.isclosed--"> </div> </a> </h1> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> cursor.isClosed() </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-cursor.isClosed" title="Permalink to this definition"> <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="mongodb-method-cursor.isClosed"> </div> </a> </dt> <dd> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> mongosh Method </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This page documents a <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> method. This is <em> not </em> the documentation for a language-specific driver, such as Node.js. </p> <p class="leafygreen-ui-1kp3ins"> For MongoDB API drivers, refer to the language-specific <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> MongoDB driver documentation <!-- --> . </span> </a> </p> </div> </div> <table class="css-11h39yh e1nex8bq0"> <colgroup> <col class="field-name"/> <col class="field-body"/> </colgroup> <tbody> <tr class="css-x8snli"> <th> Returns <!-- --> : </th> <td> Boolean. </td> </tr> </tbody> </table> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.isClosed" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> cursor.isClosed() </code> </span> </a> returns <code class="leafygreen-ui-1l06pbn"> true </code> if the server has closed the cursor. </p> <p class="leafygreen-ui-1kp3ins"> A closed cursor may still have documents remaining in the last received batch. Use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.isExhausted/#mongodb-method-cursor.isExhausted"> <code class="leafygreen-ui-1l06pbn"> cursor.isExhausted() </code> </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.hasNext/#mongodb-method-cursor.hasNext"> <code class="leafygreen-ui-1l06pbn"> cursor.hasNext() </code> </a> to check if the cursor is fully exhausted. </p> </dd> </dl> </section>
https://www.mongodb.com/docs/manual/installation/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Install MongoDB <a class="headerlink leafygreen-ui-1kepx47" href="#install-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="install-mongodb"> </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="#mongodb-installation-tutorials" target="_self"> <span> MongoDB Installation Tutorials </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#upgrade-community-edition-to-enterprise-edition-tutorials" target="_self"> <span> Upgrade Community Edition to Enterprise Edition Tutorials </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#supported-platforms" target="_self"> <span> Supported Platforms </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> MongoDB is available in two server editions: <em> Community </em> and <em> Enterprise </em> . </p> <p class="leafygreen-ui-1kp3ins"> This section of the manual contains information on installing MongoDB. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For instructions on upgrading your current deployment to MongoDB 8.0, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/8.0/#std-label-8.0-upgrade"> 8.0 Upgrade Procedures <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For instructions on upgrading to the latest patch release for your current version, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/upgrade-revision/#std-label-upgrade-to-latest-revision"> Upgrade to the Latest Self-Managed Patch Release of MongoDB <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For documentation of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> , and all other tools distributed with MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/#std-label-mongodb-package-components"> MongoDB Package Components <!-- --> . </a> </p> </li> </ul> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> MongoDB Installation Tutorials <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-installation-tutorials" 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="mongodb-installation-tutorials"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB installation tutorials are available for the following platforms, for both the Community Edition and the Enterprise Edition: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:10%"/> <col style="width:45%"/> <col style="width:45%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Platform </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Community Edition </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Enterprise Edition </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Linux </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-red-hat/"> Install MongoDB Community Edition on Red Hat or CentOS </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-ubuntu/"> Install MongoDB Community Edition on Ubuntu </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-debian/"> Install MongoDB Community Edition on Debian </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-suse/"> Install MongoDB Community Edition on SUSE </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-amazon/"> Install MongoDB Community Edition on Amazon Linux </a> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-enterprise-on-red-hat/"> Install MongoDB Enterprise Edition on Red Hat or CentOS </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-enterprise-on-ubuntu/"> Install MongoDB Enterprise Edition on Ubuntu </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-enterprise-on-debian/"> Install MongoDB Enterprise Edition on Debian </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-enterprise-on-suse/"> Install MongoDB Enterprise Edition on SUSE </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-enterprise-on-amazon/"> Install MongoDB Enterprise Edition on Amazon Linux </a> </div> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-os-x/"> Install MongoDB Community Edition on macOS </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-enterprise-on-os-x/"> Install MongoDB Enterprise on macOS </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Windows </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-windows/"> Install MongoDB Community Edition on Windows </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-enterprise-on-windows/"> Install MongoDB Enterprise Edition on Windows </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Docker </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-community-with-docker/#std-label-docker-mongodb-community-install"> Install MongoDB Community with Docker </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-enterprise-with-docker/#std-label-docker-mongodb-enterprise-install"> Install MongoDB Enterprise with Docker </a> </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Upgrade Community Edition to Enterprise Edition Tutorials <a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-community-edition-to-enterprise-edition-tutorials" 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="upgrade-community-edition-to-enterprise-edition-tutorials"> </div> </a> </h2> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Do not use these instructions to upgrade to another release version. To upgrade release versions, refer to the appropriate release upgrade instructions, such as <a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/8.0/#std-label-8.0-upgrade"> Upgrade to MongoDB 8.0 <!-- --> . </a> </p> </div> </div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/upgrade-to-enterprise-standalone/"> Upgrade to MongoDB Enterprise (Standalone) </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/upgrade-to-enterprise-replica-set/"> Upgrade to MongoDB Enterprise (Replica Set) </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/upgrade-to-enterprise-sharded-cluster/"> Upgrade to MongoDB Enterprise (Sharded Cluster) </a> </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-mongodb-supported-platforms"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Supported Platforms <a class="headerlink leafygreen-ui-1kepx47" href="#supported-platforms" 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="supported-platforms"> </div> </a> </h2> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> MongoDB does not support 32-bit x86 platforms. </p> </div> </div> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> v4.4 End of Life </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> v4.4 reached end of life on February 29, 2024 and is no longer supported by MongoDB. </p> </div> </div> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:20%"/> <col style="width:10%"/> <col style="width:10%"/> <col style="width:10%"/> <col style="width:10%"/> <col style="width:10%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Platform </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Architecture </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Edition </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 8.0 </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 7.0 </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 6.0 </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 5.0 </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 4.4 </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Amazon Linux 2023 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Amazon Linux 2023 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Amazon Linux V2 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Amazon Linux V2 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Debian 12 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Debian 12 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Debian 11 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 5.0.8+ </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Debian 11 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 5.0.8+ </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Debian 10 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Debian 10 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Debian 9 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Debian 9 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/Rocky/Alma/Oracle Linux 9.0+ <a class="footnote-reference header-buffer" href="#footnote-oracle-support" id="ref-oracle-support-id1"> [ <!-- --> 1 <!-- --> ] </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 6.0.4+ </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/Rocky/Alma/Oracle Linux 9.0+ <a class="footnote-reference header-buffer" href="#footnote-oracle-support" id="ref-oracle-support-id2"> [ <!-- --> 1 <!-- --> ] </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 6.0.4+ </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/Rocky/Alma/Oracle Linux 8.0+ <a class="footnote-reference header-buffer" href="#footnote-oracle-support" id="ref-oracle-support-id3"> [ <!-- --> 1 <!-- --> ] </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/Rocky/Alma/Oracle Linux 8.0+ <a class="footnote-reference header-buffer" href="#footnote-oracle-support" id="ref-oracle-support-id4"> [ <!-- --> 1 <!-- --> ] </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/CentOS/Oracle Linux 7.0+ <a class="footnote-reference header-buffer" href="#footnote-oracle-support" id="ref-oracle-support-id5"> [ <!-- --> 1 <!-- --> ] </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/CentOS/Oracle Linux 7.0+ <a class="footnote-reference header-buffer" href="#footnote-oracle-support" id="ref-oracle-support-id6"> [ <!-- --> 1 <!-- --> ] </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/CentOS/Oracle Linux 6.2+ <a class="footnote-reference header-buffer" href="#footnote-oracle-support" id="ref-oracle-support-id7"> [ <!-- --> 1 <!-- --> ] </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/CentOS/Oracle Linux 6.2+ <a class="footnote-reference header-buffer" href="#footnote-oracle-support" id="ref-oracle-support-id8"> [ <!-- --> 1 <!-- --> ] </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> SLES 15 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> SLES 15 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> SLES 12 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> SLES 12 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 24.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 24.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 22.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 6.0.4+ </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 22.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 6.0.4+ </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 20.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 20.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 18.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 18.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 16.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 16.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Windows 11 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Windows 11 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Windows Server 2022 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Windows Server 2022 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Windows Server 2019 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Windows Server 2019 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Windows 10 / Server 2016 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Windows 10 / Server 2016 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 14 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 14 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 13 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 13 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 12 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 12 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 11 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 11 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 10.15 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 10.15 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 10.14 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 10.14 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 10.13 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 10.13 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> x86_64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 14 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 14 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 13 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 13 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 12 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 12 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 11 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> macOS 11 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Amazon Linux 2023 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Amazon Linux 2023 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Amazon Linux 2 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 4.4.4+ </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Amazon Linux 2 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 4.4.4+ </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/CentOS/Rocky/Alma 9 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/CentOS/Rocky/Alma 9 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/CentOS/Rocky/Alma 8 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 4.4.4+ </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/CentOS/Rocky/Alma 8 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 4.4.4+ </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 24.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 24.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 22.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 6.0.4+ </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 22.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 6.0.4+ </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 20.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 20.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 18.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 18.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> Ubuntu 16.04 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> arm64 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/Rocky/Alma 9 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> ppc64le </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/Rocky/Alma 8 <a class="footnote-reference header-buffer" href="#footnote-RHEL8-tcmalloc-support" id="ref-RHEL8-tcmalloc-support-id9"> [ <!-- --> 7 <!-- --> ] </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> ppc64le </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/CentOS 7 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> ppc64le </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 6.0.7+ </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/Rocky/Alma 8 <a class="footnote-reference header-buffer" href="#footnote-RHEL8-tcmalloc-support" id="ref-RHEL8-tcmalloc-support-id10"> [ <!-- --> 7 <!-- --> ] </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> s390x </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 5.0.9+ </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/CentOS 7 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> s390x </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Enterprise </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-xejatx" role="rowheader"> <div class="leafygreen-ui-1n4j8xf"> <div> RHEL/CentOS 7 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> s390x </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Community </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> </tr> </tbody> </table> </div> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-oracle-support" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <!-- --> 1 <!-- --> ] </td> <td class="leafygreen-ui-17r2xs0"> <em> ( <a href="#ref-oracle-support-id1"> 1 </a> , <a href="#ref-oracle-support-id2"> 2 </a> , <a href="#ref-oracle-support-id3"> 3 </a> , <a href="#ref-oracle-support-id4"> 4 </a> , <a href="#ref-oracle-support-id5"> 5 </a> , <a href="#ref-oracle-support-id6"> 6 </a> , <a href="#ref-oracle-support-id7"> 7 </a> , <a href="#ref-oracle-support-id8"> 8 </a> ) </em> <!-- --> On Oracle Linux, MongoDB only supports the Red Hat Compatible Kernel. </td> </tr> </tbody> </table> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-oracle-linux" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <!-- --> 2 <!-- --> ] </td> <td class="leafygreen-ui-17r2xs0"> <!-- --> MongoDB only supports Oracle Linux running the Red Hat Compatible Kernel (RHCK). MongoDB does <strong> not </strong> support the Unbreakable Enterprise Kernel (UEK). </td> </tr> </tbody> </table> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-RockyAlmaLinux-support-install" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <!-- --> 3 <!-- --> ] </td> <td class="leafygreen-ui-17r2xs0"> <!-- --> MongoDB on-premises products released for RHEL version 8.0+ are compatible with and supported on Rocky Linux version 8.0+ and AlmaLinux version 8.0+, contingent upon those distributions meeting their obligation to deliver full RHEL compatibility. </td> </tr> </tbody> </table> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-SLES12-SP-info" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <!-- --> 4 <!-- --> ] </td> <td class="leafygreen-ui-17r2xs0"> <!-- --> MongoDB versions 5.0 and greater are tested against SLES 12 service pack 5. Earlier versions of MongoDB are tested against SLES 12 with no service pack. </td> </tr> </tbody> </table> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-SLES15-SP-info" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <!-- --> 5 <!-- --> ] </td> <td class="leafygreen-ui-17r2xs0"> <!-- --> MongoDB versions 7.0 and later are tested against SLES 15 service pack 4. Earlier versions of MongoDB are tested against SLES 15 with no service pack. </td> </tr> </tbody> </table> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-RHEL7-compat" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <!-- --> 6 <!-- --> ] </td> <td class="leafygreen-ui-17r2xs0"> <!-- --> MongoDB version 7.0 is built and tested against RHEL 7.9. Earlier versions of MongoDB are tested against RHEL 7 and assume forward compatibility. </td> </tr> </tbody> </table> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-RHEL8-tcmalloc-support" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <!-- --> 7 <!-- --> ] </td> <td class="leafygreen-ui-17r2xs0"> <em> ( <a href="#ref-RHEL8-tcmalloc-support-id9"> 1 </a> , <a href="#ref-RHEL8-tcmalloc-support-id10"> 2 </a> ) </em> <!-- --> RHEL 8 on PPC64LE and s390x does not support the updated version of TCMalloc used in MongoDB versions 8.0 and later. On these architectures, RHEL 8 uses the legacy TCMalloc version. To learn more, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/tcmalloc-performance/#std-label-tcmalloc-performance"> TCMalloc Performance Optimization for a Self-Managed Deployment <!-- --> . </a> </td> </tr> </tbody> </table> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-RHEL9-tcmalloc-support" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <!-- --> 8 <!-- --> ] </td> <td class="leafygreen-ui-17r2xs0"> <!-- --> RHEL 9 on PPC64LE and s390x does not support the updated version of TCMalloc used in MongoDB versions 8.0 and later. On these architectures, RHEL 9 uses the legacy TCMalloc version. To learn more, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/tcmalloc-performance/#std-label-tcmalloc-performance"> TCMalloc Performance Optimization for a Self-Managed Deployment <!-- --> . </a> </td> </tr> </tbody> </table> </section> </section>
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-debian/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Install MongoDB Community Edition on Debian <a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-community-edition-on-debian" 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="install-mongodb-community-edition-on-debian"> </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="#overview" target="_self"> <span> Overview </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self"> <span> Considerations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#install-mongodb-community-edition" target="_self"> <span> Install MongoDB Community Edition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#run-mongodb-community-edition" target="_self"> <span> Run MongoDB Community Edition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#uninstall-mongodb-community-edition" target="_self"> <span> Uninstall MongoDB Community Edition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-information" target="_self"> <span> Additional Information </span> </a> </li> </ul> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> MongoDB Atlas </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/atlas/database?tck=docs_server" target="_self"> <span> MongoDB Atlas </span> </a> is a hosted MongoDB service option in the cloud which requires no installation overhead and offers a free tier to get started. </p> </div> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Overview <a class="headerlink leafygreen-ui-1kepx47" href="#overview" 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="overview"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Use this tutorial to install MongoDB 8.0 <!-- --> Community <!-- --> Edition using the <code class="leafygreen-ui-1l06pbn"> apt </code> package manager. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> MongoDB Version <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-version" 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="mongodb-version"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> This tutorial installs MongoDB 8.0 <!-- --> Community <!-- --> Edition. To install a different version of MongoDB <!-- --> Community <!-- --> , use the version drop-down menu in the upper-left corner of this page to select the documentation for that version. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Platform Support <a class="headerlink leafygreen-ui-1kepx47" href="#platform-support" 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="platform-support"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB 8.0 Community Edition supports the following <strong class="css-4dei7l"> 64-bit </strong> Debian releases on <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms-x86_64"> x86_64 </a> architecture: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Debian 12 "Bookworm" </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> MongoDB only supports the 64-bit versions of these platforms. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms"> Platform Support </a> for more information. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Production Notes <a class="headerlink leafygreen-ui-1kepx47" href="#production-notes" 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="production-notes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Before deploying MongoDB in a production environment, consider the <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/"> Production Notes for Self-Managed Deployments </a> document which offers performance considerations and configuration recommendations for production MongoDB deployments. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Official MongoDB Packages <a class="headerlink leafygreen-ui-1kepx47" href="#official-mongodb-packages" 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="official-mongodb-packages"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To install MongoDB <!-- --> Community <!-- --> on your <!-- --> Debian <!-- --> system, these instructions will use the official <code class="leafygreen-ui-1l06pbn"> mongodb-org </code> package, which is maintained and supported by MongoDB Inc. The official <code class="leafygreen-ui-1l06pbn"> mongodb-org </code> package always contains the latest version of MongoDB, and is available from its own dedicated repo. </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> mongodb </code> package provided by <!-- --> Debian <!-- --> is <strong> not </strong> maintained by MongoDB Inc. and conflicts with the official <code class="leafygreen-ui-1l06pbn"> mongodb-org </code> package. If you have already installed the <code class="leafygreen-ui-1l06pbn"> mongodb </code> package on your <!-- --> Debian <!-- --> system, you <strong> must </strong> first uninstall the <code class="leafygreen-ui-1l06pbn"> mongodb </code> package before proceeding with these instructions. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-debian-package-content" target="_self"> <span> MongoDB Community Edition Packages </span> </a> for the complete list of official packages. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-install-community-debian-pkg"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Install MongoDB Community Edition <a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-community-edition" 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="install-mongodb-community-edition"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Follow these steps to install MongoDB <!-- --> Community <!-- --> Edition using the <code class="leafygreen-ui-1l06pbn"> apt </code> package manager. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"From a terminal, install gnupg and curl if they are not already\navailable:To import the MongoDB public GPG key, run the following command:"},{"@type":"HowToStep","text":"Create a /etc/apt/sources.list.d/mongodb-org-8.0.list file for MongoDB.Create the list file using the command appropriate for your version\nof Debian:"},{"@type":"HowToStep","text":"Reload local package databaseIssue the following command to reload the local package database:"},{"@type":"HowToStep","text":"Install MongoDB Community ServerYou can install either the latest stable version of MongoDB or a\nspecific version of MongoDB.To install the latest stable version, issue the followingTo install a specific release, you must specify each component package\nindividually along with the version number, as in the\nfollowing example:If you only install mongodb-org=8.0.0 and do not include the\ncomponent packages, the latest version of each MongoDB package will be\ninstalled regardless of what version you specified.Optional. Although you can specify any available version of MongoDB,\napt-get will upgrade the packages when a newer version becomes\navailable. To prevent unintended upgrades, you can pin the package\nat the currently installed version:"}],"name":"Install MongoDB Community Edition","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <p class="leafygreen-ui-1kp3ins"> From a terminal, install <code class="leafygreen-ui-1l06pbn"> gnupg </code> and <code class="leafygreen-ui-1l06pbn"> curl </code> if they are not already available: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get install gnupg curl","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get install gnupg curl</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 import the MongoDB public GPG key, run the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \\\n sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \\\n --dearmor","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">curl -fsSL https:/<!-- -->/www.mongodb.org/static/pgp/server-<!-- -->8.0.asc | \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> sudo gpg -o <!-- -->/usr/share/keyrings/mongodb-server-<!-- -->8.0.gpg \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> --dearmor</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create a <code class="leafygreen-ui-1l06pbn"> /etc/apt/sources.list.d/mongodb-org-8.0.list </code> file for MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#create-a-etc-apt-sources-list-d-mongodb-org-8-0-list-file-for-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="create-a-etc-apt-sources-list-d-mongodb-org-8-0-list-file-for-mongodb"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Create the list file using the command appropriate for your version of Debian: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"echo \"deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main\" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main"</span> | sudo <span class="lg-highlight-built_in">tee</span> <!-- -->/etc/apt/sources.list.d/mongodb-org-<!-- -->8.0.list</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Reload local package database <a class="headerlink leafygreen-ui-1kepx47" href="#reload-local-package-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="reload-local-package-database"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Issue the following command to reload the local package database: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get update","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get update</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Install MongoDB Community Server <a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-community-server" 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="install-mongodb-community-server"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> You can install either the latest stable version of MongoDB or a specific version of MongoDB. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-14"> <div aria-label="Tabs to describe usage of latest/specific" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_6mjlr5xjv" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_999qjuakw" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Latest Release </div> </button> <button aria-controls="_et6wvmivt" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ld46601nc" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Specific Release </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="_9oavmwp75" class="" id="_p35kn8ih7" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To install the latest stable version, issue the following </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get install -y mongodb-org","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get install -y mongodb-org</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="_8p4vytvy6" class="leafygreen-ui-38lglc" id="_oi5frvphl" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To install a specific release, you must specify each component package individually along with the version number, as in the following example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get install -y mongodb-org=8.0.0 mongodb-org-database=8.0.0 mongodb-org-server=8.0.0 mongodb-mongosh mongodb-org-mongos=8.0.0 mongodb-org-tools=8.0.0\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get install -y mongodb-org=8.0.0 mongodb-org-database=8.0.0 mongodb-org-server=8.0.0 mongodb-mongosh mongodb-org-mongos=8.0.0 mongodb-org-tools=8.0.0</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"> If you only install <code class="leafygreen-ui-1l06pbn"> mongodb-org=8.0.0 </code> and do not include the component packages, the latest version of each MongoDB package will be installed regardless of what version you specified. </p> <p class="leafygreen-ui-1kp3ins"> Optional. Although you can specify any available version of MongoDB, <code class="leafygreen-ui-1l06pbn"> apt-get </code> will upgrade the packages when a newer version becomes available. To prevent unintended upgrades, you can pin the package at the currently installed version: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"echo \"mongodb-org hold\" | sudo dpkg --set-selections\necho \"mongodb-org-database hold\" | sudo dpkg --set-selections\necho \"mongodb-org-server hold\" | sudo dpkg --set-selections\necho \"mongodb-mongosh hold\" | sudo dpkg --set-selections\necho \"mongodb-org-mongos hold\" | sudo dpkg --set-selections\necho \"mongodb-org-tools hold\" | sudo dpkg --set-selections","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-org hold"</span> | sudo dpkg --set-selections</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-org-database hold"</span> | sudo dpkg --set-selections</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-org-server hold"</span> | sudo dpkg --set-selections</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-mongosh hold"</span> | sudo dpkg --set-selections</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-org-mongos hold"</span> | sudo dpkg --set-selections</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-org-tools hold"</span> | sudo dpkg --set-selections</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> </section> </div> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Run MongoDB Community Edition <a class="headerlink leafygreen-ui-1kepx47" href="#run-mongodb-community-edition" 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="run-mongodb-community-edition"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> ulimit Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#ulimit-considerations" 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="ulimit-considerations"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/ulimit/"> UNIX <code class="leafygreen-ui-1l06pbn"> ulimit </code> Settings for Self-Managed Deployments </a> for the recommended settings for your platform. </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 the <code class="leafygreen-ui-1l06pbn"> ulimit </code> value for number of open files is under <code class="leafygreen-ui-1l06pbn"> 64000 </code> , MongoDB generates a startup warning. </p> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Directories <a class="headerlink leafygreen-ui-1kepx47" href="#directories" 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="directories"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> By default, a MongoDB instance stores: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> its data files in <code class="leafygreen-ui-1l06pbn"> /var/lib/mongodb </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> its log files in <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb </code> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> If you installed via the package manager, these default directories are created during the installation. </p> <p class="leafygreen-ui-1kp3ins"> If you installed manually by downloading the tarballs, you can create the directories using <code class="leafygreen-ui-1l06pbn"> mkdir -p &lt;directory&gt; </code> or <code class="leafygreen-ui-1l06pbn"> sudo mkdir -p &lt;directory&gt; </code> depending on the user that will run MongoDB. (See your linux man pages for information on <code class="leafygreen-ui-1l06pbn"> mkdir </code> and <code class="leafygreen-ui-1l06pbn"> sudo </code> .) </p> <p class="leafygreen-ui-1kp3ins"> By default, MongoDB runs using the <code class="leafygreen-ui-1l06pbn"> mongodb </code> user account. If you change the user that runs the MongoDB process, you <strong> must </strong> also modify the permission to the <code class="leafygreen-ui-1l06pbn"> /var/lib/mongodb </code> and <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb </code> directories to give this user access to these directories. </p> <p class="leafygreen-ui-1kp3ins"> To specify a different log file directory and data file directory, edit the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-systemLog.path"> <code class="leafygreen-ui-1l06pbn"> systemLog.path </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.dbPath"> <code class="leafygreen-ui-1l06pbn"> storage.dbPath </code> </a> settings in the <code class="leafygreen-ui-1l06pbn"> /etc/mongod.conf </code> . Ensure that the user running MongoDB has access to these directories. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Procedure <a class="headerlink leafygreen-ui-1kepx47" href="#procedure" 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="procedure"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Follow these steps to run MongoDB <!-- --> Community <!-- --> Edition on your system. These instructions assume that you are using the official <code class="leafygreen-ui-1l06pbn"> mongodb-org </code> package -- not the unofficial <code class="leafygreen-ui-1l06pbn"> mongodb </code> package provided by <!-- --> Debian <!-- --> -- and are using the default settings. </p> <p class="leafygreen-ui-1kp3ins"> <strong> Init System </strong> </p> <p class="leafygreen-ui-1kp3ins"> To run and manage your <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process, you will be using your operating system's built-in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-init-system"> init system </a> . Recent versions of Linux tend to use <strong> systemd </strong> (which uses the <code class="leafygreen-ui-1l06pbn"> systemctl </code> command), while older versions of Linux tend to use <strong> System V init </strong> (which uses the <code class="leafygreen-ui-1l06pbn"> service </code> command). </p> <p class="leafygreen-ui-1kp3ins"> If you are unsure which init system your platform uses, run the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ps --no-headers -o comm 1","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">ps --no-headers -o <span class="lg-highlight-built_in">comm</span> 1</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"> Then select the appropriate tab below based on the result: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> systemd </code> - select the <strong> systemd (systemctl) </strong> tab below. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> init </code> - select the <strong> System V Init (service) </strong> tab below. </p> </li> </ul> <div class="line-block"> <div class="line"> <br/> </div> </div> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-29"> <div aria-label="Tabs to describe usage of systemd-systemctl/systemvinit-service" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_oxzxyjyj2" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_192eowj6a" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> systemd (systemctl) </div> </button> <button aria-controls="_vkowrge7i" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_o7cmaawbc" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> System V Init (service) </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="_e9r26y29y" class="" id="_uu2sj53b0" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Start MongoDB.You can start the mongod process by issuing the\nfollowing command:If you receive an error similar to the following when starting\nmongod:Failed to start mongod.service: Unit mongod.service not found.Run the following command first:Then run the start command above again."},{"@type":"HowToStep","text":"Verify that MongoDB has started successfully.You can optionally ensure that MongoDB will start following a\nsystem reboot by issuing the following command:"},{"@type":"HowToStep","text":"Stop MongoDB.As needed, you can stop the mongod process by issuing the\nfollowing command:"},{"@type":"HowToStep","text":"Restart MongoDB.You can restart the mongod process by issuing the following\ncommand:You can follow the state of the process for errors or important messages\nby watching the output in the /var/log/mongodb/mongod.log file."},{"@type":"HowToStep","text":"Begin using MongoDB.Start a mongosh session on the same host machine as the\nmongod. You can run mongosh\nwithout any command-line options to connect to a\nmongod that is running on your localhost with default\nport 27017.For more information on connecting using mongosh,\nsuch as to connect to a mongod instance running\non a different host and/or port, see the\nmongosh documentation.To help you start using MongoDB, MongoDB provides Getting\nStarted Guides in various driver editions. For the\ndriver documentation, see Start Developing with MongoDB."}],"name":"Procedure - systemd (systemctl)","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Start MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#start-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="start-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can start the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl start mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl start mongod</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"> If you receive an error similar to the following when starting <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> : </a> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> Failed to start mongod.service: Unit mongod.service not found. </code> </p> <p class="leafygreen-ui-1kp3ins"> Run the following command first: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl daemon-reload\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl daemon-reload</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"> Then run the start command above again. </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Verify that MongoDB has started successfully. <a class="headerlink leafygreen-ui-1kepx47" href="#verify-that-mongodb-has-started-successfully" 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="verify-that-mongodb-has-started-successfully"> </div> </a> </h4> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl status mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl status mongod</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"> You can optionally ensure that MongoDB will start following a system reboot by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl enable mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl enable mongod</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Stop MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#stop-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="stop-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> As needed, you can stop the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl stop mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl stop mongod</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Restart MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#restart-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="restart-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can restart the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl restart mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl restart mongod</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"> You can follow the state of the process for errors or important messages by watching the output in the <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb/mongod.log </code> file. </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 5 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Begin using MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#begin-using-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="begin-using-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Start a <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> session on the same host machine as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> . You can run <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> without any command-line options to 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> that is running on your localhost with default port 27017. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\nmongosh\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh</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"> For more information on connecting using <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> , such as to 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> instance running on a different host and/or port, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self"> <span> mongosh documentation <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> To help you start using MongoDB, MongoDB provides <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/getting-started/#std-label-getting-started"> Getting Started Guides </a> in various driver editions. For the driver documentation, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://api.mongodb.com/" target="_self"> <span> Start Developing with MongoDB <!-- --> . </span> </a> </p> </section> </div> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_g3bqwzn4i" class="leafygreen-ui-38lglc" id="_23c0euijk" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Start MongoDB.Issue the following command to start mongod:"},{"@type":"HowToStep","text":"Verify that MongoDB has started successfullyVerify that the mongod process has started\nsuccessfully:You can also check the log file for the current status of the\nmongod process, located at:\n/var/log/mongodb/mongod.log by default. A running\nmongod instance will indicate that it is ready for\nconnections with the following line:[initandlisten] waiting for connections on port 27017"},{"@type":"HowToStep","text":"Stop MongoDB.As needed, you can stop the mongod process by issuing the\nfollowing command:"},{"@type":"HowToStep","text":"Restart MongoDB.Issue the following command to restart mongod:"},{"@type":"HowToStep","text":"Begin using MongoDB.Start a mongosh session on the same host machine as the\nmongod. You can run mongosh\nwithout any command-line options to connect to a\nmongod that is running on your localhost with default\nport 27017.For more information on connecting using mongosh,\nsuch as to connect to a mongod instance running\non a different host and/or port, see the\nmongosh documentation.To help you start using MongoDB, MongoDB provides Getting\nStarted Guides in various driver editions. For the\ndriver documentation, see Start Developing with MongoDB."}],"name":"Procedure - System V Init (service)","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Start MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#start-mongodb-1" 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="start-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Issue the following command to start <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod start\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod start</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Verify that MongoDB has started successfully <a class="headerlink leafygreen-ui-1kepx47" href="#verify-that-mongodb-has-started-successfully-1" 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="verify-that-mongodb-has-started-successfully-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Verify that the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process has started successfully: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod status\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod status</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"> You can also check the log file for the current status of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process, located at: <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb/mongod.log </code> by default. A running <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instance will indicate that it is ready for connections with the following line: </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> [initandlisten] waiting for connections on port 27017 </code> </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Stop MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#stop-mongodb-1" 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="stop-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> As needed, you can stop the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod stop\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod stop</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Restart MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#restart-mongodb-1" 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="restart-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Issue the following command to restart <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod restart\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod restart</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 5 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Begin using MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#begin-using-mongodb-1" 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="begin-using-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Start a <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> session on the same host machine as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> . You can run <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> without any command-line options to 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> that is running on your localhost with default port 27017. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\nmongosh\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh</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"> For more information on connecting using <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> , such as to 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> instance running on a different host and/or port, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self"> <span> mongosh documentation <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> To help you start using MongoDB, MongoDB provides <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/getting-started/#std-label-getting-started"> Getting Started Guides </a> in various driver editions. For the driver documentation, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://api.mongodb.com/" target="_self"> <span> Start Developing with MongoDB <!-- --> . </span> </a> </p> </section> </div> </div> </div> </div> </div> </div> </div> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Uninstall MongoDB Community Edition <a class="headerlink leafygreen-ui-1kepx47" href="#uninstall-mongodb-community-edition" 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="uninstall-mongodb-community-edition"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To completely remove MongoDB from a system, you must remove the MongoDB applications themselves, the configuration files, and any directories containing data and logs. The following section guides you through the necessary steps. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This process will <em> completely </em> remove MongoDB, its configuration, and <em> all </em> databases. This process is not reversible, so ensure that all of your configuration and data is backed up before proceeding. </p> </div> </div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Stop MongoDB.Stop the mongod process by issuing the following command:"},{"@type":"HowToStep","text":"Remove Packages.Remove any MongoDB packages that you had previously installed."},{"@type":"HowToStep","text":"Remove Data Directories.Remove MongoDB databases and log files."}],"name":"Uninstall MongoDB Community Edition","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Stop MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#stop-mongodb-2" 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="stop-mongodb-2"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Stop the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod stop\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod stop</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Remove Packages. <a class="headerlink leafygreen-ui-1kepx47" href="#remove-packages" 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="remove-packages"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Remove any MongoDB packages that you had previously installed. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get purge mongodb-org*\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get purge mongodb-org*</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Remove Data Directories. <a class="headerlink leafygreen-ui-1kepx47" href="#remove-data-directories" 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="remove-data-directories"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Remove MongoDB databases and log files. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo rm -r /var/log/mongodb\nsudo rm -r /var/lib/mongodb\n","programmingLanguage":"Shell"} </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 shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo rm -r /var/log/mongodb</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sudo rm -r /var/lib/mongodb</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> </section> </div> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" 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> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Localhost Binding by Default <a class="headerlink leafygreen-ui-1kepx47" href="#localhost-binding-by-default" 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="localhost-binding-by-default"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> By default, MongoDB launches with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> set to <code class="leafygreen-ui-1l06pbn"> 127.0.0.1 </code> , which binds to the localhost network interface. This means that the <code class="leafygreen-ui-1l06pbn"> mongod </code> can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the <code class="leafygreen-ui-1l06pbn"> mongod </code> , and the <code class="leafygreen-ui-1l06pbn"> mongod </code> will not be able to initialize a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set"> replica set </a> unless this value is set to a valid network interface. </p> <p class="leafygreen-ui-1kp3ins"> This value can be configured either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> in the MongoDB configuration file with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> , or </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> via the command-line argument <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--bind_ip"> <code class="leafygreen-ui-1l06pbn"> --bind_ip </code> </a> </p> </li> </ul> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist"> Security Checklist for Self-Managed Deployments </a> . At minimum, consider <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-checklist-auth"> enabling authentication </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-hardening/#std-label-network-config-hardening"> hardening network infrastructure <!-- --> . </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> For more information on configuring <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> , see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-mongodb-configuration/"> IP Binding in Self-Managed Deployments <!-- --> . </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-debian-package-content"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> MongoDB Community Edition Packages <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-community-edition-packages" 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="mongodb-community-edition-packages"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB Community Edition is available from its own dedicated repository, and contains the following officially-supported packages: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:25%"/> <col style="width:75%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Package Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> A <code class="leafygreen-ui-1l06pbn"> metapackage </code> that automatically installs the component packages listed below. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org-database </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> metapackage </code> that automatically installs the component packages listed below. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:50%"/> <col style="width:50%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Package Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org-server </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> daemon, associated init script, and a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-conf-file"> configuration file </a> ( <code class="leafygreen-ui-1l06pbn"> /etc/mongod.conf </code> ). You can use the initialization script to start <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> with the configuration file. For details, see the "Run MongoDB Community Edition" section, above. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org-mongos </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> daemon. </div> </div> </td> </tr> </tbody> </table> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-mongosh </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the MongoDB Shell ( <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> ). </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org-tools </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> metapackage </code> that automatically installs the component packages listed below: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:50%"/> <col style="width:50%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Package Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-database-tools </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Contains the following MongoDB database tools: </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/database-tools/mongodump/#mongodb-binary-bin.mongodump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongodump </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongorestore </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/bsondump/#mongodb-binary-bin.bsondump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> bsondump </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoimport </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoexport </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongostat/#mongodb-binary-bin.mongostat" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongostat </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongotop/#mongodb-binary-bin.mongotop" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongotop </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongofiles/#mongodb-binary-bin.mongofiles" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongofiles </code> </span> </a> </p> </li> </ul> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org-database-tools-extra </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/install_compass/#std-label-install-compass"> <code class="leafygreen-ui-1l06pbn"> install_compass </code> </a> script </div> </div> </td> </tr> </tbody> </table> </div> </div> </div> </td> </tr> </tbody> </table> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-enterprise-on-red-hat/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Install MongoDB Enterprise Edition on Red Hat or CentOS <a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-enterprise-edition-on-red-hat-or-centos" 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="install-mongodb-enterprise-edition-on-red-hat-or-centos"> </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="#overview" target="_self"> <span> Overview </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self"> <span> Considerations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#install-mongodb-enterprise-edition" target="_self"> <span> Install MongoDB Enterprise Edition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#run-mongodb-enterprise-edition" target="_self"> <span> Run MongoDB Enterprise Edition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#uninstall-mongodb" target="_self"> <span> Uninstall MongoDB </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-information" target="_self"> <span> Additional Information </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Overview <a class="headerlink leafygreen-ui-1kepx47" href="#overview" 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="overview"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Use this tutorial to install MongoDB 8.0 <!-- --> Enterprise <!-- --> Edition on Red Hat Enterprise Linux, CentOS Linux, or Oracle Linux <a class="footnote-reference header-buffer" href="#footnote-oracle-linux" id="ref-oracle-linux-id1"> [ <!-- --> 1 <!-- --> ] </a> using the <code class="leafygreen-ui-1l06pbn"> yum </code> package manager. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self"> <span> MongoDB Enterprise Edition </span> </a> is available on select platforms and contains support for several features related to security and monitoring. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> MongoDB Version <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-version" 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="mongodb-version"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> This tutorial installs MongoDB 8.0 <!-- --> Enterprise <!-- --> Edition. To install a different version of MongoDB <!-- --> Enterprise <!-- --> , use the version drop-down menu in the upper-left corner of this page to select the documentation for that version. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Platform Support <a class="headerlink leafygreen-ui-1kepx47" href="#platform-support" 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="platform-support"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB 8.0 Enterprise Edition supports the following <strong class="css-4dei7l"> 64-bit </strong> versions of Red Hat Enterprise Linux (RHEL), CentOS Linux, Oracle Linux <a class="footnote-reference header-buffer" href="#footnote-oracle-linux" id="ref-oracle-linux-id2"> [ <!-- --> 1 <!-- --> ] </a> , Rocky Linux, and AlmaLinux <a class="footnote-reference header-buffer" href="#footnote-rocky-almalinux" id="ref-rocky-almalinux-id3"> [ <!-- --> 2 <!-- --> ] </a> on <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms-x86_64"> x86_64 </a> architecture: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <span class="leafygreen-ui-vm4wms" tabindex="0"> RHEL </span> / CentOS Stream / Oracle / Rocky / AlmaLinux 9 </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <span class="leafygreen-ui-vm4wms" tabindex="0"> RHEL </span> / CentOS Stream / Oracle / Rocky / AlmaLinux 8 </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> MongoDB only supports the 64-bit versions of these platforms. </p> <p class="leafygreen-ui-1kp3ins"> MongoDB 8.0 Enterprise Edition on <span class="leafygreen-ui-vm4wms" tabindex="0"> RHEL </span> / CentOS / Oracle / Rocky / Alma Linux also supports the <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms-ARM64"> ARM64 </a> architecture on select platforms. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms"> Platform Support </a> for more information. </p> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-oracle-linux" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <!-- --> 1 <!-- --> ] </td> <td class="leafygreen-ui-17r2xs0"> <em> ( <a href="#ref-oracle-linux-id1"> 1 </a> , <a href="#ref-oracle-linux-id2"> 2 </a> ) </em> <!-- --> MongoDB only supports Oracle Linux running the Red Hat Compatible Kernel (RHCK). MongoDB does <strong> not </strong> support the Unbreakable Enterprise Kernel (UEK). </td> </tr> </tbody> </table> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-rocky-almalinux" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <a href="#ref-rocky-almalinux-id3"> 2 </a> ] </td> <td class="leafygreen-ui-17r2xs0"> <!-- --> MongoDB on-premises products released for RHEL version 8.0+ are compatible with and supported on Rocky Linux version 8.0+ and AlmaLinux version 8.0+, contingent upon those distributions meeting their obligation to deliver full RHEL compatibility. </td> </tr> </tbody> </table> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Production Notes <a class="headerlink leafygreen-ui-1kepx47" href="#production-notes" 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="production-notes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Before deploying MongoDB in a production environment, consider the <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/"> Production Notes for Self-Managed Deployments </a> document which offers performance considerations and configuration recommendations for production MongoDB deployments. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-install-enterprise-redhat-pkg"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Install MongoDB Enterprise Edition <a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-enterprise-edition" 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="install-mongodb-enterprise-edition"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Follow these steps to install MongoDB <!-- --> Enterprise <!-- --> Edition using the <code class="leafygreen-ui-1l06pbn"> yum </code> package manager. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create an\n/etc/yum.repos.d/mongodb-enterprise-8.0.repo file so\nthat you can install MongoDB Enterprise directly using yum:If you have a mongodb-enterprise.repo file\nin this directory from a previous installation of MongoDB, you\nshould remove it. Use the mongodb-enterprise-8.0.repo\nfile above to install MongoDB 8.0.You can also download the .rpm files directly from the\nMongoDB repository.\nDownloads are organized by Red Hat / CentOS\nversion (e.g. 9), then MongoDB\nrelease version\n(e.g. 8.0), then architecture (e.g. x86_64).Prior to MongoDB 5.0, odd-numbered MongoDB release versions, such as\n4.3, were development releases. Beginning with MongoDB 5.1,\nMongoDB has quarterly rapid releases. For more information on the\ndifferences between rapid and long-term support releases, see\nMongoDB Versioning.","name":"Configure the Repository"},{"@type":"HowToStep","text":"To install the latest stable version of MongoDB Enterprise\n8.0, issue the following command:To install a specific release, you must specify each component package\nindividually along with the version number, as in the\nfollowing example:Although you can specify any available version of MongoDB\nEnterprise, yum upgrades the packages when a newer\nversion becomes available. To prevent unintended upgrades,\npin the package by adding the following exclude directive\nto your /etc/yum.conf file:","name":"Install MongoDB Enterprise Server"}],"name":"Install MongoDB Enterprise Edition","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Configure the Repository <a class="headerlink leafygreen-ui-1kepx47" href="#configure-the-repository" 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="configure-the-repository"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Create an <code class="leafygreen-ui-1l06pbn"> /etc/yum.repos.d/mongodb-enterprise-8.0.repo </code> file so that you can install MongoDB Enterprise directly using <code class="leafygreen-ui-1l06pbn"> yum </code> : </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-11"> <div aria-label="Tabs to describe usage of rhel8/rhel9" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_dw28tbkbv" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_n8grr8rtp" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> 9 </div> </button> <button aria-controls="_nxjkkp8rt" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_weovr4k81" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> 8 </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="_s7rvptt0i" class="" id="_6oekw37b0" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[mongodb-enterprise-8.0]\nname=MongoDB Enterprise Repository\nbaseurl=https://repo.mongodb.com/yum/redhat/9/mongodb-enterprise/8.0/$basearch/\ngpgcheck=1\nenabled=1\ngpgkey=https://pgp.mongodb.com/server-8.0.asc"} </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[mongodb-enterprise-8.0]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">name=MongoDB Enterprise Repository</td></tr><tr class=""><td class="leafygreen-ui-7razhx">baseurl=https://repo.mongodb.com/yum/redhat/9/mongodb-enterprise/8.0/$basearch/</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgcheck=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">enabled=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgkey=https://pgp.mongodb.com/server-8.0.asc</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="_vr7so31za" class="leafygreen-ui-38lglc" id="_6ss1lfdtn" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[mongodb-enterprise-8.0]\nname=MongoDB Enterprise Repository\nbaseurl=https://repo.mongodb.com/yum/redhat/8/mongodb-enterprise/8.0/$basearch/\ngpgcheck=1\nenabled=1\ngpgkey=https://pgp.mongodb.com/server-8.0.asc"} </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[mongodb-enterprise-8.0]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">name=MongoDB Enterprise Repository</td></tr><tr class=""><td class="leafygreen-ui-7razhx">baseurl=https://repo.mongodb.com/yum/redhat/8/mongodb-enterprise/8.0/$basearch/</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgcheck=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">enabled=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgkey=https://pgp.mongodb.com/server-8.0.asc</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> <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 a <code class="leafygreen-ui-1l06pbn"> mongodb-enterprise.repo </code> file in this directory from a previous installation of MongoDB, you should remove it. Use the <code class="leafygreen-ui-1l06pbn"> mongodb-enterprise-8.0.repo </code> file above to install MongoDB 8.0. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> You can also download the <code class="leafygreen-ui-1l06pbn"> .rpm </code> files directly from the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://repo.mongodb.com/yum/redhat/" target="_self"> <span> MongoDB repository </span> </a> . Downloads are organized by Red Hat / CentOS version (e.g. <code class="leafygreen-ui-1l06pbn"> 9 </code> ), then MongoDB <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/versioning/#std-label-release-version-numbers"> release version </a> (e.g. <code class="leafygreen-ui-1l06pbn"> 8.0 </code> ), then architecture (e.g. <code class="leafygreen-ui-1l06pbn"> x86_64 </code> ). </p> <p class="leafygreen-ui-1kp3ins"> Prior to MongoDB 5.0, odd-numbered MongoDB release versions, such as <code class="leafygreen-ui-1l06pbn"> 4.3 </code> , were development releases. Beginning with MongoDB 5.1, MongoDB has quarterly rapid releases. For more information on the differences between rapid and long-term support releases, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/versioning/#std-label-release-version-numbers"> MongoDB Versioning <!-- --> . </a> </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Install MongoDB Enterprise Server <a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-enterprise-server" 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="install-mongodb-enterprise-server"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To install the latest stable version of MongoDB Enterprise 8.0, issue the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y mongodb-enterprise","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum install -y mongodb-enterprise</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 install a specific release, you must specify each component package individually along with the version number, as in the following example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y mongodb-enterprise-8.0.0 mongodb-enterprise-database-8.0.0 mongodb-enterprise-server-8.0.0 mongodb-mongosh mongodb-enterprise-mongos-8.0.0 mongodb-enterprise-tools-8.0.0\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum install -y mongodb-enterprise-8.0.0 mongodb-enterprise-database-8.0.0 mongodb-enterprise-server-8.0.0 mongodb-mongosh mongodb-enterprise-mongos-8.0.0 mongodb-enterprise-tools-8.0.0</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 class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Although you can specify any available version of MongoDB Enterprise, <code class="leafygreen-ui-1l06pbn"> yum </code> upgrades the packages when a newer version becomes available. To prevent unintended upgrades, pin the package by adding the following <code class="leafygreen-ui-1l06pbn"> exclude </code> directive to your <code class="leafygreen-ui-1l06pbn"> /etc/yum.conf </code> file: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"exclude=mongodb-enterprise,mongodb-enterprise-database,mongodb-enterprise-server,mongodb-enterprise-shell,mongodb-enterprise-mongos,mongodb-enterprise-tools","programmingLanguage":"Ini"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light ini leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">exclude</span>=mongodb-enterprise,mongodb-enterprise-database,mongodb-enterprise-server,mongodb-enterprise-shell,mongodb-enterprise-mongos,mongodb-enterprise-tools</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> </section> </div> </div> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> You can also install the MongoDB Shell that uses the system's OpenSSL. You must have already installed OpenSSL on your system before installing this version of the MongoDB Shell. </p> <p class="leafygreen-ui-1kp3ins"> You can install all of the MongoDB Enterprise packages and the MongoDB Shell that uses the system's OpenSSL without removing the MongoDB Shell first. For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y mongodb-enterprise mongodb-mongosh-shared-openssl11","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum install -y mongodb-enterprise mongodb-mongosh-shared-openssl11</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"> The following example removes the MongoDB Shell and then installs the MongoDB Shell that uses the system's OpenSSL 1.1: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum remove -y mongodb-mongosh &amp;&amp; sudo yum install -y\nmongodb-mongosh-shared-openssl11","programmingLanguage":"Shell"} </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 shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum remove -y mongodb-mongosh &amp;&amp; sudo yum install -y</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongodb-mongosh-shared-openssl11</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"> The following example removes the MongoDB Shell and then installs the MongoDB Shell that uses the system's OpenSSL 3: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum remove -y mongodb-mongosh &amp;&amp; sudo yum install -y\nmongodb-mongosh-shared-openssl3","programmingLanguage":"Shell"} </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 shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum remove -y mongodb-mongosh &amp;&amp; sudo yum install -y</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongodb-mongosh-shared-openssl3</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"> You can also choose the MongoDB packages to install. </p> <p class="leafygreen-ui-1kp3ins"> The following example installs MongoDB Enterprise and tools, and the MongoDB Shell that uses the system's OpenSSL 1.1: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y mongodb-enterprise-database\nmongodb-enterprise-tools mongodb-mongosh-shared-openssl11","programmingLanguage":"Shell"} </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 shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum install -y mongodb-enterprise-database</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongodb-enterprise-tools mongodb-mongosh-shared-openssl11</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"> The following example installs MongoDB Enterprise and tools, and the MongoDB Shell that uses the system's OpenSSL 3: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y mongodb-enterprise-database\nmongodb-enterprise-tools mongodb-mongosh-shared-openssl3","programmingLanguage":"Shell"} </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 shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum install -y mongodb-enterprise-database</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongodb-enterprise-tools mongodb-mongosh-shared-openssl3</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Run MongoDB Enterprise Edition <a class="headerlink leafygreen-ui-1kepx47" href="#run-mongodb-enterprise-edition" 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="run-mongodb-enterprise-edition"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> ulimit <a class="headerlink leafygreen-ui-1kepx47" href="#ulimit" 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="ulimit"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/ulimit/"> UNIX <code class="leafygreen-ui-1l06pbn"> ulimit </code> Settings for Self-Managed Deployments </a> for the recommended settings for your platform. </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 the <code class="leafygreen-ui-1l06pbn"> ulimit </code> value for number of open files is under <code class="leafygreen-ui-1l06pbn"> 64000 </code> , MongoDB generates a startup warning. </p> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Directory Paths <a class="headerlink leafygreen-ui-1kepx47" href="#directory-paths" 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="directory-paths"> </div> </a> </h3> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> To Use Default Directories <a class="headerlink leafygreen-ui-1kepx47" href="#to-use-default-directories" 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="to-use-default-directories"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> By default, MongoDB runs using the <code class="leafygreen-ui-1l06pbn"> mongod </code> user account and uses the following default directories: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> /var/lib/mongo </code> (the data directory) </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb </code> (the log directory) </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The package manager creates the default directories during installation. The owner and group name are <code class="leafygreen-ui-1l06pbn"> mongod </code> . </p> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> To Use Non-Default Directories <a class="headerlink leafygreen-ui-1kepx47" href="#to-use-non-default-directories" 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="to-use-non-default-directories"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> To use a data directory and/or log directory other than the default directories: </p> <ol class="leafygreen-ui-rioki0" type="1"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Create the new directory or directories. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Edit the configuration file <code class="leafygreen-ui-1l06pbn"> /etc/mongod.conf </code> and modify the following fields accordingly: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.dbPath"> <code class="leafygreen-ui-1l06pbn"> storage.dbPath </code> </a> to specify a new data directory path (e.g. <code class="leafygreen-ui-1l06pbn"> /some/data/directory </code> ) </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-systemLog.path"> <code class="leafygreen-ui-1l06pbn"> systemLog.path </code> </a> to specify a new log file path (e.g. <code class="leafygreen-ui-1l06pbn"> /some/log/directory/mongod.log </code> ) </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ensure that the user running MongoDB has access to the directory or directories: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo chown -R mongod:mongod &lt;directory&gt;","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo <span class="lg-highlight-built_in">chown</span> -R mongod:mongod &lt;directory&gt;</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"> If you change the user that runs the MongoDB process, you <strong> must </strong> give the new user access to these directories. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Configure SELinux if enforced. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-install-enterprise-rhel-configure-selinux" target="_self"> <span> Configure SELinux <!-- --> . </span> </a> </p> </li> </ol> <span class="leafygreen-ui-1qnjd6d" id="std-label-install-enterprise-selinux-data-directory"> </span> <span class="leafygreen-ui-1qnjd6d" id="std-label-install-enterprise-rhel-configure-selinux"> </span> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Configure SELinux <a class="headerlink leafygreen-ui-1kepx47" href="#configure-selinux" 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="configure-selinux"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, a new SELinux policy is available for MongoDB installations that: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Use an <code class="leafygreen-ui-1l06pbn"> .rpm </code> installer. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Use default configuration settings. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Run on RHEL7 or later. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> If your installation does not meet these requirements, refer to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-enterprise-on-red-hat-tarball/#std-label-install-enterprise-tarball-rhel-configure-selinux"> SELinux Instructions </a> for <code class="leafygreen-ui-1l06pbn"> .tgz </code> packages. </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 your MongoDB deployment uses custom settings for any of the following: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/default-mongodb-port/#std-label-default-mongodb-port"> MongoDB connection ports </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.dbPath"> <code class="leafygreen-ui-1l06pbn"> dbPath </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-systemLog.path"> <code class="leafygreen-ui-1l06pbn"> systemLog.path </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-processManagement.pidFilePath"> <code class="leafygreen-ui-1l06pbn"> pidFilePath </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You cannot use the MongoDB supplied SELinux policy. An alternative is to create a <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-enterprise-on-red-hat-tarball/#std-label-install-enterprise-tarball-rhel-configure-selinux"> custom SELinux policy </a> , however an improperly written custom policy may be less secure or may stop your <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instance from working. </p> </div> </div> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Install the SELinux Policy <a class="headerlink leafygreen-ui-1kepx47" href="#install-the-selinux-policy" 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="install-the-selinux-policy"> </div> </a> </h4> <ol class="leafygreen-ui-rioki0" type="1"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ensure you have the following packages installed: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> git </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> make </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> checkpolicy </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> policycoreutils </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> selinux-policy-devel </code> </p> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install git make checkpolicy policycoreutils selinux-policy-devel","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum install git make checkpolicy policycoreutils selinux-policy-devel</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Download the policy repository. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"git clone https://github.com/mongodb/mongodb-selinux","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">git <span class="lg-highlight-built_in">clone</span> https:/<!-- -->/github.com/mongodb/mongodb-selinux</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Build the policy. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"cd mongodb-selinux\nmake","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">cd</span> mongodb-selinux</td></tr><tr class=""><td class="leafygreen-ui-7razhx">make</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Apply the policy. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo make install","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo make install</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> </li> </ol> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Backward-Incompatible Feature </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.1, you must run the following command from the directory into which the SELinux policy was previously cloned before you can downgrade to an earlier MongoDB version: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo make uninstall","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo make uninstall</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> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> SELinux Policy Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#selinux-policy-considerations" 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="selinux-policy-considerations"> </div> </a> </h4> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The SELinux policy is designed to work with the configuration that results from a standard MongoDB <code class="leafygreen-ui-1l06pbn"> .rpm </code> package installation. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/mongodb-selinux/blob/master/README.md#standard-installation" rel="noopener noreferrer"> <span> standard installation assumptions </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> for more details. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The SELinux policy is designed for <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> servers. It does not apply to other MongoDB daemons or tools such as: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/install-library/#std-label-mongocryptd"> Install and Configure a CSFLE Library </a> </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/SELinuxProject/refpolicy/blob/master/policy/modules/services/mongodb.if" rel="noopener noreferrer"> <span> reference policy </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> supplied by the SELinux Project includes a <code class="leafygreen-ui-1l06pbn"> mongodb_admin </code> macro. This macro is not included in the MongoDB SELinux policy. An administrator in the <code class="leafygreen-ui-1l06pbn"> unconfined_t </code> domain can manage <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To uninstall the policy, go to the directory where you downloaded the policy repository and run: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo make uninstall","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo make uninstall</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> </li> </ul> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Procedure <a class="headerlink leafygreen-ui-1kepx47" href="#procedure" 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="procedure"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Follow these steps to run MongoDB <!-- --> Enterprise <!-- --> Edition on your system. These instructions assume that you are using the default settings. </p> <p class="leafygreen-ui-1kp3ins"> <strong> Init System </strong> </p> <p class="leafygreen-ui-1kp3ins"> To run and manage your <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process, you will be using your operating system's built-in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-init-system"> init system </a> . Recent versions of Linux tend to use <strong> systemd </strong> (which uses the <code class="leafygreen-ui-1l06pbn"> systemctl </code> command), while older versions of Linux tend to use <strong> System V init </strong> (which uses the <code class="leafygreen-ui-1l06pbn"> service </code> command). </p> <p class="leafygreen-ui-1kp3ins"> If you are unsure which init system your platform uses, run the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ps --no-headers -o comm 1","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">ps --no-headers -o <span class="lg-highlight-built_in">comm</span> 1</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"> Then select the appropriate tab below based on the result: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> systemd </code> - select the <strong> systemd (systemctl) </strong> tab below. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> init </code> - select the <strong> System V Init (service) </strong> tab below. </p> </li> </ul> <div class="line-block"> <div class="line"> <br/> </div> </div> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-32"> <div aria-label="Tabs to describe usage of systemd-systemctl/systemvinit-service" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_x2lymjfem" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_pyqyvorge" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> systemd (systemctl) </div> </button> <button aria-controls="_aeuc0zzbo" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_hok4v9h86" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> System V Init (service) </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="_n820dek6c" class="" id="_37py48mt6" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Start MongoDB.You can start the mongod process by issuing the\nfollowing command:If you receive an error similar to the following when starting\nmongod:Failed to start mongod.service: Unit mongod.service not found.Run the following command first:Then run the start command above again."},{"@type":"HowToStep","text":"Verify that MongoDB has started successfully.You can verify that the mongod process has started\nsuccessfully by issuing the following command:You can optionally ensure that MongoDB will start following a\nsystem reboot by issuing the following command:"},{"@type":"HowToStep","text":"Stop MongoDB.As needed, you can stop the mongod process by issuing the\nfollowing command:"},{"@type":"HowToStep","text":"Restart MongoDB.You can restart the mongod process by issuing the following\ncommand:You can follow the state of the process for errors or important messages\nby watching the output in the /var/log/mongodb/mongod.log file."},{"@type":"HowToStep","text":"Begin using MongoDB.Start a mongosh session on the same host machine as the\nmongod. You can run mongosh\nwithout any command-line options to connect to a\nmongod that is running on your localhost with default\nport 27017.For more information on connecting using mongosh,\nsuch as to connect to a mongod instance running\non a different host and/or port, see the\nmongosh documentation.To help you start using MongoDB, MongoDB provides Getting\nStarted Guides in various driver editions. For the\ndriver documentation, see Start Developing with MongoDB."}],"name":"Procedure - systemd (systemctl)","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Start MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#start-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="start-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can start the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl start mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl start mongod</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"> If you receive an error similar to the following when starting <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> : </a> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> Failed to start mongod.service: Unit mongod.service not found. </code> </p> <p class="leafygreen-ui-1kp3ins"> Run the following command first: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl daemon-reload\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl daemon-reload</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"> Then run the start command above again. </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Verify that MongoDB has started successfully. <a class="headerlink leafygreen-ui-1kepx47" href="#verify-that-mongodb-has-started-successfully" 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="verify-that-mongodb-has-started-successfully"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can verify that the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process has started successfully by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl status mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl status mongod</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"> You can optionally ensure that MongoDB will start following a system reboot by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl enable mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl enable mongod</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Stop MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#stop-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="stop-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> As needed, you can stop the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl stop mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl stop mongod</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Restart MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#restart-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="restart-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can restart the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl restart mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl restart mongod</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"> You can follow the state of the process for errors or important messages by watching the output in the <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb/mongod.log </code> file. </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 5 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Begin using MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#begin-using-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="begin-using-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Start a <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> session on the same host machine as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> . You can run <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> without any command-line options to 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> that is running on your localhost with default port 27017. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\nmongosh\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh</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"> For more information on connecting using <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> , such as to 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> instance running on a different host and/or port, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self"> <span> mongosh documentation <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> To help you start using MongoDB, MongoDB provides <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/getting-started/#std-label-getting-started"> Getting Started Guides </a> in various driver editions. For the driver documentation, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://api.mongodb.com/" target="_self"> <span> Start Developing with MongoDB <!-- --> . </span> </a> </p> </section> </div> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_6d6gtpgp2" class="leafygreen-ui-38lglc" id="_q3mb17fss" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Start MongoDB.You can start the mongod process by issuing the following\ncommand:"},{"@type":"HowToStep","text":"Verify that MongoDB has started successfullyYou can verify that the mongod process has started\nsuccessfully by checking the contents of the log file at\n/var/log/mongodb/mongod.log\nfor a line readingwhere <port> is the port configured in /etc/mongod.conf, 27017 by default.You can optionally ensure that MongoDB will start following a system\nreboot by issuing the following command:"},{"@type":"HowToStep","text":"Stop MongoDB.As needed, you can stop the mongod process by issuing the\nfollowing command:"},{"@type":"HowToStep","text":"Restart MongoDB.You can restart the mongod process by issuing the following\ncommand:You can follow the state of the process for errors or important messages\nby watching the output in the /var/log/mongodb/mongod.log file."},{"@type":"HowToStep","text":"Begin using MongoDB.Start a mongosh session on the same host machine as the\nmongod. You can run mongosh\nwithout any command-line options to connect to a\nmongod that is running on your localhost with default\nport 27017.For more information on connecting using mongosh,\nsuch as to connect to a mongod instance running\non a different host and/or port, see the\nmongosh documentation.To help you start using MongoDB, MongoDB provides Getting\nStarted Guides in various driver editions. For the\ndriver documentation, see Start Developing with MongoDB."}],"name":"Procedure - System V Init (service)","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Start MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#start-mongodb-1" 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="start-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can start the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod start\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod start</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Verify that MongoDB has started successfully <a class="headerlink leafygreen-ui-1kepx47" href="#verify-that-mongodb-has-started-successfully-1" 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="verify-that-mongodb-has-started-successfully-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can verify that the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process has started successfully by checking the contents of the log file at <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb/mongod.log </code> for a line reading </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[initandlisten] waiting for connections on port &lt;port&gt;\n"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[initandlisten] waiting for connections on port &lt;port&gt;</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"> where <code class="leafygreen-ui-1l06pbn"> &lt;port&gt; </code> is the port configured in <code class="leafygreen-ui-1l06pbn"> /etc/mongod.conf </code> , <code class="leafygreen-ui-1l06pbn"> 27017 </code> by default. </p> <p class="leafygreen-ui-1kp3ins"> You can optionally ensure that MongoDB will start following a system reboot by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo chkconfig mongod on\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo chkconfig mongod on</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Stop MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#stop-mongodb-1" 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="stop-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> As needed, you can stop the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod stop\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod stop</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Restart MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#restart-mongodb-1" 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="restart-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can restart the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod restart\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod restart</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"> You can follow the state of the process for errors or important messages by watching the output in the <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb/mongod.log </code> file. </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 5 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Begin using MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#begin-using-mongodb-1" 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="begin-using-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Start a <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> session on the same host machine as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> . You can run <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> without any command-line options to 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> that is running on your localhost with default port 27017. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\nmongosh\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh</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"> For more information on connecting using <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> , such as to 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> instance running on a different host and/or port, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self"> <span> mongosh documentation <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> To help you start using MongoDB, MongoDB provides <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/getting-started/#std-label-getting-started"> Getting Started Guides </a> in various driver editions. For the driver documentation, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://api.mongodb.com/" target="_self"> <span> Start Developing with MongoDB <!-- --> . </span> </a> </p> </section> </div> </div> </div> </div> </div> </div> </div> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Uninstall MongoDB <a class="headerlink leafygreen-ui-1kepx47" href="#uninstall-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="uninstall-mongodb"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To completely remove MongoDB from a system, you must remove the MongoDB applications themselves, the configuration files, and any directories containing data and logs. The following section guides you through the necessary steps. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This process will <em> completely </em> remove MongoDB, its configuration, and <em> all </em> databases. This process is not reversible, so ensure that all of your configuration and data is backed up before proceeding. </p> </div> </div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Stop MongoDB.Stop the mongod process by issuing the following command:"},{"@type":"HowToStep","text":"Remove Packages.Remove any MongoDB packages that you had previously installed."},{"@type":"HowToStep","text":"Remove Data Directories.Remove MongoDB databases and log files."}],"name":"Uninstall MongoDB","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Stop MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#stop-mongodb-2" 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="stop-mongodb-2"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Stop the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod stop\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod stop</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Remove Packages. <a class="headerlink leafygreen-ui-1kepx47" href="#remove-packages" 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="remove-packages"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Remove any MongoDB packages that you had previously installed. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum erase $(rpm -qa | grep mongodb-enterprise)\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum erase $(rpm -qa | grep mongodb-enterprise)</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Remove Data Directories. <a class="headerlink leafygreen-ui-1kepx47" href="#remove-data-directories" 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="remove-data-directories"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Remove MongoDB databases and log files. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo rm -r /var/log/mongodb\nsudo rm -r /var/lib/mongo\n","programmingLanguage":"Shell"} </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 shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo rm -r /var/log/mongodb</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sudo rm -r /var/lib/mongo</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> </section> </div> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" 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> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Localhost Binding by Default <a class="headerlink leafygreen-ui-1kepx47" href="#localhost-binding-by-default" 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="localhost-binding-by-default"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> By default, MongoDB launches with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> set to <code class="leafygreen-ui-1l06pbn"> 127.0.0.1 </code> , which binds to the localhost network interface. This means that the <code class="leafygreen-ui-1l06pbn"> mongod </code> can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the <code class="leafygreen-ui-1l06pbn"> mongod </code> , and the <code class="leafygreen-ui-1l06pbn"> mongod </code> will not be able to initialize a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set"> replica set </a> unless this value is set to a valid network interface. </p> <p class="leafygreen-ui-1kp3ins"> This value can be configured either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> in the MongoDB configuration file with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> , or </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> via the command-line argument <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--bind_ip"> <code class="leafygreen-ui-1l06pbn"> --bind_ip </code> </a> </p> </li> </ul> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist"> Security Checklist for Self-Managed Deployments </a> . At minimum, consider <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-checklist-auth"> enabling authentication </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-hardening/#std-label-network-config-hardening"> hardening network infrastructure <!-- --> . </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> For more information on configuring <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> , see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-mongodb-configuration/"> IP Binding in Self-Managed Deployments <!-- --> . </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> MongoDB Enterprise Edition Packages <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-enterprise-edition-packages" 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="mongodb-enterprise-edition-packages"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB Enterprise Edition is available from its own dedicated repository, and contains the following officially-supported packages: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:35%"/> <col style="width:65%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Package Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-enterprise </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> A <code class="leafygreen-ui-1l06pbn"> metapackage </code> that automatically installs the component packages listed below. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-enterprise-database </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> metapackage </code> that automatically installs the component packages listed below. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:50%"/> <col style="width:50%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Package Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-enterprise-server </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> daemon and associated configuration and init scripts. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-enterprise-mongos </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> daemon. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-enterprise-cryptd </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/encryption-components/#std-label-csfle-encryption-components"> mongocryptd </a> binary </div> </div> </td> </tr> </tbody> </table> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-mongosh </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the MongoDB Shell ( <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> ). </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-shared-openssl* </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the MongoDB Shell that uses the OpenSSL version already installed on your computer ( <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> ). </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-enterprise-tools </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> metapackage </code> that automatically installs the component packages listed below: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:50%"/> <col style="width:50%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Package Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-database-tools </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Contains the following MongoDB database tools: </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/database-tools/mongodump/#mongodb-binary-bin.mongodump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongodump </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongorestore </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/bsondump/#mongodb-binary-bin.bsondump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> bsondump </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoimport </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoexport </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongostat/#mongodb-binary-bin.mongostat" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongostat </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongotop/#mongodb-binary-bin.mongotop" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongotop </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongofiles/#mongodb-binary-bin.mongofiles" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongofiles </code> </span> </a> </p> </li> </ul> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-enterprise-database-tools-extra </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Contains the following MongoDB support tools: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongoldap/#mongodb-binary-bin.mongoldap"> <code class="leafygreen-ui-1l06pbn"> mongoldap </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongokerberos/#mongodb-binary-bin.mongokerberos"> <code class="leafygreen-ui-1l06pbn"> mongokerberos </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/install_compass/#std-label-install-compass"> <code class="leafygreen-ui-1l06pbn"> install_compass </code> </a> script </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> mongodecrypt </code> binary </p> </li> </ul> </div> </div> </td> </tr> </tbody> </table> </div> </div> </div> </td> </tr> </tbody> </table> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Install MongoDB Community Edition on Ubuntu <a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-community-edition-on-ubuntu" 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="install-mongodb-community-edition-on-ubuntu"> </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="#overview" target="_self"> <span> Overview </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self"> <span> Considerations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#install-mongodb-community-edition" target="_self"> <span> Install MongoDB Community Edition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#run-mongodb-community-edition" target="_self"> <span> Run MongoDB Community Edition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#uninstall-mongodb-community-edition" target="_self"> <span> Uninstall MongoDB Community Edition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-information" target="_self"> <span> Additional Information </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Overview <a class="headerlink leafygreen-ui-1kepx47" href="#overview" 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="overview"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Use this tutorial to install MongoDB 8.0 <!-- --> Community <!-- --> Edition on LTS (long-term support) releases of Ubuntu Linux using the <code class="leafygreen-ui-1l06pbn"> apt </code> package manager. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> MongoDB Version <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-version" 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="mongodb-version"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> This tutorial installs MongoDB 8.0 <!-- --> Community <!-- --> Edition. To install a different version of MongoDB <!-- --> Community <!-- --> , use the version drop-down menu in the upper-left corner of this page to select the documentation for that version. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Platform Support <a class="headerlink leafygreen-ui-1kepx47" href="#platform-support" 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="platform-support"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB 8.0 Community Edition supports the following <strong class="css-4dei7l"> 64-bit </strong> Ubuntu LTS (long-term support) releases on <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms-x86_64"> x86_64 </a> architecture: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> 24.04 <span class="leafygreen-ui-vm4wms" tabindex="0"> LTS </span> ("Noble") </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> 22.04 <span class="leafygreen-ui-vm4wms" tabindex="0"> LTS </span> ("Jammy") </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> 20.04 <span class="leafygreen-ui-vm4wms" tabindex="0"> LTS </span> ("Focal") </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> MongoDB only supports the 64-bit versions of these platforms. To determine which Ubuntu release your host is running, run the following command on the host's terminal: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"cat /etc/lsb-release","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">cat</span> <!-- -->/etc/lsb-release</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"> MongoDB 8.0 Community Edition on Ubuntu also supports the <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms-ARM64"> ARM64 </a> architecture on select platforms. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms"> Platform Support </a> for more information. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Production Notes <a class="headerlink leafygreen-ui-1kepx47" href="#production-notes" 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="production-notes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Before deploying MongoDB in a production environment, consider the <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/"> Production Notes for Self-Managed Deployments </a> document which offers performance considerations and configuration recommendations for production MongoDB deployments. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Official MongoDB Packages <a class="headerlink leafygreen-ui-1kepx47" href="#official-mongodb-packages" 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="official-mongodb-packages"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To install MongoDB <!-- --> Community <!-- --> on your <!-- --> Ubuntu <!-- --> system, these instructions will use the official <code class="leafygreen-ui-1l06pbn"> mongodb-org </code> package, which is maintained and supported by MongoDB Inc. The official <code class="leafygreen-ui-1l06pbn"> mongodb-org </code> package always contains the latest version of MongoDB, and is available from its own dedicated repo. </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> mongodb </code> package provided by <!-- --> Ubuntu <!-- --> is <strong> not </strong> maintained by MongoDB Inc. and conflicts with the official <code class="leafygreen-ui-1l06pbn"> mongodb-org </code> package. If you have already installed the <code class="leafygreen-ui-1l06pbn"> mongodb </code> package on your <!-- --> Ubuntu <!-- --> system, you <strong> must </strong> first uninstall the <code class="leafygreen-ui-1l06pbn"> mongodb </code> package before proceeding with these instructions. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-ubuntu-package-content" target="_self"> <span> MongoDB Community Edition Packages </span> </a> for the complete list of official packages. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-install-community-ubuntu-pkg"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Install MongoDB Community Edition <a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-community-edition" 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="install-mongodb-community-edition"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Follow these steps to install MongoDB <!-- --> Community <!-- --> Edition using the <code class="leafygreen-ui-1l06pbn"> apt </code> package manager. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"From a terminal, install gnupg and curl if they are not already\navailable:To import the MongoDB public GPG key, run the following command:","name":"Import the Public Key"},{"@type":"HowToStep","text":"Create the list file\n/etc/apt/sources.list.d/mongodb-org-8.0.list for\nyour version of Ubuntu.Create the list file for Ubuntu 24.04 (Noble):Create the list file for Ubuntu 22.04 (Jammy):Create the list file for Ubuntu 20.04 (Focal):","name":"Create the List File"},{"@type":"HowToStep","text":"Issue the following command to reload the local package database:","name":"Reload the Package Database"},{"@type":"HowToStep","text":"You can install either the latest stable version of MongoDB or a\nspecific version of MongoDB.To install the latest stable version, issue the followingTo install a specific release, you must specify each component package\nindividually along with the version number, as in the\nfollowing example:If you only install mongodb-org=8.0.0 and do not include the\ncomponent packages, the latest version of each MongoDB package will be\ninstalled regardless of what version you specified.Optional. Although you can specify any available version of MongoDB,\napt-get will upgrade the packages when a newer version becomes\navailable. To prevent unintended upgrades, you can pin the package\nat the currently installed version:","name":"Install MongoDB Community Server"}],"name":"Install MongoDB Community Edition","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Import the Public Key <a class="headerlink leafygreen-ui-1kepx47" href="#import-the-public-key" 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-the-public-key"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> From a terminal, install <code class="leafygreen-ui-1l06pbn"> gnupg </code> and <code class="leafygreen-ui-1l06pbn"> curl </code> if they are not already available: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get install gnupg curl","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get install gnupg curl</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 import the MongoDB public GPG key, run the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \\\n sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \\\n --dearmor","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">curl -fsSL https:/<!-- -->/www.mongodb.org/static/pgp/server-<!-- -->8.0.asc | \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> sudo gpg -o <!-- -->/usr/share/keyrings/mongodb-server-<!-- -->8.0.gpg \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> --dearmor</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create the List File <a class="headerlink leafygreen-ui-1kepx47" href="#create-the-list-file" 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-the-list-file"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Create the list file <code class="leafygreen-ui-1l06pbn"> /etc/apt/sources.list.d/mongodb-org-8.0.list </code> for your version of Ubuntu. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-13"> <div aria-label="Tabs to describe usage of focal/jammy/noble" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_3xbs38dnz" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_sr9y88xf3" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Ubuntu 24.04 (Noble) </div> </button> <button aria-controls="_0ph4qgap0" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_mpshh2bmb" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Ubuntu 22.04 (Jammy) </div> </button> <button aria-controls="_sisxh1zxg" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_dvcuxpt9s" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Ubuntu 20.04 (Focal) </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="_j5lpfhxcd" class="" id="_39kt16epk" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create the list file for Ubuntu 24.04 (Noble): </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"echo \"deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse\" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse"</span> | sudo <span class="lg-highlight-built_in">tee</span> <!-- -->/etc/apt/sources.list.d/mongodb-org-<!-- -->8.0.list</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="_ym5n1brb3" class="leafygreen-ui-38lglc" id="_dzb8x9ip6" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create the list file for Ubuntu 22.04 (Jammy): </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"echo \"deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse\" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse"</span> | sudo <span class="lg-highlight-built_in">tee</span> <!-- -->/etc/apt/sources.list.d/mongodb-org-<!-- -->8.0.list</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="_e3h9f192m" class="leafygreen-ui-38lglc" id="_py010jer6" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> Create the list file for Ubuntu 20.04 (Focal): </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"echo \"deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0 multiverse\" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0 multiverse"</span> | sudo <span class="lg-highlight-built_in">tee</span> <!-- -->/etc/apt/sources.list.d/mongodb-org-<!-- -->8.0.list</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Reload the Package Database <a class="headerlink leafygreen-ui-1kepx47" href="#reload-the-package-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="reload-the-package-database"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Issue the following command to reload the local package database: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get update","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get update</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Install MongoDB Community Server <a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-community-server" 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="install-mongodb-community-server"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> You can install either the latest stable version of MongoDB or a specific version of MongoDB. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-16"> <div aria-label="Tabs to describe usage of latest/specific" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_qlgczntax" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_3bg8d4hn9" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Latest Release </div> </button> <button aria-controls="_updxslgsa" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_fmw1xyssw" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Specific Release </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="_k4m9n9kob" class="" id="_qi9yg396p" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To install the latest stable version, issue the following </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get install -y mongodb-org","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get install -y mongodb-org</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="_fv9pokyhg" class="leafygreen-ui-38lglc" id="_w2fepblbd" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To install a specific release, you must specify each component package individually along with the version number, as in the following example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get install -y mongodb-org=8.0.0 mongodb-org-database=8.0.0 mongodb-org-server=8.0.0 mongodb-mongosh mongodb-org-mongos=8.0.0 mongodb-org-tools=8.0.0\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get install -y mongodb-org=8.0.0 mongodb-org-database=8.0.0 mongodb-org-server=8.0.0 mongodb-mongosh mongodb-org-mongos=8.0.0 mongodb-org-tools=8.0.0</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"> If you only install <code class="leafygreen-ui-1l06pbn"> mongodb-org=8.0.0 </code> and do not include the component packages, the latest version of each MongoDB package will be installed regardless of what version you specified. </p> <p class="leafygreen-ui-1kp3ins"> Optional. Although you can specify any available version of MongoDB, <code class="leafygreen-ui-1l06pbn"> apt-get </code> will upgrade the packages when a newer version becomes available. To prevent unintended upgrades, you can pin the package at the currently installed version: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"echo \"mongodb-org hold\" | sudo dpkg --set-selections\necho \"mongodb-org-database hold\" | sudo dpkg --set-selections\necho \"mongodb-org-server hold\" | sudo dpkg --set-selections\necho \"mongodb-mongosh hold\" | sudo dpkg --set-selections\necho \"mongodb-org-mongos hold\" | sudo dpkg --set-selections\necho \"mongodb-org-tools hold\" | sudo dpkg --set-selections","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-org hold"</span> | sudo dpkg --set-selections</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-org-database hold"</span> | sudo dpkg --set-selections</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-org-server hold"</span> | sudo dpkg --set-selections</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-mongosh hold"</span> | sudo dpkg --set-selections</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-org-mongos hold"</span> | sudo dpkg --set-selections</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">echo</span> <span class="lg-highlight-string">"mongodb-org-tools hold"</span> | sudo dpkg --set-selections</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> </section> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> For help with troubleshooting errors encountered while installing MongoDB on Ubuntu, see our <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/installation-ubuntu-community-troubleshooting/#std-label-install-ubuntu-troubleshooting"> troubleshooting </a> guide. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Run MongoDB Community Edition <a class="headerlink leafygreen-ui-1kepx47" href="#run-mongodb-community-edition" 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="run-mongodb-community-edition"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> ulimit Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#ulimit-considerations" 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="ulimit-considerations"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/ulimit/"> UNIX <code class="leafygreen-ui-1l06pbn"> ulimit </code> Settings for Self-Managed Deployments </a> for the recommended settings for your platform. </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 the <code class="leafygreen-ui-1l06pbn"> ulimit </code> value for number of open files is under <code class="leafygreen-ui-1l06pbn"> 64000 </code> , MongoDB generates a startup warning. </p> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Directories <a class="headerlink leafygreen-ui-1kepx47" href="#directories" 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="directories"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If you installed through the package manager, the data directory <code class="leafygreen-ui-1l06pbn"> /var/lib/mongodb </code> and the log directory <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb </code> are created during the installation. </p> <p class="leafygreen-ui-1kp3ins"> By default, MongoDB runs using the <code class="leafygreen-ui-1l06pbn"> mongodb </code> user account. If you change the user that runs the MongoDB process, you <strong> must </strong> also modify the permission to the data and log directories to give this user access to these directories. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Configuration File <a class="headerlink leafygreen-ui-1kepx47" href="#configuration-file" 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="configuration-file"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The official MongoDB package includes a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-conf-file"> configuration file </a> ( <code class="file docutils literal"> <span class="pre"> /etc/mongod.conf </span> </code> ). These settings (such as the data directory and log directory specifications) take effect upon startup. That is, if you change the configuration file while the MongoDB instance is running, you must restart the instance for the changes to take effect. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Procedure <a class="headerlink leafygreen-ui-1kepx47" href="#procedure" 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="procedure"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Follow these steps to run MongoDB <!-- --> Community <!-- --> Edition on your system. These instructions assume that you are using the official <code class="leafygreen-ui-1l06pbn"> mongodb-org </code> package -- not the unofficial <code class="leafygreen-ui-1l06pbn"> mongodb </code> package provided by <!-- --> Ubuntu <!-- --> -- and are using the default settings. </p> <p class="leafygreen-ui-1kp3ins"> <strong> Init System </strong> </p> <p class="leafygreen-ui-1kp3ins"> To run and manage your <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process, you will be using your operating system's built-in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-init-system"> init system </a> . Recent versions of Linux tend to use <strong> systemd </strong> (which uses the <code class="leafygreen-ui-1l06pbn"> systemctl </code> command), while older versions of Linux tend to use <strong> System V init </strong> (which uses the <code class="leafygreen-ui-1l06pbn"> service </code> command). </p> <p class="leafygreen-ui-1kp3ins"> If you are unsure which init system your platform uses, run the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ps --no-headers -o comm 1","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">ps --no-headers -o <span class="lg-highlight-built_in">comm</span> 1</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"> Then select the appropriate tab below based on the result: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> systemd </code> - select the <strong> systemd (systemctl) </strong> tab below. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> init </code> - select the <strong> System V Init (service) </strong> tab below. </p> </li> </ul> <div class="line-block"> <div class="line"> <br/> </div> </div> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-32"> <div aria-label="Tabs to describe usage of systemd-systemctl/systemvinit-service" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_s0ox7mn38" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_4aqqg3ffd" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> systemd (systemctl) </div> </button> <button aria-controls="_jicj5fmuv" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_d9vnux7r5" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> System V Init (service) </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="_vs76ta9g5" class="" id="_plxr0jm4x" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Start MongoDB.You can start the mongod process by issuing the\nfollowing command:If you receive an error similar to the following when starting\nmongod:Failed to start mongod.service: Unit mongod.service not found.Run the following command first:Then run the start command above again."},{"@type":"HowToStep","text":"Verify that MongoDB has started successfully.You can optionally ensure that MongoDB will start following a\nsystem reboot by issuing the following command:"},{"@type":"HowToStep","text":"Stop MongoDB.As needed, you can stop the mongod process by issuing the\nfollowing command:"},{"@type":"HowToStep","text":"Restart MongoDB.You can restart the mongod process by issuing the following\ncommand:You can follow the state of the process for errors or important messages\nby watching the output in the /var/log/mongodb/mongod.log file."},{"@type":"HowToStep","text":"Begin using MongoDB.Start a mongosh session on the same host machine as the\nmongod. You can run mongosh\nwithout any command-line options to connect to a\nmongod that is running on your localhost with default\nport 27017.For more information on connecting using mongosh,\nsuch as to connect to a mongod instance running\non a different host and/or port, see the\nmongosh documentation.To help you start using MongoDB, MongoDB provides Getting\nStarted Guides in various driver editions. For the\ndriver documentation, see Start Developing with MongoDB."}],"name":"Procedure - systemd (systemctl)","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Start MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#start-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="start-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can start the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl start mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl start mongod</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"> If you receive an error similar to the following when starting <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> : </a> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> Failed to start mongod.service: Unit mongod.service not found. </code> </p> <p class="leafygreen-ui-1kp3ins"> Run the following command first: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl daemon-reload\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl daemon-reload</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"> Then run the start command above again. </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Verify that MongoDB has started successfully. <a class="headerlink leafygreen-ui-1kepx47" href="#verify-that-mongodb-has-started-successfully" 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="verify-that-mongodb-has-started-successfully"> </div> </a> </h4> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl status mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl status mongod</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"> You can optionally ensure that MongoDB will start following a system reboot by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl enable mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl enable mongod</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Stop MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#stop-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="stop-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> As needed, you can stop the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl stop mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl stop mongod</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Restart MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#restart-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="restart-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> You can restart the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl restart mongod\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl restart mongod</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"> You can follow the state of the process for errors or important messages by watching the output in the <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb/mongod.log </code> file. </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 5 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Begin using MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#begin-using-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="begin-using-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Start a <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> session on the same host machine as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> . You can run <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> without any command-line options to 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> that is running on your localhost with default port 27017. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\nmongosh\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh</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"> For more information on connecting using <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> , such as to 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> instance running on a different host and/or port, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self"> <span> mongosh documentation <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> To help you start using MongoDB, MongoDB provides <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/getting-started/#std-label-getting-started"> Getting Started Guides </a> in various driver editions. For the driver documentation, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://api.mongodb.com/" target="_self"> <span> Start Developing with MongoDB <!-- --> . </span> </a> </p> </section> </div> </div> </div> </div> </div> </div> <div> <div aria-labelledby="_ry1252mcf" class="leafygreen-ui-38lglc" id="_dbhufo5nc" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Start MongoDB.Issue the following command to start mongod:"},{"@type":"HowToStep","text":"Verify that MongoDB has started successfullyVerify that the mongod process has started\nsuccessfully:You can also check the log file for the current status of the\nmongod process, located at:\n/var/log/mongodb/mongod.log by default. A running\nmongod instance will indicate that it is ready for\nconnections with the following line:[initandlisten] waiting for connections on port 27017"},{"@type":"HowToStep","text":"Stop MongoDB.As needed, you can stop the mongod process by issuing the\nfollowing command:"},{"@type":"HowToStep","text":"Restart MongoDB.Issue the following command to restart mongod:"},{"@type":"HowToStep","text":"Begin using MongoDB.Start a mongosh session on the same host machine as the\nmongod. You can run mongosh\nwithout any command-line options to connect to a\nmongod that is running on your localhost with default\nport 27017.For more information on connecting using mongosh,\nsuch as to connect to a mongod instance running\non a different host and/or port, see the\nmongosh documentation.To help you start using MongoDB, MongoDB provides Getting\nStarted Guides in various driver editions. For the\ndriver documentation, see Start Developing with MongoDB."}],"name":"Procedure - System V Init (service)","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Start MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#start-mongodb-1" 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="start-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Issue the following command to start <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod start\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod start</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Verify that MongoDB has started successfully <a class="headerlink leafygreen-ui-1kepx47" href="#verify-that-mongodb-has-started-successfully-1" 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="verify-that-mongodb-has-started-successfully-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Verify that the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process has started successfully: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod status\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod status</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"> You can also check the log file for the current status of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process, located at: <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb/mongod.log </code> by default. A running <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instance will indicate that it is ready for connections with the following line: </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> [initandlisten] waiting for connections on port 27017 </code> </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Stop MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#stop-mongodb-1" 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="stop-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> As needed, you can stop the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod stop\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod stop</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Restart MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#restart-mongodb-1" 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="restart-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Issue the following command to restart <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod restart\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod restart</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 5 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Begin using MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#begin-using-mongodb-1" 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="begin-using-mongodb-1"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Start a <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> session on the same host machine as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> . You can run <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> without any command-line options to 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> that is running on your localhost with default port 27017. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\nmongosh\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh</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"> For more information on connecting using <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> , such as to 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> instance running on a different host and/or port, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self"> <span> mongosh documentation <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> To help you start using MongoDB, MongoDB provides <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/getting-started/#std-label-getting-started"> Getting Started Guides </a> in various driver editions. For the driver documentation, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://api.mongodb.com/" target="_self"> <span> Start Developing with MongoDB <!-- --> . </span> </a> </p> </section> </div> </div> </div> </div> </div> </div> </div> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Uninstall MongoDB Community Edition <a class="headerlink leafygreen-ui-1kepx47" href="#uninstall-mongodb-community-edition" 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="uninstall-mongodb-community-edition"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To completely remove MongoDB from a system, you must remove the MongoDB applications themselves, the configuration files, and any directories containing data and logs. The following section guides you through the necessary steps. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This process will <em> completely </em> remove MongoDB, its configuration, and <em> all </em> databases. This process is not reversible, so ensure that all of your configuration and data is backed up before proceeding. </p> </div> </div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Stop MongoDB.Stop the mongod process by issuing the following command:"},{"@type":"HowToStep","text":"Remove Packages.Remove any MongoDB packages that you had previously installed."},{"@type":"HowToStep","text":"Remove Data Directories.Remove MongoDB databases and log files."}],"name":"Uninstall MongoDB Community Edition","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Stop MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#stop-mongodb-2" 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="stop-mongodb-2"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Stop the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process by issuing the following command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod stop\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo service mongod stop</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Remove Packages. <a class="headerlink leafygreen-ui-1kepx47" href="#remove-packages" 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="remove-packages"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Remove any MongoDB packages that you had previously installed. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get purge mongodb-org*\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get purge mongodb-org*</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Remove Data Directories. <a class="headerlink leafygreen-ui-1kepx47" href="#remove-data-directories" 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="remove-data-directories"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Remove MongoDB databases and log files. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo rm -r /var/log/mongodb\nsudo rm -r /var/lib/mongodb\n","programmingLanguage":"Shell"} </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 shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo rm -r /var/log/mongodb</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sudo rm -r /var/lib/mongodb</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> </section> </div> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" 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> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Localhost Binding by Default <a class="headerlink leafygreen-ui-1kepx47" href="#localhost-binding-by-default" 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="localhost-binding-by-default"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> By default, MongoDB launches with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> set to <code class="leafygreen-ui-1l06pbn"> 127.0.0.1 </code> , which binds to the localhost network interface. This means that the <code class="leafygreen-ui-1l06pbn"> mongod </code> can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the <code class="leafygreen-ui-1l06pbn"> mongod </code> , and the <code class="leafygreen-ui-1l06pbn"> mongod </code> will not be able to initialize a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set"> replica set </a> unless this value is set to a valid network interface. </p> <p class="leafygreen-ui-1kp3ins"> This value can be configured either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> in the MongoDB configuration file with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> , or </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> via the command-line argument <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--bind_ip"> <code class="leafygreen-ui-1l06pbn"> --bind_ip </code> </a> </p> </li> </ul> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist"> Security Checklist for Self-Managed Deployments </a> . At minimum, consider <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-checklist-auth"> enabling authentication </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-hardening/#std-label-network-config-hardening"> hardening network infrastructure <!-- --> . </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> For more information on configuring <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> , see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-mongodb-configuration/"> IP Binding in Self-Managed Deployments <!-- --> . </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-ubuntu-package-content"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> MongoDB Community Edition Packages <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-community-edition-packages" 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="mongodb-community-edition-packages"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB Community Edition is available from its own dedicated repository, and contains the following officially-supported packages: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:25%"/> <col style="width:75%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Package Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> A <code class="leafygreen-ui-1l06pbn"> metapackage </code> that automatically installs the component packages listed below. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org-database </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> metapackage </code> that automatically installs the component packages listed below. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:50%"/> <col style="width:50%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Package Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org-server </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> daemon, associated init script, and a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-conf-file"> configuration file </a> ( <code class="leafygreen-ui-1l06pbn"> /etc/mongod.conf </code> ). You can use the initialization script to start <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> with the configuration file. For details, see the "Run MongoDB Community Edition" section, above. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org-mongos </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> daemon. </div> </div> </td> </tr> </tbody> </table> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-mongosh </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the MongoDB Shell ( <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> ). </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org-tools </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> metapackage </code> that automatically installs the component packages listed below: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:50%"/> <col style="width:50%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Package Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-database-tools </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Contains the following MongoDB database tools: </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/database-tools/mongodump/#mongodb-binary-bin.mongodump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongodump </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongorestore </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/bsondump/#mongodb-binary-bin.bsondump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> bsondump </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoimport </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoexport </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongostat/#mongodb-binary-bin.mongostat" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongostat </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongotop/#mongodb-binary-bin.mongotop" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongotop </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongofiles/#mongodb-binary-bin.mongofiles" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongofiles </code> </span> </a> </p> </li> </ul> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongodb-org-database-tools-extra </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/install_compass/#std-label-install-compass"> <code class="leafygreen-ui-1l06pbn"> install_compass </code> </a> script </div> </div> </td> </tr> </tbody> </table> </div> </div> </div> </td> </tr> </tbody> </table> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu-tarball/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Install MongoDB Community on Ubuntu using .tgz Tarball <a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-community-on-ubuntu-using-.tgz-tarball" 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="install-mongodb-community-on-ubuntu-using-.tgz-tarball"> </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="#overview" target="_self"> <span> Overview </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self"> <span> Considerations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#install-mongodb-community-edition" target="_self"> <span> Install MongoDB Community Edition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#run-mongodb-community-edition" target="_self"> <span> Run MongoDB Community Edition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-information" target="_self"> <span> Additional Information </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Overview <a class="headerlink leafygreen-ui-1kepx47" href="#overview" 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="overview"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Use this tutorial to manually install MongoDB 8.0 <!-- --> Community <!-- --> Edition on LTS (long-term support) releases of Ubuntu Linux using a downloaded <code class="leafygreen-ui-1l06pbn"> .tgz </code> tarball. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> MongoDB Version <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-version" 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="mongodb-version"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> This tutorial installs MongoDB 8.0 <!-- --> Community <!-- --> Edition. To install a different version of MongoDB <!-- --> Community <!-- --> , use the version drop-down menu in the upper-left corner of this page to select the documentation for that version. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Installation Method <a class="headerlink leafygreen-ui-1kepx47" href="#installation-method" 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="installation-method"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> While MongoDB can be installed manually via a downloaded <code class="leafygreen-ui-1l06pbn"> .tgz </code> tarball as described in this document, it is recommended to use the <code class="leafygreen-ui-1l06pbn"> apt </code> package manager on your system to install MongoDB if possible. Using a package manager automatically installs all needed dependencies, provides an example <code class="leafygreen-ui-1l06pbn"> mongod.conf </code> file to get you started, and simplifies future upgrade and maintenance tasks. </p> <p class="leafygreen-ui-1kp3ins"> ➤ <!-- --> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-ubuntu/"> Install MongoDB using the apt Package Manager </a> for instructions. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> MongoDB Shell, <code class="leafygreen-ui-1l06pbn"> mongosh </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-shell--mongosh" 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="mongodb-shell--mongosh"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> When you use the <code class="leafygreen-ui-1l06pbn"> .tgz </code> package to install the server, you need to follow the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/install/" target="_self"> <span> mongosh installation instructions </span> </a> to download and install <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self"> <span> mongosh </span> </a> separately. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Platform Support <a class="headerlink leafygreen-ui-1kepx47" href="#platform-support" 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="platform-support"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB 8.0 Community Edition supports the following <strong class="css-4dei7l"> 64-bit </strong> Ubuntu LTS (long-term support) releases on <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms-x86_64"> x86_64 </a> architecture: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> 24.04 <span class="leafygreen-ui-vm4wms" tabindex="0"> LTS </span> ("Noble") </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> 22.04 <span class="leafygreen-ui-vm4wms" tabindex="0"> LTS </span> ("Jammy") </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> 20.04 <span class="leafygreen-ui-vm4wms" tabindex="0"> LTS </span> ("Focal") </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> MongoDB only supports the 64-bit versions of these platforms. To determine which Ubuntu release your host is running, run the following command on the host's terminal: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"cat /etc/lsb-release","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">cat</span> <!-- -->/etc/lsb-release</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"> MongoDB 8.0 Community Edition on Ubuntu also supports the <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms-ARM64"> ARM64 </a> architecture on select platforms. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms"> Platform Support </a> for more information. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Production Notes <a class="headerlink leafygreen-ui-1kepx47" href="#production-notes" 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="production-notes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Before deploying MongoDB in a production environment, consider the <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/"> Production Notes for Self-Managed Deployments </a> document which offers performance considerations and configuration recommendations for production MongoDB deployments. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Install MongoDB Community Edition <a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-community-edition" 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="install-mongodb-community-edition"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Prerequisites <a class="headerlink leafygreen-ui-1kepx47" href="#prerequisites" 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="prerequisites"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Use the following command to install the dependencies required for the MongoDB <!-- --> Community <!-- --> <code class="leafygreen-ui-1l06pbn"> .tgz </code> tarball: </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-13"> <div aria-label="Tabs to describe usage of noble/ubuntu-20-focal/ubuntu-22-jammy" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_jdqajemtk" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_0kw5j6r16" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Ubuntu 24.04 (Noble) </div> </button> <button aria-controls="_24yyeuyvr" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_oey5i04t0" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Ubuntu 22.04 (Jammy) </div> </button> <button aria-controls="_56u58cqsp" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_hw3qh05u1" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Ubuntu 20.04 (Focal) </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="_7nxfx9sgj" class="" id="_xsl3quqdz" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get install libcurl4 libgssapi-krb5-2 libldap2 libwrap0 libsasl2-2 libsasl2-modules libsasl2-modules-gssapi-mit openssl liblzma5","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get install libcurl4 libgssapi-krb5-2 libldap2 libwrap0 libsasl2-2 libsasl2-modules libsasl2-modules-gssapi-mit openssl liblzma5</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="_pnw1m02uf" class="leafygreen-ui-38lglc" id="_w820kiijk" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get install libcurl4 libgssapi-krb5-2 libldap-2.5-0 libwrap0 libsasl2-2 libsasl2-modules libsasl2-modules-gssapi-mit openssl liblzma5","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get install libcurl4 libgssapi-krb5-2 libldap-2.5-0 libwrap0 libsasl2-2 libsasl2-modules libsasl2-modules-gssapi-mit openssl liblzma5</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="_0lql2uyfd" class="leafygreen-ui-38lglc" id="_bcabgigyi" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get install libcurl4 openssl liblzma5","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get install libcurl4 openssl liblzma5</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Procedure <a class="headerlink leafygreen-ui-1kepx47" href="#procedure" 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="procedure"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Follow these steps to manually install MongoDB <!-- --> Community <!-- --> Edition from the <code class="leafygreen-ui-1l06pbn"> .tgz </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Download the tarball.After you have installed the required prerequisite packages, download\nthe MongoDB Community tgz tarball from the following link:➤ MongoDB Download CenterIn the Version dropdown, select the version of\nMongoDB to download.In the Platform dropdown, select your operating system\nversion and architecture.In the Package dropdown, select tgz.Click Download."},{"@type":"HowToStep","text":"Extract the files from the downloaded archive.Using an archive manager program or the tar command, extract the\nfiles.For example, to extract from the terminal shell, you can use the\nfollowing tar command:If you downloaded a different MongoDB 8.0 point release,\nbe sure to modify the command to reflect the correct .tgz\nfile name."},{"@type":"HowToStep","text":"Optional. Ensure the binaries are in a directory listed in your PATH environment variable.The MongoDB binaries are in the <mongodb-install-directory>/bin/\ndirectory.To avoid having to specify the path to the MongoDB binaries, you can\ncreate symbolic links to the binaries from a directory listed in\nyour PATH variable, such as /usr/local/bin. Update\n/path/to/the/mongodb-directory/ with your installation\ndirectory as appropriate.Alternatively, you can copy these binaries into a directory listed\nin your PATH variable such as /usr/local/bin."},{"@type":"HowToStep","text":"Install the MongoDB Shell (mongosh).Install mongosh then use the MongoDB Shell\nto connect to your deployment.Download the package for the version of mongosh you need from the\nMongoDB Download Center and uncompress the package."}],"name":"Procedure","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Download the tarball. <a class="headerlink leafygreen-ui-1kepx47" href="#download-the-tarball" 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="download-the-tarball"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> After you have installed the required prerequisite packages, download the MongoDB <!-- --> Community <!-- --> <code class="leafygreen-ui-1l06pbn"> tgz </code> tarball from the following link: </p> <p class="leafygreen-ui-1kp3ins"> ➤ <!-- --> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/try/download/community?tck=docs_server" target="_self"> <span> MongoDB Download Center </span> </a> </p> <ol class="leafygreen-ui-rioki0" type="a"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> In the <span class="guilabel css-h15tq0"> Version </span> dropdown, select the version of MongoDB to download. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> In the <span class="guilabel css-h15tq0"> Platform </span> dropdown, select your operating system version and architecture. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> In the <span class="guilabel css-h15tq0"> Package </span> dropdown, select <span class="guilabel css-h15tq0"> tgz </span> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Click <span class="guilabel css-h15tq0"> Download </span> . </p> </li> </ol> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Extract the files from the downloaded archive. <a class="headerlink leafygreen-ui-1kepx47" href="#extract-the-files-from-the-downloaded-archive" 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="extract-the-files-from-the-downloaded-archive"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Using an archive manager program or the <code class="leafygreen-ui-1l06pbn"> tar </code> command, extract the files. </p> <p class="leafygreen-ui-1kp3ins"> For example, to extract from the terminal shell, you can use the following <code class="leafygreen-ui-1l06pbn"> tar </code> command: </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"> If you downloaded a different MongoDB 8.0 point release, be sure to modify the command to reflect the correct <code class="leafygreen-ui-1l06pbn"> .tgz </code> file name. </p> </div> </div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"tar -zxvf mongodb-linux-*-8.0.0.tgz","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">tar -zxvf mongodb-linux-*-8.0.0.tgz</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Optional. Ensure the binaries are in a directory listed in your <code class="leafygreen-ui-1l06pbn"> PATH </code> environment variable. <a class="headerlink leafygreen-ui-1kepx47" href="#optional-ensure-the-binaries-are-in-a-directory-listed-in-your-path-environment-variable" 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="optional-ensure-the-binaries-are-in-a-directory-listed-in-your-path-environment-variable"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> The MongoDB binaries are in the <code class="leafygreen-ui-1l06pbn"> &lt;mongodb-install-directory&gt;/bin/ </code> directory. </p> <p class="leafygreen-ui-1kp3ins"> To avoid having to specify the path to the MongoDB binaries, you can create symbolic links to the binaries from a directory listed in your <code class="leafygreen-ui-1l06pbn"> PATH </code> variable, such as <code class="leafygreen-ui-1l06pbn"> /usr/local/bin </code> . Update <code class="leafygreen-ui-1l06pbn"> /path/to/the/mongodb-directory/ </code> with your installation directory as appropriate. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo <span class="lg-highlight-built_in">ln</span> -s <!-- -->/path/to/the/mongodb-directory/bin<!-- -->/* <!-- -->/usr/local/bin<!-- -->/</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"> Alternatively, you can copy these binaries into a directory listed in your <code class="leafygreen-ui-1l06pbn"> PATH </code> variable such as <code class="leafygreen-ui-1l06pbn"> /usr/local/bin </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo cp &lt;mongodb-install-directory&gt;/bin/* /usr/local/bin/","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo <span class="lg-highlight-built_in">cp</span> &lt;mongodb-install-directory&gt;<!-- -->/bin<!-- -->/* <!-- -->/usr/local/bin<!-- -->/</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Install the MongoDB Shell ( <code class="leafygreen-ui-1l06pbn"> mongosh </code> ). <a class="headerlink leafygreen-ui-1kepx47" href="#install-the-mongodb-shell-mongosh" 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="install-the-mongodb-shell-mongosh"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/install/" target="_self"> <span> Install </span> </a> <code class="leafygreen-ui-1l06pbn"> mongosh </code> then use the MongoDB Shell to connect to your deployment. </p> <p class="leafygreen-ui-1kp3ins"> Download the package for the version of <code class="leafygreen-ui-1l06pbn"> mongosh </code> you need from the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/try/download/community?tck=docs_server" target="_self"> <span> MongoDB Download Center </span> </a> and uncompress the package. </p> </section> </div> </div> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Run MongoDB Community Edition <a class="headerlink leafygreen-ui-1kepx47" href="#run-mongodb-community-edition" 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="run-mongodb-community-edition"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> ulimit Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#ulimit-considerations" 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="ulimit-considerations"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/ulimit/"> UNIX <code class="leafygreen-ui-1l06pbn"> ulimit </code> Settings for Self-Managed Deployments </a> for the recommended settings for your platform. </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 the <code class="leafygreen-ui-1l06pbn"> ulimit </code> value for number of open files is under <code class="leafygreen-ui-1l06pbn"> 64000 </code> , MongoDB generates a startup warning. </p> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Configuration <a class="headerlink leafygreen-ui-1kepx47" href="#configuration" 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="configuration"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> You can configure the MongoDB instance (such as the data directory and log directory specifications) using either the command-line options or a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-conf-file"> configuration file <!-- --> . </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Procedure <a class="headerlink leafygreen-ui-1kepx47" href="#procedure-1" 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="procedure-1"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Follow these steps to run MongoDB <!-- --> Community <!-- --> Edition. These instructions assume that you are using the default settings. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create the data and log directories.Create a directory where the MongoDB instance stores its data. For\nexample:Create a directory where the MongoDB instance stores its log. For example:The user that starts the MongoDB process must have read and write\npermission to these directories. For example, if you intend to run\nMongoDB as yourself:"},{"@type":"HowToStep","text":"Run MongoDB.To run MongoDB, run the mongod process at the system prompt.For details on the command-line options --dbpath and --logpath, see\nOptions."},{"@type":"HowToStep","text":"Verify that MongoDB has started successfully.Verify that MongoDB has started successfully by\nchecking the process output for the following line in the\nlog file /var/log/mongodb/mongod.log:You may see non-critical warnings in the process\noutput. As long as you see the log line shown above, you can safely\nignore these warnings during your initial evaluation of MongoDB."},{"@type":"HowToStep","text":"Begin using MongoDB.Start a mongosh session on the same host machine as the\nmongod. You can run mongosh\nwithout any command-line options to connect to a\nmongod that is running on your localhost with default\nport 27017.For more information on connecting using mongosh,\nsuch as to connect to a mongod instance running\non a different host and/or port, see the\nmongosh documentation.To help you start using MongoDB, MongoDB provides Getting\nStarted Guides in various driver editions. For the\ndriver documentation, see Start Developing with MongoDB."}],"name":"Procedure","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Create the data and log directories. <a class="headerlink leafygreen-ui-1kepx47" href="#create-the-data-and-log-directories" 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-the-data-and-log-directories"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Create a directory where the MongoDB instance stores its data. For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo mkdir -p /var/lib/mongo","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo <span class="lg-highlight-built_in">mkdir</span> -p <!-- -->/var/lib/mongo</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"> Create a directory where the MongoDB instance stores its log. For example: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo mkdir -p /var/log/mongodb","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo <span class="lg-highlight-built_in">mkdir</span> -p <!-- -->/var/log/mongodb</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"> The user that starts the MongoDB process must have read and write permission to these directories. For example, if you intend to run MongoDB as yourself: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo chown `whoami` /var/lib/mongo # Or substitute another user\nsudo chown `whoami` /var/log/mongodb # Or substitute another user","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo <span class="lg-highlight-built_in">chown</span> `<span class="lg-highlight-built_in">whoami</span>` <!-- -->/var/lib/mongo<!-- --> <span class="lg-highlight-comment"># Or substitute another user</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">sudo <span class="lg-highlight-built_in">chown</span> `<span class="lg-highlight-built_in">whoami</span>` <!-- -->/var/log/mongodb<!-- --> <span class="lg-highlight-comment"># Or substitute another user</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Run MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#run-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="run-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> To run MongoDB, run the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> process at the system prompt. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --dbpath <!-- -->/var/lib/mongo<!-- --> --logpath <!-- -->/var/log/mongodb/mongod.log<!-- --> --fork</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"> For details on the command-line options <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--dbpath"> <code class="leafygreen-ui-1l06pbn"> --dbpath </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--logpath"> <code class="leafygreen-ui-1l06pbn"> --logpath </code> </a> , see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-label-mongod-options"> Options <!-- --> . </a> </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 3 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Verify that MongoDB has started successfully. <a class="headerlink leafygreen-ui-1kepx47" href="#verify-that-mongodb-has-started-successfully" 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="verify-that-mongodb-has-started-successfully"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Verify that MongoDB has started successfully by checking the process output for the following line in the log file <code class="leafygreen-ui-1l06pbn"> /var/log/mongodb/mongod.log </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[initandlisten] waiting for connections on port 27017\n"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[initandlisten] waiting for connections on port 27017</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> You may see non-critical warnings in the process output. As long as you see the log line shown above, you can safely ignore these warnings during your initial evaluation of MongoDB. </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 4 </div> </div> <div class="css-1ed38mk"> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Begin using MongoDB. <a class="headerlink leafygreen-ui-1kepx47" href="#begin-using-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="begin-using-mongodb"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Start a <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> session on the same host machine as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> . You can run <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> without any command-line options to 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> that is running on your localhost with default port 27017. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\nmongosh\n","programmingLanguage":"Shell"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh</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"> For more information on connecting using <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> , such as to 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> instance running on a different host and/or port, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self"> <span> mongosh documentation <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> To help you start using MongoDB, MongoDB provides <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/getting-started/#std-label-getting-started"> Getting Started Guides </a> in various driver editions. For the driver documentation, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://api.mongodb.com/" target="_self"> <span> Start Developing with MongoDB <!-- --> . </span> </a> </p> </section> </div> </div> </div> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" 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> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Localhost Binding by Default <a class="headerlink leafygreen-ui-1kepx47" href="#localhost-binding-by-default" 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="localhost-binding-by-default"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> By default, MongoDB launches with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> set to <code class="leafygreen-ui-1l06pbn"> 127.0.0.1 </code> , which binds to the localhost network interface. This means that the <code class="leafygreen-ui-1l06pbn"> mongod </code> can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the <code class="leafygreen-ui-1l06pbn"> mongod </code> , and the <code class="leafygreen-ui-1l06pbn"> mongod </code> will not be able to initialize a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set"> replica set </a> unless this value is set to a valid network interface. </p> <p class="leafygreen-ui-1kp3ins"> This value can be configured either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> in the MongoDB configuration file with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> , or </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> via the command-line argument <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--bind_ip"> <code class="leafygreen-ui-1l06pbn"> --bind_ip </code> </a> </p> </li> </ul> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist"> Security Checklist for Self-Managed Deployments </a> . At minimum, consider <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-checklist-auth"> enabling authentication </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-hardening/#std-label-network-config-hardening"> hardening network infrastructure <!-- --> . </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> For more information on configuring <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> bindIp </code> </a> , see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-mongodb-configuration/"> IP Binding in Self-Managed Deployments <!-- --> . </a> </p> </section> </section> </section>
https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Reference <a class="headerlink leafygreen-ui-1kepx47" href="#reference" 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="reference"> </div> </a> </h1> <p class="leafygreen-ui-1kp3ins"> Read the following sections to learn about components of Queryable Encryption: </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/queryable-encryption/reference/supported-operations/#std-label-qe-reference-automatic-encryption-supported-operations"> Supported Operations for Queryable Encryption </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/reference/qe-options-clients/#std-label-qe-reference-mongo-client"> MongoClient Options for Queryable Encryption </a> </p> </li> </ul> </section>
https://www.mongodb.com/docs/manual/reference/replica-states/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Replica Set Member States <a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-member-states" 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="replica-set-member-states"> </div> </a> </h1> <p class="leafygreen-ui-1kp3ins"> Each member of a replica set has a state. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:15%"/> <col style="width:25%"/> <col style="width:60%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Number </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> State Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 0 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.STARTUP" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> STARTUP </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Not yet an active member of any set. All members start up in this state. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> parses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/replica-set-member-configuration/"> replica set configuration document </a> while in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.STARTUP" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> STARTUP </code> . </span> </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 1 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.PRIMARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> PRIMARY </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The member in state <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-primary/#std-label-replica-set-primary"> primary </a> is the only member that can accept write operations. Eligible to vote. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.SECONDARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> SECONDARY </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> A member in state <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-secondary/#std-label-replica-set-secondary-members-ref"> secondary </a> is replicating the data store. Eligible to vote. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 3 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.RECOVERING" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> RECOVERING </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Members either perform startup self-checks, or transition from completing a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-rollbacks/#std-label-replica-set-rollbacks"> rollback </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/resync-replica-set-member/#std-label-resync-replica-member"> resync </a> . Data is not available for reads from this member. Eligible to vote. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 5 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.STARTUP2" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> STARTUP2 </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The member is running an initial sync. Eligible to vote, except when newly added to the replica set. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 6 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.UNKNOWN" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> UNKNOWN </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The member's state, as seen from another member of the set, is not yet known. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 7 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.ARBITER" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> ARBITER </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-members/#std-label-replica-set-arbiters"> Arbiters </a> do not replicate data and exist solely to participate in elections. Eligible to vote. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 8 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.DOWN" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> DOWN </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The member, as seen from another member of the set, is unreachable. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 9 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.ROLLBACK" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> ROLLBACK </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> This member is actively performing a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-rollbacks/#std-label-replica-set-rollbacks"> rollback </a> . Eligible to vote. Data is not available for reads from this member. </p> <p class="leafygreen-ui-1kp3ins"> Starting in version 4.2, MongoDB kills all in-progress user operations when a member enters the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.ROLLBACK" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> ROLLBACK </code> </span> </a> state. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 10 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.REMOVED" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> REMOVED </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> This member was once in a replica set but was subsequently removed. </div> </div> </td> </tr> </tbody> </table> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> States <a class="headerlink leafygreen-ui-1kepx47" href="#states" 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="states"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Core States <a class="headerlink leafygreen-ui-1kepx47" href="#core-states" 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="core-states"> </div> </a> </h3> <dl class="replstate"> <dt> <code class="leafygreen-ui-1l06pbn"> PRIMARY </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-replstate-replstate.PRIMARY" title="Permalink to this definition"> <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="mongodb-replstate-replstate.PRIMARY"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Members in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.PRIMARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> PRIMARY </code> </span> </a> state accept write operations. A replica set has at most one primary at a time. <a class="footnote-reference header-buffer" href="#footnote-edge-cases-2-primaries" id="ref-edge-cases-2-primaries-id1"> [ <!-- --> 1 <!-- --> ] </a> A <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.SECONDARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> SECONDARY </code> </span> </a> member becomes primary after an <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/#std-label-replica-set-elections"> election </a> . Members in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.PRIMARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> PRIMARY </code> </span> </a> state are eligible to vote. </p> </dd> </dl> <dl class="replstate"> <dt> <code class="leafygreen-ui-1l06pbn"> SECONDARY </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-replstate-replstate.SECONDARY" title="Permalink to this definition"> <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="mongodb-replstate-replstate.SECONDARY"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Members in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.SECONDARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> SECONDARY </code> </span> </a> state replicate the primary's data set and can be configured to accept read operations. Secondaries are eligible to vote in elections, and may be elected to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.PRIMARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> PRIMARY </code> </span> </a> state if the primary becomes unavailable. </p> </dd> </dl> <dl class="replstate"> <dt> <code class="leafygreen-ui-1l06pbn"> ARBITER </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-replstate-replstate.ARBITER" title="Permalink to this definition"> <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="mongodb-replstate-replstate.ARBITER"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Members in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.ARBITER" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> ARBITER </code> </span> </a> state do not replicate data or accept write operations. They are eligible to vote, and exist solely to break a tie during elections. Replica sets should only have a member in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.ARBITER" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> ARBITER </code> </span> </a> state if the set would otherwise have an even number of voting members, and could suffer from tied elections. There should only be at most one arbiter configured in any replica set. For considerations when using an arbiter, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-arbiter/"> Replica Set Arbiter <!-- --> . </a> </p> </dd> </dl> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-members/"> Replica Set Members </a> for more information on core states. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Other States <a class="headerlink leafygreen-ui-1kepx47" href="#other-states" 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="other-states"> </div> </a> </h3> <dl class="replstate"> <dt> <code class="leafygreen-ui-1l06pbn"> STARTUP </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-replstate-replstate.STARTUP" title="Permalink to this definition"> <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="mongodb-replstate-replstate.STARTUP"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Each member of a replica set starts up in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.STARTUP" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> STARTUP </code> </span> </a> state. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> then loads that member's replica set configuration, and transitions the member's state to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.STARTUP2" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> STARTUP2 </code> </span> </a> or <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.ARBITER" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> ARBITER </code> </span> </a> . Members in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.STARTUP" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> STARTUP </code> </span> </a> are not eligible to vote, as they are not yet a recognized member of any replica set. </p> </dd> </dl> <dl class="replstate"> <dt> <code class="leafygreen-ui-1l06pbn"> STARTUP2 </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-replstate-replstate.STARTUP2" title="Permalink to this definition"> <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="mongodb-replstate-replstate.STARTUP2"> </div> </a> </dt> <dd> <div> <p> <em> Changed <!-- --> in version <!-- --> 5.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Each data-bearing member of a replica set enters the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.STARTUP2" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> STARTUP2 </code> </span> </a> state as soon as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> finishes loading that member's configuration. </p> <p class="leafygreen-ui-1kp3ins"> The member then decides whether or not to undertake an initial sync. If a member begins an initial sync, the member remains in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.STARTUP2" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> STARTUP2 </code> </span> </a> until all data is copied and all indexes are built. Afterwards, the member transitions to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.RECOVERING" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> RECOVERING </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> Newly-added members in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.STARTUP2" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> STARTUP2 </code> </span> </a> are not eligible to vote and cannot be elected during the initial sync process. Prior to MongoDB 5.0, members in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.STARTUP2" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> STARTUP2 </code> </span> </a> were eligible to vote. </p> </dd> </dl> <dl class="replstate"> <dt> <code class="leafygreen-ui-1l06pbn"> RECOVERING </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-replstate-replstate.RECOVERING" title="Permalink to this definition"> <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="mongodb-replstate-replstate.RECOVERING"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A member of a replica set enters <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.RECOVERING" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> RECOVERING </code> </span> </a> state when it is not ready to accept reads. The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.RECOVERING" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> RECOVERING </code> </span> </a> state can occur during normal operation, and doesn't necessarily reflect an error condition. Members in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.RECOVERING" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> RECOVERING </code> </span> </a> state are eligible to vote in elections, but are not eligible to enter the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.PRIMARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> PRIMARY </code> </span> </a> state. </p> <p class="leafygreen-ui-1kp3ins"> A member transitions from <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.RECOVERING" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> RECOVERING </code> </span> </a> to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.SECONDARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> SECONDARY </code> </span> </a> after replicating enough data to guarantee a consistent view of the data for client reads. The only difference between <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.RECOVERING" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> RECOVERING </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.SECONDARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> SECONDARY </code> </span> </a> states is that <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.RECOVERING" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> RECOVERING </code> </span> </a> prohibits client reads and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.SECONDARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> SECONDARY </code> </span> </a> permits them. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.SECONDARY" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> SECONDARY </code> </span> </a> state does not guarantee anything about the staleness of the data with respect to the primary. </p> <p class="leafygreen-ui-1kp3ins"> Due to overload, a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary"> secondary </a> may fall far enough behind the other members of the replica set such that it may need to <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/resync-replica-set-member/"> resync </a> with the rest of the set. When this happens, the member enters the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.RECOVERING" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> RECOVERING </code> </span> </a> state and requires manual intervention. </p> </dd> </dl> <dl class="replstate"> <dt> <code class="leafygreen-ui-1l06pbn"> ROLLBACK </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-replstate-replstate.ROLLBACK" title="Permalink to this definition"> <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="mongodb-replstate-replstate.ROLLBACK"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Whenever the replica set replaces a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary"> primary </a> in an election, the old primary may contain documents that did not replicate to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary"> secondary </a> members. In this case, the old primary member reverts those writes. During <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-rollbacks/#std-label-replica-set-rollbacks"> rollback </a> , the member will have <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.ROLLBACK" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> ROLLBACK </code> </span> </a> state. Members in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.ROLLBACK" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> ROLLBACK </code> </span> </a> state are eligible to vote in elections. </p> <p class="leafygreen-ui-1kp3ins"> Starting in version 4.2, MongoDB kills all in-progress user operations when a member enters the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.ROLLBACK" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> ROLLBACK </code> </span> </a> state. </p> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Error States <a class="headerlink leafygreen-ui-1kepx47" href="#error-states" 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="error-states"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Members in any error state can't vote. </p> <dl class="replstate"> <dt> <code class="leafygreen-ui-1l06pbn"> UNKNOWN </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-replstate-replstate.UNKNOWN" title="Permalink to this definition"> <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="mongodb-replstate-replstate.UNKNOWN"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Members that have never communicated status information to the replica set are in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.UNKNOWN" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> UNKNOWN </code> </span> </a> state. </p> </dd> </dl> <dl class="replstate"> <dt> <code class="leafygreen-ui-1l06pbn"> DOWN </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-replstate-replstate.DOWN" title="Permalink to this definition"> <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="mongodb-replstate-replstate.DOWN"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Members that lose their connection to the replica set are seen as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.DOWN" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> DOWN </code> </span> </a> by the remaining members of the set. </p> </dd> </dl> <dl class="replstate"> <dt> <code class="leafygreen-ui-1l06pbn"> REMOVED </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-replstate-replstate.REMOVED" title="Permalink to this definition"> <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="mongodb-replstate-replstate.REMOVED"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Members that are removed from the replica set enter the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.REMOVED" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> REMOVED </code> </span> </a> state. When members enter the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-replstate-replstate.REMOVED" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> REMOVED </code> </span> </a> state, the logs will mark this event with a <code class="leafygreen-ui-1l06pbn"> replSet REMOVED </code> message entry. </p> </dd> </dl> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-edge-cases-2-primaries" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <a href="#ref-edge-cases-2-primaries-id1"> 1 </a> ] </td> <td class="leafygreen-ui-17r2xs0"> <!-- --> In <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-use-cases/#std-label-edge-cases"> some circumstances </a> , two nodes in a replica set may <em> transiently </em> believe that they are the primary, but at most, one of them will be able to complete writes with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> { w: "majority" } </code> </a> write concern. The node that can complete <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> { w: "majority" } </code> </a> writes is the current primary, and the other node is a former primary that has not yet recognized its demotion, typically due to a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-network-partition"> network partition </a> . When this occurs, clients that connect to the former primary may observe stale data despite having requested read preference <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-primary"> <code class="leafygreen-ui-1l06pbn"> primary </code> </a> , and new writes to the former primary will eventually roll back. </td> </tr> </tbody> </table> </section> </section> </section>
https://www.mongodb.com/docs/manual/core/replica-set-secondary/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Replica Set Secondary Members <a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-secondary-members" 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="replica-set-secondary-members"> </div> </a> </h1> <p class="leafygreen-ui-1kp3ins"> A secondary maintains a copy of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary"> primary's </a> data set. To replicate data, a secondary applies operations from the primary's <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-oplog/#std-label-replica-set-oplog"> oplog </a> to its own data set in an asynchronous process. <a class="footnote-reference header-buffer" href="#footnote-slow-oplogs" id="ref-slow-oplogs-id1"> [ <!-- --> 1 <!-- --> ] </a> A replica set can have one or more secondaries. </p> <p class="leafygreen-ui-1kp3ins"> The following three-member replica set has two secondary members. The secondaries replicate the primary's oplog and apply the operations to their data sets. </p> <div class="figure css-5vkxs0" style="width:700px"> <img alt="Diagram of a 3 member replica set that consists of a primary and two secondaries." class="leafygreen-ui-1qnf57e" height="280" src="/docs/manual/images/replica-set-primary-with-two-secondaries.bakedsvg.svg" style="--border-color:#C1C7C6" width="740"/> </div> <p class="leafygreen-ui-1kp3ins"> Although clients cannot write data to secondaries, clients can read data from secondary members. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/"> Read Preference </a> for more information on how clients direct read operations to replica sets. </p> <p class="leafygreen-ui-1kp3ins"> A secondary can become a primary. If the current primary becomes unavailable, the replica set holds an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-election"> election </a> to choose which of the secondaries becomes the new primary. </p> <p class="leafygreen-ui-1kp3ins"> In the following three-member replica set, the primary becomes unavailable. This triggers an election where one of the remaining secondaries becomes the new primary. </p> <div class="css-18h91be ej97su30"> <div role="button" tabindex="-1"> <img alt="Diagram of an election of a new primary. In a three member replica set with two secondaries, the primary becomes unreachable. The loss of a primary triggers an election where one of the secondaries becomes the new primary" class="leafygreen-ui-1qnf57e" height="500" src="/docs/manual/images/replica-set-trigger-election.bakedsvg.svg" style="--border-color:#C1C7C6" width="660"/> <div class="css-19pi7x2 ej97su31" style="--color:#444"> click to enlarge </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/"> Replica Set Elections </a> for more details. </p> <p class="leafygreen-ui-1kp3ins"> You can configure a secondary member for a specific purpose. You can configure a secondary to: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Prevent it from becoming a primary in an election, which allows it to reside in a secondary data center or to serve as a cold standby. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-priority-0-member/"> Priority 0 Replica Set Members <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Prevent applications from reading from it, which allows it to run applications that require separation from normal traffic. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-hidden-member/"> Hidden Replica Set Members <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Keep a running "historical" snapshot for use in recovery from certain errors, such as unintentionally deleted databases. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-delayed-member/"> Delayed Replica Set Members <!-- --> . </a> </p> </li> </ul> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-slow-oplogs" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <a href="#ref-slow-oplogs-id1"> 1 </a> ] </td> <td class="leafygreen-ui-17r2xs0"> <!-- --> Secondary members of a replica set now <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-oplog/#std-label-slow-oplog-application"> log oplog entries </a> that take longer than the slow operation threshold to apply. These slow oplog messages: <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> Are logged for the secondaries in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--logpath"> <code class="leafygreen-ui-1l06pbn"> diagnostic log </code> . </a> </li> <li class="leafygreen-ui-d7p7b6"> Are logged under the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-REPL"> <code class="leafygreen-ui-1l06pbn"> REPL </code> </a> component with the text <code class="leafygreen-ui-1l06pbn"> applied op: &lt;oplog entry&gt; took &lt;num&gt;ms </code> . </li> <li class="leafygreen-ui-d7p7b6"> Do not depend on the log levels (either at the system or component level) </li> <li class="leafygreen-ui-d7p7b6"> Do not depend on the profiling level. </li> <li class="leafygreen-ui-d7p7b6"> Are affected by <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-operationProfiling.slowOpSampleRate"> <code class="leafygreen-ui-1l06pbn"> slowOpSampleRate </code> . </a> </li> </ul> The profiler does not capture slow oplog entries. </td> </tr> </tbody> </table> </section>
https://www.mongodb.com/docs/manual/tutorial/aggregation-with-user-preference-data/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Aggregation with User Preference Data <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-with-user-preference-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="aggregation-with-user-preference-data"> </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="#data-model" target="_self"> <span> Data Model </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#return-a-single-field" target="_self"> <span> Return a Single Field </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#normalize-and-sort-documents" target="_self"> <span> Normalize and Sort Documents </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#return-usernames-ordered-by-join-month" target="_self"> <span> Return Usernames Ordered by Join Month </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#return-total-number-of-joins-per-month" target="_self"> <span> Return Total Number of Joins per Month </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#return-the-five-most-common--likes-" target="_self"> <span> Return the Five Most Common "Likes" </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Data Model <a class="headerlink leafygreen-ui-1kepx47" href="#data-model" 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="data-model"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Consider a sports club database with a <code class="leafygreen-ui-1l06pbn"> members </code> collection that tracks members' names, join dates, and sport preferences: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.insertMany( [\n {\n _id: \"jane\",\n joined: ISODate(\"2011-03-02\"),\n likes: [\"golf\", \"racquetball\"]\n },\n {\n _id: \"joe\",\n joined: ISODate(\"2012-07-02\"),\n likes: [\"tennis\", \"golf\", \"swimming\"]\n },\n {\n _id: \"ruth\",\n joined: ISODate(\"2012-01-14\"),\n likes: [\"golf\", \"racquetball\"]\n },\n {\n _id: \"harold\",\n joined: ISODate(\"2012-01-21\"),\n likes: [\"handball\", \"golf\", \"racquetball\"]\n },\n {\n _id: \"kate\",\n joined: ISODate(\"2012-01-14\"),\n likes: [\"swimming\", \"tennis\"]\n }\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">db.<span class="lg-highlight-property">members</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"jane"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2011-03-02"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"golf"</span>, <span class="lg-highlight-string">"racquetball"</span>]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"joe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2012-07-02"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"tennis"</span>, <span class="lg-highlight-string">"golf"</span>, <span class="lg-highlight-string">"swimming"</span>]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"ruth"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2012-01-14"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"golf"</span>, <span class="lg-highlight-string">"racquetball"</span>]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"harold"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2012-01-21"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"handball"</span>, <span class="lg-highlight-string">"golf"</span>, <span class="lg-highlight-string">"racquetball"</span>]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"kate"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2012-01-14"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"swimming"</span>, <span class="lg-highlight-string">"tennis"</span>]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Return a Single Field <a class="headerlink leafygreen-ui-1kepx47" href="#return-a-single-field" 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="return-a-single-field"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following operation uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> to return only the <code class="leafygreen-ui-1l06pbn"> _id </code> field for all documents in the <code class="leafygreen-ui-1l06pbn"> members </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.aggregate(\n [\n { $project: { _id: 1 } }\n ]\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">db.<span class="lg-highlight-property">members</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">_id</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">)</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"> The operation returns the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: 'jane' },\n { _id: 'joe' },\n { _id: 'ruth' },\n { _id: 'harold' },\n { _id: 'kate' }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'jane'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'joe'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'ruth'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'harold'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'kate'</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> For basic query and projection operations, standard queries with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find"> <code class="leafygreen-ui-1l06pbn"> find() </code> </a> method have the best performance. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Normalize and Sort Documents <a class="headerlink leafygreen-ui-1kepx47" href="#normalize-and-sort-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="normalize-and-sort-documents"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following operation returns member names in upper case and in alphabetical order. You might do this to normalize member names for processing. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.aggregate(\n [\n { $project: { name: { $toUpper: \"$_id\" }, _id: 0 } },\n { $sort: { name: 1 } }\n ]\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">db.<span class="lg-highlight-property">members</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <!-- -->{ <span class="lg-highlight-attr">$toUpper</span>: <span class="lg-highlight-string">"$_id"</span> }<!-- -->, <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-attr">name</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">)</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"> All documents from the <code class="leafygreen-ui-1l06pbn"> members </code> collection pass through the pipeline, which consists of the following operations: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> operator: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> creates a new field called <code class="leafygreen-ui-1l06pbn"> name </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> converts the value of the <code class="leafygreen-ui-1l06pbn"> _id </code> to upper case, with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/toUpper/#mongodb-expression-exp.-toUpper"> <code class="leafygreen-ui-1l06pbn"> $toUpper </code> </a> operator. Then the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> creates a new field, named <code class="leafygreen-ui-1l06pbn"> name </code> to hold this value. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> suppresses the <code class="leafygreen-ui-1l06pbn"> id </code> field. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> will pass the <code class="leafygreen-ui-1l06pbn"> _id </code> field by default, unless explicitly suppressed. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> operator orders the results by the <code class="leafygreen-ui-1l06pbn"> name </code> field. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The operation returns the following result: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { name: 'HAROLD' },\n { name: 'JANE' },\n { name: 'JOE' },\n { name: 'KATE' },\n { name: 'RUTH' }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'HAROLD'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'JANE'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'JOE'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'KATE'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'RUTH'</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Return Usernames Ordered by Join Month <a class="headerlink leafygreen-ui-1kepx47" href="#return-usernames-ordered-by-join-month" 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="return-usernames-ordered-by-join-month"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following aggregation operation returns member names sorted by the month they joined. You might use this aggregation to help generate membership renewal notices. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.aggregate( [\n {\n $project: {\n month_joined: { $month: \"$joined\" },\n name: \"$_id\",\n _id: 0\n }\n },\n { $sort: { month_joined: 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">db.<span class="lg-highlight-property">members</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">month_joined</span>: <!-- -->{ <span class="lg-highlight-attr">$month</span>: <span class="lg-highlight-string">"$joined"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"$_id"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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">month_joined</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> <p class="leafygreen-ui-1kp3ins"> The pipeline passes all documents in the <code class="leafygreen-ui-1l06pbn"> members </code> collection through the following operations: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> operator: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Creates two new fields: <code class="leafygreen-ui-1l06pbn"> month_joined </code> and <code class="leafygreen-ui-1l06pbn"> name </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Suppresses the <code class="leafygreen-ui-1l06pbn"> id </code> from the results. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> aggregate() </code> </a> method includes the <code class="leafygreen-ui-1l06pbn"> _id </code> , unless explicitly suppressed. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/month/#mongodb-expression-exp.-month"> <code class="leafygreen-ui-1l06pbn"> $month </code> </a> operator converts the values of the <code class="leafygreen-ui-1l06pbn"> joined </code> field to integer representations of the month. Then the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> operator assigns those values to the <code class="leafygreen-ui-1l06pbn"> month_joined </code> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> operator sorts the results by the <code class="leafygreen-ui-1l06pbn"> month_joined </code> field. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The operation returns the following result: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { month_joined: 1, name: 'ruth' },\n { month_joined: 1, name: 'harold' },\n { month_joined: 1, name: 'kate' },\n { month_joined: 3, name: 'jane' },\n { month_joined: 7, name: 'joe' }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'ruth'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'harold'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'kate'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'jane'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">7</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'joe'</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Return Total Number of Joins per Month <a class="headerlink leafygreen-ui-1kepx47" href="#return-total-number-of-joins-per-month" 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="return-total-number-of-joins-per-month"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following operation shows how many people joined each month of the year. You might use this aggregated data for recruiting and marketing strategies. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.aggregate( [\n { $project: { month_joined: { $month: \"$joined\" } } } ,\n { $group: { _id: { month_joined: \"$month_joined\" } , number: { $sum: 1 } } },\n { $sort: { \"_id.month_joined\": 1 } }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">members</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">$project</span>: <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <!-- -->{ <span class="lg-highlight-attr">$month</span>: <span class="lg-highlight-string">"$joined"</span> } } } <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-string">"$month_joined"</span> } <!-- -->, <span class="lg-highlight-attr">number</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-number">1</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-string">"_id.month_joined"</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> <p class="leafygreen-ui-1kp3ins"> The pipeline passes all documents in the <code class="leafygreen-ui-1l06pbn"> members </code> collection through the following operations: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> operator creates a new field called <code class="leafygreen-ui-1l06pbn"> month_joined </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/month/#mongodb-expression-exp.-month"> <code class="leafygreen-ui-1l06pbn"> $month </code> </a> operator converts the values of the <code class="leafygreen-ui-1l06pbn"> joined </code> field to integer representations of the month. Then the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> operator assigns the values to the <code class="leafygreen-ui-1l06pbn"> month_joined </code> field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> operator collects all documents with a given <code class="leafygreen-ui-1l06pbn"> month_joined </code> value and counts how many documents there are for that value. Specifically, for each unique value, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> creates a new "per-month" document with two fields: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> _id </code> , which contains a nested document with the <code class="leafygreen-ui-1l06pbn"> month_joined </code> field and its value. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> number </code> , which is a generated field. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> $sum </code> </a> operator increments this field by 1 for every document containing the given <code class="leafygreen-ui-1l06pbn"> month_joined </code> value. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> operator sorts the documents created by <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> according to the contents of the <code class="leafygreen-ui-1l06pbn"> month_joined </code> field. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The aggregation operation returns the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: { month_joined: 1 }, number: 3 },\n { _id: { month_joined: 3 }, number: 1 },\n { _id: { month_joined: 7 }, number: 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">3</span> }<!-- -->, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">7</span> }<!-- -->, <span class="lg-highlight-attr">number</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Return the Five Most Common "Likes" <a class="headerlink leafygreen-ui-1kepx47" href="#return-the-five-most-common--likes-" 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="return-the-five-most-common--likes-"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following aggregation collects the top five most "liked" activities in the data set. This type of analysis could help inform planning and future development. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.aggregate(\n [\n { $unwind: \"$likes\" },\n { $group: { _id: \"$likes\" , number: { $sum: 1 } } },\n { $sort: { number: -1 } },\n { $limit: 5 }\n ]\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">db.<span class="lg-highlight-property">members</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unwind</span>: <span class="lg-highlight-string">"$likes"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$likes"</span> <!-- -->, <span class="lg-highlight-attr">number</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-number">1</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-attr">number</span>: <!-- -->-<span class="lg-highlight-number">1</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$limit</span>: <span class="lg-highlight-number">5</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <p class="leafygreen-ui-1kp3ins"> The pipeline begins with all documents in the <code class="leafygreen-ui-1l06pbn"> members </code> collection, and passes these documents through the following operations: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unwind/#mongodb-pipeline-pipe.-unwind"> <code class="leafygreen-ui-1l06pbn"> $unwind </code> </a> operator separates each value in the <code class="leafygreen-ui-1l06pbn"> likes </code> array, and creates a new version of the source document for every element in the array. </p> <div class="leafygreen-ui-vg7qwp" role="note"> <h2 class="leafygreen-ui-2xicti"> Example </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Given the following document from the <code class="leafygreen-ui-1l06pbn"> members </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: \"jane\",\n joined: ISODate(\"2011-03-02\"),\n likes: [\"golf\", \"racquetball\"]\n}","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"jane"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2011-03-02"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"golf"</span>, <span class="lg-highlight-string">"racquetball"</span>]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unwind/#mongodb-pipeline-pipe.-unwind"> <code class="leafygreen-ui-1l06pbn"> $unwind </code> </a> operator outputs the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: \"jane\",\n joined: ISODate(\"2011-03-02\"),\n likes: \"golf\"\n}\n{\n _id: \"jane\",\n joined: ISODate(\"2011-03-02\"),\n likes: \"racquetball\"\n}","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"jane"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2011-03-02"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">likes</span>: <span class="lg-highlight-string">"golf"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"jane"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2011-03-02"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">likes</span>: <span class="lg-highlight-string">"racquetball"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> operator collects all documents with the same value for the <code class="leafygreen-ui-1l06pbn"> likes </code> field and counts each grouping. With this information, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> creates a new document with two fields: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> _id </code> , which contains the <code class="leafygreen-ui-1l06pbn"> likes </code> value. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> number </code> , which is a generated field. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> $sum </code> </a> operator increments this field by 1 for every document containing the given <code class="leafygreen-ui-1l06pbn"> likes </code> value. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> operator sorts these documents by the <code class="leafygreen-ui-1l06pbn"> number </code> field in reverse order. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/limit/#mongodb-pipeline-pipe.-limit"> <code class="leafygreen-ui-1l06pbn"> $limit </code> </a> operator only includes the first 5 result documents. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The aggregation operation returns the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: 'golf', number: 4 },\n { _id: 'racquetball', number: 3 },\n { _id: 'tennis', number: 2 },\n { _id: 'swimming', number: 2 },\n { _id: 'handball', number: 1 }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'golf'</span>, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'racquetball'</span>, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'tennis'</span>, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'swimming'</span>, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'handball'</span>, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $divide (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-divide--aggregation-" 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="-divide--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="expression"> <dt> <code class="leafygreen-ui-1l06pbn"> $divide </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-divide" title="Permalink to this definition"> <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="mongodb-expression-exp.-divide"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Divides one number by another and returns the result. Pass the arguments to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-divide" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $divide </code> </span> </a> in an array. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-divide" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $divide </code> </span> </a> expression has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $divide: [ &lt;expression1&gt;, &lt;expression2&gt; ] }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$divide</span>: <!-- -->[ &lt;<!-- -->expression1<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->expression2<!-- -->&gt; <!-- -->] }</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"> The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. </p> <p class="leafygreen-ui-1kp3ins"> The arguments can be any valid <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> expression </a> as long as they resolve to numbers. For more information on expressions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> Expression Operators <!-- --> . </a> </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The default return type is a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Double"> <code class="leafygreen-ui-1l06pbn"> double </code> </a> . If at least one operand is a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Decimal128"> <code class="leafygreen-ui-1l06pbn"> decimal </code> </a> , then the return type is a decimal. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Consider a <code class="leafygreen-ui-1l06pbn"> conferencePlanning </code> collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.conferencePlanning.insertMany( [\n { \"_id\" : 1, \"city\" : \"New York\", \"hours\" : 80, \"tasks\" : 7 },\n { \"_id\" : 2, \"city\" : \"Singapore\", \"hours\" : 40, \"tasks\" : 4 }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">conferencePlanning</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">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"city"</span> <!-- -->: <span class="lg-highlight-string">"New York"</span>, <span class="lg-highlight-string">"hours"</span> <!-- -->: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-string">"tasks"</span> <!-- -->: <span class="lg-highlight-number">7</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"city"</span> <!-- -->: <span class="lg-highlight-string">"Singapore"</span>, <span class="lg-highlight-string">"hours"</span> <!-- -->: <span class="lg-highlight-number">40</span>, <span class="lg-highlight-string">"tasks"</span> <!-- -->: <span class="lg-highlight-number">4</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-divide" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $divide </code> </span> </a> expression to divide the <code class="leafygreen-ui-1l06pbn"> hours </code> field by a literal <code class="leafygreen-ui-1l06pbn"> 8 </code> to compute the number of work days: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.planning.aggregate(\n [\n { $project: { city: 1, workdays: { $divide: [ \"$hours\", 8 ] } } }\n ]\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">planning</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">workdays</span>: <!-- -->{ <span class="lg-highlight-attr">$divide</span>: <!-- -->[ <span class="lg-highlight-string">"$hours"</span>, <span class="lg-highlight-number">8</span> ] } } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"city\" : \"New York\", \"workdays\" : 10 }\n{ \"_id\" : 2, \"city\" : \"Singapore\", \"workdays\" : 5 }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"city"</span> <!-- -->: <span class="lg-highlight-string">"New York"</span>, <span class="lg-highlight-string">"workdays"</span> <!-- -->: <span class="lg-highlight-number">10</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"city"</span> <!-- -->: <span class="lg-highlight-string">"Singapore"</span>, <span class="lg-highlight-string">"workdays"</span> <!-- -->: <span class="lg-highlight-number">5</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/core/aggregation-pipeline/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Aggregation Pipeline <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-pipeline" 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="aggregation-pipeline"> </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="#complete-aggregation-pipeline-examples" target="_self"> <span> Complete Aggregation Pipeline Examples </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-aggregation-pipeline-stage-details" target="_self"> <span> Additional Aggregation Pipeline Stage Details </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#run-an-aggregation-pipeline" target="_self"> <span> Run an Aggregation Pipeline </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#update-documents-using-an-aggregation-pipeline" target="_self"> <span> Update Documents Using an Aggregation Pipeline </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#other-considerations" target="_self"> <span> Other Considerations </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"> An aggregation pipeline consists of one or more <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference"> stages </a> that process documents: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Each stage performs an operation on the input documents. For example, a stage can filter documents, group documents, and calculate values. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The documents that are output from a stage are passed to the next stage. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> An aggregation pipeline can return results for groups of documents. For example, return the total, average, maximum, and minimum values. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You can update documents with an aggregation pipeline if you use the stages shown in <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/update-documents-with-aggregation-pipeline/#std-label-updates-agg-pipeline"> Updates with Aggregation Pipeline. </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"> Aggregation pipelines run with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> method do not modify documents in a collection, unless the pipeline contains a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out"> <code class="leafygreen-ui-1l06pbn"> $out </code> </a> stage. </p> </div> </div> <a class="css-53dzkk" href="https://www.mongodb.com/docs/atlas/atlas-ui/agg-pipeline"> <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/agg-pipeline/" target="_self"> <span> run aggregation pipelines 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> <p class="leafygreen-ui-1kp3ins"> When you run aggregation pipelines on MongoDB Atlas deployments in the MongoDB Atlas UI, you can preview the results at each stage. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-aggregation-pipeline-examples"> </span> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Complete Aggregation Pipeline Examples <a class="headerlink leafygreen-ui-1kepx47" href="#complete-aggregation-pipeline-examples" 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="complete-aggregation-pipeline-examples"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This section shows aggregation pipeline examples that use the following pizza <code class="leafygreen-ui-1l06pbn"> orders </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.orders.insertMany( [\n { _id: 0, name: \"Pepperoni\", size: \"small\", price: 19,\n quantity: 10, date: ISODate( \"2021-03-13T08:14:30Z\" ) },\n { _id: 1, name: \"Pepperoni\", size: \"medium\", price: 20,\n quantity: 20, date : ISODate( \"2021-03-13T09:13:24Z\" ) },\n { _id: 2, name: \"Pepperoni\", size: \"large\", price: 21,\n quantity: 30, date : ISODate( \"2021-03-17T09:22:12Z\" ) },\n { _id: 3, name: \"Cheese\", size: \"small\", price: 12,\n quantity: 15, date : ISODate( \"2021-03-13T11:21:39.736Z\" ) },\n { _id: 4, name: \"Cheese\", size: \"medium\", price: 13,\n quantity:50, date : ISODate( \"2022-01-12T21:23:13.331Z\" ) },\n { _id: 5, name: \"Cheese\", size: \"large\", price: 14,\n quantity: 10, date : ISODate( \"2022-01-12T05:08:13Z\" ) },\n { _id: 6, name: \"Vegan\", size: \"small\", price: 17,\n quantity: 10, date : ISODate( \"2021-01-13T05:08:13Z\" ) },\n { _id: 7, name: \"Vegan\", size: \"medium\", price: 18,\n quantity: 10, date : ISODate( \"2021-01-13T05:10:13Z\" ) }\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">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-attr">_id</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Pepperoni"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"small"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">19</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-03-13T08:14:30Z"</span> ) },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Pepperoni"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"medium"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">20</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">20</span>, date : <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-03-13T09:13:24Z"</span> ) },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Pepperoni"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"large"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">21</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">30</span>, date : <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-03-17T09:22:12Z"</span> ) },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"small"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">12</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">15</span>, date : <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-03-13T11:21:39.736Z"</span> ) },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"medium"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">13</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quantity</span>:<span class="lg-highlight-number">50</span>, date : <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2022-01-12T21:23:13.331Z"</span> ) },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Cheese"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"large"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">14</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">10</span>, date : <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2022-01-12T05:08:13Z"</span> ) },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Vegan"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"small"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">17</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">10</span>, date : <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-01-13T05:08:13Z"</span> ) },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">7</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Vegan"</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"medium"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">18</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">10</span>, date : <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-01-13T05:10:13Z"</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> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Calculate Total Order Quantity <a class="headerlink leafygreen-ui-1kepx47" href="#calculate-total-order-quantity" 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="calculate-total-order-quantity"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following aggregation pipeline example contains two <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference"> stages </a> and returns the total order quantity of medium size pizzas grouped by pizza name: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.orders.aggregate( [\n\n // Stage 1: Filter pizza order documents by pizza size\n {\n $match: { size: \"medium\" }\n },\n\n // Stage 2: Group remaining documents by pizza name and calculate total quantity\n {\n $group: { _id: \"$name\", totalQuantity: { $sum: \"$quantity\" } }\n }\n\n] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">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"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-comment">// Stage 1:</span><span class="lg-highlight-comment"> Filter pizza order </span><span class="lg-highlight-comment">documents by pizza size</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$match</span>: { <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-string">"medium"</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"> <span class="lg-highlight-comment">// Stage 2:</span><span class="lg-highlight-comment"> Group remaining documents </span><span class="lg-highlight-comment">by</span><span class="lg-highlight-comment"> pizza name and </span><span class="lg-highlight-comment">calculate total quantity</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$group</span>: { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$name"</span>, <span class="lg-highlight-attr">totalQuantity</span>: { <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$quantity"</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">] )</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"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> stage: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Filters the pizza order documents to pizzas with a <code class="leafygreen-ui-1l06pbn"> size </code> of <code class="leafygreen-ui-1l06pbn"> medium </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Passes the remaining documents to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Groups the remaining documents by pizza <code class="leafygreen-ui-1l06pbn"> name </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> $sum </code> </a> to calculate the total order <code class="leafygreen-ui-1l06pbn"> quantity </code> for each pizza <code class="leafygreen-ui-1l06pbn"> name </code> . The total is stored in the <code class="leafygreen-ui-1l06pbn"> totalQuantity </code> field returned by the aggregation pipeline. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Example output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: 'Cheese', totalQuantity: 50 },\n { _id: 'Vegan', totalQuantity: 10 },\n { _id: 'Pepperoni', totalQuantity: 20 }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'Cheese'</span>, <span class="lg-highlight-attr">totalQuantity</span>: <span class="lg-highlight-number">50</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'Vegan'</span>, <span class="lg-highlight-attr">totalQuantity</span>: <span class="lg-highlight-number">10</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'Pepperoni'</span>, <span class="lg-highlight-attr">totalQuantity</span>: <span class="lg-highlight-number">20</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Calculate Total Order Value and Average Order Quantity <a class="headerlink leafygreen-ui-1kepx47" href="#calculate-total-order-value-and-average-order-quantity" 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="calculate-total-order-value-and-average-order-quantity"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following example calculates the total pizza order value and average order quantity between two dates: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.orders.aggregate( [\n\n // Stage 1: Filter pizza order documents by date range\n {\n $match:\n {\n \"date\": { $gte: new ISODate( \"2020-01-30\" ), $lt: new ISODate( \"2022-01-30\" ) }\n }\n },\n\n // Stage 2: Group remaining documents by date and calculate results\n {\n $group:\n {\n _id: { $dateToString: { format: \"%Y-%m-%d\", date: \"$date\" } },\n totalOrderValue: { $sum: { $multiply: [ \"$price\", \"$quantity\" ] } },\n averageOrderQuantity: { $avg: \"$quantity\" }\n }\n },\n\n // Stage 3: Sort documents by totalOrderValue in descending order\n {\n $sort: { totalOrderValue: -1 }\n }\n\n ] )","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">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"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-comment">// Stage 1:</span><span class="lg-highlight-comment"> Filter pizza order </span><span class="lg-highlight-comment">documents by date range</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$match</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span>: { <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2020-01-30"</span> ), <span class="lg-highlight-attr">$lt</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2022-01-30"</span> ) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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"> <span class="lg-highlight-comment">// Stage 2:</span><span class="lg-highlight-comment"> Group remaining documents </span><span class="lg-highlight-comment">by</span><span class="lg-highlight-comment"> date and calculate </span><span class="lg-highlight-comment">results</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$group</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: { <span class="lg-highlight-attr">$dateToString</span>: { <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d"</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</span> } },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">totalOrderValue</span>: { <span class="lg-highlight-attr">$sum</span>: { <span class="lg-highlight-attr">$multiply</span>: [ <span class="lg-highlight-string">"$price"</span>, <span class="lg-highlight-string">"$quantity"</span> ] } },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">averageOrderQuantity</span>: { <span class="lg-highlight-attr">$avg</span>: <span class="lg-highlight-string">"$quantity"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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"> <span class="lg-highlight-comment">// Stage 3: Sort documents by totalOrderValue in descending order</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">totalOrderValue</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"> ] )</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"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> stage: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Filters the pizza order documents to those in a date range specified using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/gte/#mongodb-expression-exp.-gte"> <code class="leafygreen-ui-1l06pbn"> $gte </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lt/#mongodb-expression-exp.-lt"> <code class="leafygreen-ui-1l06pbn"> $lt </code> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Passes the remaining documents to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Groups the documents by date using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/dateToString/#mongodb-expression-exp.-dateToString"> <code class="leafygreen-ui-1l06pbn"> $dateToString </code> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For each group, calculates: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Total order value using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum"> <code class="leafygreen-ui-1l06pbn"> $sum </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/multiply/#mongodb-expression-exp.-multiply"> <code class="leafygreen-ui-1l06pbn"> $multiply </code> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Average order quantity using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/avg/#mongodb-group-grp.-avg"> <code class="leafygreen-ui-1l06pbn"> $avg </code> . </a> </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Passes the grouped documents to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> stage. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> stage: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Sorts the documents by the total order value for each group in descending order ( <code class="leafygreen-ui-1l06pbn"> -1 </code> ). </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Returns the sorted documents. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Example output: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: '2022-01-12', totalOrderValue: 790, averageOrderQuantity: 30 },\n { _id: '2021-03-13', totalOrderValue: 770, averageOrderQuantity: 15 },\n { _id: '2021-03-17', totalOrderValue: 630, averageOrderQuantity: 30 },\n { _id: '2021-01-13', totalOrderValue: 350, averageOrderQuantity: 10 }\n]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'2022-01-12'</span>, <span class="lg-highlight-attr">totalOrderValue</span>: <span class="lg-highlight-number">790</span>, <span class="lg-highlight-attr">averageOrderQuantity</span>: <span class="lg-highlight-number">30</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'2021-03-13'</span>, <span class="lg-highlight-attr">totalOrderValue</span>: <span class="lg-highlight-number">770</span>, <span class="lg-highlight-attr">averageOrderQuantity</span>: <span class="lg-highlight-number">15</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'2021-03-17'</span>, <span class="lg-highlight-attr">totalOrderValue</span>: <span class="lg-highlight-number">630</span>, <span class="lg-highlight-attr">averageOrderQuantity</span>: <span class="lg-highlight-number">30</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'2021-01-13'</span>, <span class="lg-highlight-attr">totalOrderValue</span>: <span class="lg-highlight-number">350</span>, <span class="lg-highlight-attr">averageOrderQuantity</span>: <span class="lg-highlight-number">10</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre> </div> </div> </div> <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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/aggregation-with-user-preference-data/"> Aggregation with User Preference Data </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/aggregation-zip-code-data-set/"> Aggregation with the Zip Code Data Set </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/update-documents-with-aggregation-pipeline/"> Updates with Aggregation Pipeline </a> </p> </li> </ul> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-aggregation-pipeline-stages-details"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Additional Aggregation Pipeline Stage Details <a class="headerlink leafygreen-ui-1kepx47" href="#additional-aggregation-pipeline-stage-details" 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-aggregation-pipeline-stage-details"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> An aggregation pipeline consists of one or more <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference"> stages </a> that process documents: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A stage does not have to output one document for every input document. For example, some stages may produce new documents or filter out documents. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The same stage can appear multiple times in the pipeline with these stage exceptions: <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out"> <code class="leafygreen-ui-1l06pbn"> $out </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear"> <code class="leafygreen-ui-1l06pbn"> $geoNear </code> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To calculate averages and perform other calculations in a stage, use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> aggregation expressions </a> that specify <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expression-operators"> aggregation operators </a> . You will learn more about aggregation expressions in the next section. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For all aggregation stages, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference"> Aggregation Stages. </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-aggregation-pipeline-expressions"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Aggregation Expressions and Operators <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-expressions-and-operators" 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="aggregation-expressions-and-operators"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Some aggregation pipeline stages accept <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-expression"> expressions </a> . Operators calculate values based on input expressions. </p> <p class="leafygreen-ui-1kp3ins"> In the MongoDB Query Language, you can build expressions from the following components: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width: 10%;"/> <col style="width: 10%;"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Component </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Example </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Constants </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> 3 </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Operators </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/add/#mongodb-expression-exp.-add"> <code class="leafygreen-ui-1l06pbn"> $add </code> </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Field path expressions </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> "$&lt;path.to.field&gt;" </code> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> For example, <code class="leafygreen-ui-1l06pbn"> { $add: [ 3, "$inventory.total" ] } </code> is an expression consisting of the <code class="leafygreen-ui-1l06pbn"> $add </code> operator and two input expressions: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The constant <code class="leafygreen-ui-1l06pbn"> 3 </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-quick-ref-field-paths" target="_self"> <span> field path expression </span> </a> <code class="leafygreen-ui-1l06pbn"> "$inventory.total" </code> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The expression returns the result of adding 3 to the value at path <code class="leafygreen-ui-1l06pbn"> inventory.total </code> of the input document. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-agg-quick-ref-field-paths"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Field Paths <a class="headerlink leafygreen-ui-1kepx47" href="#field-paths" 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="field-paths"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-field-path"> Field path </a> expressions are used to access fields in input documents. To specify a field path, prefix the field name or the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/document/#std-label-document-dot-notation"> dotted field name </a> (if the field is in an embedded document) with a dollar sign <code class="leafygreen-ui-1l06pbn"> $ </code> . For example, <code class="leafygreen-ui-1l06pbn"> "$user" </code> to specify the field path for the <code class="leafygreen-ui-1l06pbn"> user </code> field or <code class="leafygreen-ui-1l06pbn"> "$user.name" </code> to specify the field path to the embedded <code class="leafygreen-ui-1l06pbn"> "user.name" </code> field. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "$&lt;field&gt;" </code> is equivalent to <code class="leafygreen-ui-1l06pbn"> "$$CURRENT.&lt;field&gt;" </code> where the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.CURRENT"> <code class="leafygreen-ui-1l06pbn"> CURRENT </code> </a> is a system variable that defaults to the root of the current object, unless stated otherwise in specific stages. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Run an Aggregation Pipeline <a class="headerlink leafygreen-ui-1kepx47" href="#run-an-aggregation-pipeline" 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="run-an-aggregation-pipeline"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To run an aggregation pipeline, use: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> or </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate"> <code class="leafygreen-ui-1l06pbn"> aggregate </code> </a> </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-aggregation-update-documents"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Update Documents Using an Aggregation Pipeline <a class="headerlink leafygreen-ui-1kepx47" href="#update-documents-using-an-aggregation-pipeline" 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="update-documents-using-an-aggregation-pipeline"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To update documents with an aggregation pipeline, use: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Command </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <code class="leafygreen-ui-1l06pbn"> mongosh </code> Methods </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/findAndModify/#mongodb-dbcommand-dbcmd.findAndModify"> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#std-label-findOneAndUpdate-agg-pipeline"> db.collection.findOneAndUpdate() </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#std-label-findAndModify-agg-pipeline"> db.collection.findAndModify() </a> </div> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/update/#mongodb-dbcommand-dbcmd.update"> <code class="leafygreen-ui-1l06pbn"> update </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#std-label-updateOne-example-agg"> db.collection.updateOne() </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#std-label-updateMany-example-agg"> db.collection.updateMany() </a> </div> </div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.update/#std-label-example-bulk-find-update-agg"> Bulk.find.update() </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.updateOne/#std-label-example-bulk-find-update-one-agg"> Bulk.find.updateOne() </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.upsert/#std-label-bulk-find-upsert-update-agg-example"> Bulk.find.upsert() </a> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Other Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#other-considerations" 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="other-considerations"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Aggregation Pipeline Limitations <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-pipeline-limitations" 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="aggregation-pipeline-limitations"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> An aggregation pipeline has limitations on the value types and the result size. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline-limits/"> Aggregation Pipeline Limits. </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Aggregation Pipelines and Sharded Collections <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-pipelines-and-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="aggregation-pipelines-and-sharded-collections"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> An aggregation pipeline supports operations on sharded collections. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline-sharded-collections/#std-label-aggregation-pipeline-sharded-collection"> Aggregation Pipeline and Sharded Collections. </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Aggregation Pipelines as an Alternative to Map-Reduce <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-pipelines-as-an-alternative-to-map-reduce" 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="aggregation-pipelines-as-an-alternative-to-map-reduce"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce"> map-reduce </a> is deprecated: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Instead of <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce"> map-reduce </a> , you should use an <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-aggregation-pipeline" target="_self"> <span> aggregation pipeline </span> </a> . Aggregation pipelines provide better performance and usability than map-reduce. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You can rewrite map-reduce operations using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference"> aggregation pipeline stages </a> , such as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> , and others. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For map-reduce operations that require custom functionality, you can use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator"> <code class="leafygreen-ui-1l06pbn"> $accumulator </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function"> <code class="leafygreen-ui-1l06pbn"> $function </code> </a> aggregation operators. You can use those operators to define custom aggregation expressions in JavaScript. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For examples of aggregation pipeline alternatives to map-reduce, see: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/map-reduce-to-aggregation-pipeline/"> Map-Reduce to Aggregation Pipeline </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/map-reduce-examples/"> Map-Reduce Examples </a> </p> </li> </ul> </section> </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> <p class="leafygreen-ui-1kp3ins"> To learn more about aggregation pipelines, see: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expression-operators"> Expression Operators </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference"> Aggregation Stages </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.practical-mongodb-aggregations.com" 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> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/reference/command/nav-atlas-search/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Atlas Search Database Commands <a class="headerlink leafygreen-ui-1kepx47" href="#atlas-search-database-commands" 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="atlas-search-database-commands"> </div> </a> </h1> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> For details on a specific command, including syntax and examples, click on the link to the command's reference page. </p> </div> </div> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> : <!-- --> <!-- --> ( <em> Also available starting in 6.0.7 </em> ) </p> </div> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/atlas-search-overview/#fts-indexes" target="_self"> <span> Atlas Search indexes </span> </a> let you query data in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self"> <span> Atlas Search </span> </a> . Atlas Search indexes enable performant text search queries by mapping search terms to the documents that contain those terms. </p> <p class="leafygreen-ui-1kp3ins"> Use the following database commands to manage Atlas Search indexes. </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command can only be run on a deployment hosted on <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/" target="_self"> <span> MongoDB Atlas </span> </a> , and is <strong> not supported </strong> in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/create-database-deployment/#std-label-atlas-choose-serverless" target="_self"> <span> serverless instances <!-- --> . </span> </a> </p> </div> </div> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/createSearchIndexes/#mongodb-dbcommand-dbcmd.createSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> createSearchIndexes </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Creates one or more <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/atlas-search-overview/#fts-indexes" target="_self"> <span> Atlas Search indexes </span> </a> on a specified collection. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/dropSearchIndex/#mongodb-dbcommand-dbcmd.dropSearchIndex"> <code class="leafygreen-ui-1l06pbn"> dropSearchIndex </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Deletes an existing <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/atlas-search-overview/#fts-indexes" target="_self"> <span> Atlas Search index </span> </a> . </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateSearchIndex/#mongodb-dbcommand-dbcmd.updateSearchIndex"> <code class="leafygreen-ui-1l06pbn"> updateSearchIndex </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Updates an existing <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/atlas-search-overview/#fts-indexes" target="_self"> <span> Atlas Search index </span> </a> . </p> </div> </div> </td> </tr> </tbody> </table> </div> </section>
https://www.mongodb.com/docs/manual/reference/program/mongos/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> <code class="leafygreen-ui-1l06pbn"> mongos </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongos" 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="mongos"> </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="#synopsis" target="_self"> <span> Synopsis </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self"> <span> Considerations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#options" target="_self"> <span> Options </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#core-options" target="_self"> <span> Core Options </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#sharded-cluster-options" target="_self"> <span> Sharded Cluster Options </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#tls-options" target="_self"> <span> TLS Options </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#audit-options" target="_self"> <span> Audit Options </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#profiler-options" target="_self"> <span> Profiler Options </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#ldap-authentication-and-authorization-options" target="_self"> <span> LDAP Authentication and Authorization Options </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#additional-options" target="_self"> <span> Additional Options </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Synopsis <a class="headerlink leafygreen-ui-1kepx47" href="#synopsis" 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="synopsis"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> For a <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/#std-label-sharding-sharded-cluster"> sharded cluster </a> , the <code class="leafygreen-ui-1l06pbn"> mongos </code> instances provide the interface between the client applications and the sharded cluster. The <code class="leafygreen-ui-1l06pbn"> mongos </code> instances route queries and write operations to the shards. From the perspective of the application, a <code class="leafygreen-ui-1l06pbn"> mongos </code> instance behaves identically to any other MongoDB instance. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Considerations <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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"> </div> </a> </h2> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Never change the name of the <code class="leafygreen-ui-1l06pbn"> mongos </code> binary. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> MongoDB <!-- --> disables support for TLS 1.0 encryption on systems where TLS 1.1+ is available. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-binary-bin.mongos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongos </code> </span> </a> binary cannot connect to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances whose <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv"> feature compatibility version (fCV) </a> is greater than that of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-binary-bin.mongos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongos </code> </span> </a> . For example, you cannot connect a MongoDB <!-- --> 5.0 <!-- --> version <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-binary-bin.mongos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongos </code> </span> </a> to a <!-- --> 8.0 <!-- --> sharded cluster with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv"> fCV </a> set to <!-- --> 8.0 <!-- --> . You can, however, connect a MongoDB <!-- --> 5.0 <!-- --> version <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-binary-bin.mongos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongos </code> </span> </a> to a <!-- --> 8.0 <!-- --> sharded cluster with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv"> fCV </a> set to <!-- --> 5.0 <!-- --> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> includes a <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/full-time-diagnostic-data-capture/#std-label-ftdc-stub"> Full Time Diagnostic Data Capture </a> mechanism to assist MongoDB engineers with troubleshooting deployments. If this thread fails, it terminates the originating process. To avoid the most common failures, confirm that the user running the process has permissions to create the FTDC <code class="leafygreen-ui-1l06pbn"> diagnostic.data </code> directory. For <code class="leafygreen-ui-1l06pbn"> mongod </code> the directory is within <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.dbPath"> <code class="leafygreen-ui-1l06pbn"> storage.dbPath </code> </a> . For <code class="leafygreen-ui-1l06pbn"> mongos </code> it is parallel to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-systemLog.path"> <code class="leafygreen-ui-1l06pbn"> systemLog.path </code> . </a> </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Options <a class="headerlink leafygreen-ui-1kepx47" href="#options" 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="options"> </div> </a> </h2> <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/reference/configuration-file-settings-command-line-options-mapping/#std-label-conf-file-command-line-mapping"> Self-Managed Configuration File Settings and Command-Line Options Mapping </a> </p> </div> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> MongoDB deprecates the SSL options and instead adds new corresponding TLS options. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> MongoDB adds <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterCAFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCAFile </code> </span> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.clusterCAFile"> <code class="leafygreen-ui-1l06pbn"> net.tls.clusterCAFile </code> . </a> </p> </li> </ul> </div> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> MongoDB 5.0 removes the <code class="leafygreen-ui-1l06pbn"> --serviceExecutor </code> command-line option and the corresponding <code class="leafygreen-ui-1l06pbn"> net.serviceExecutor </code> configuration option. </p> </li> </ul> </div> </div> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Core Options <a class="headerlink leafygreen-ui-1kepx47" href="#core-options" 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="core-options"> </div> </a> </h3> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --help, -h </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--help" title="Permalink to this definition"> <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="std-option-mongos.--help"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Returns information on the options and use of <code class="leafygreen-ui-1l06pbn"> mongos </code> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --version </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--version" title="Permalink to this definition"> <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="std-option-mongos.--version"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Returns the <code class="leafygreen-ui-1l06pbn"> mongos </code> release number. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --config &lt;filename&gt;, -f &lt;filename&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--config" title="Permalink to this definition"> <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="std-option-mongos.--config"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies a configuration file for runtime configuration options. The configuration file is the preferred method for runtime configuration of <code class="leafygreen-ui-1l06pbn"> mongos </code> . The options are equivalent to the command-line configuration options. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/"> Self-Managed Configuration File Options </a> for more information. </p> <p class="leafygreen-ui-1kp3ins"> Ensure the configuration file uses ASCII encoding. The <code class="leafygreen-ui-1l06pbn"> mongos </code> instance does not support configuration files with non-ASCII encoding, including UTF-8. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --configExpand &lt;none|rest|exec&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--configExpand" title="Permalink to this definition"> <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="std-option-mongos.--configExpand"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : none </p> <p class="leafygreen-ui-1kp3ins"> Enables using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/expansion-directives/#std-label-externally-sourced-values"> Expansion Directives </a> in configuration files. Expansion directives allow you to set externally sourced values for configuration file options. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--configExpand" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --configExpand </code> </span> </a> supports the following expansion directives: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:40%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> none </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Default. <code class="leafygreen-ui-1l06pbn"> mongos </code> does not expand expansion directives. <code class="leafygreen-ui-1l06pbn"> mongos </code> fails to start if any configuration file settings use expansion directives. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> rest </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongos </code> expands <code class="leafygreen-ui-1l06pbn"> __rest </code> expansion directives when parsing the configuration file. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> exec </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongos </code> expands <code class="leafygreen-ui-1l06pbn"> __exec </code> expansion directives when parsing the configuration file. </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> You can specify multiple expansion directives as a comma-separated list, for example: <code class="leafygreen-ui-1l06pbn"> rest, exec </code> . If the configuration file contains expansion directives not specified to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--configExpand" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --configExpand </code> </span> </a> , the <code class="leafygreen-ui-1l06pbn"> mongos </code> returns an error and terminates. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/expansion-directives/#std-label-externally-sourced-values"> Externally Sourced Configuration File Values for Self-Managed Deployments </a> for configuration files for more information on expansion directives. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --verbose, -v </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--verbose" title="Permalink to this definition"> <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="std-option-mongos.--verbose"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Increases the amount of internal reporting returned on standard output or in log files. Increase the verbosity with the <code class="leafygreen-ui-1l06pbn"> -v </code> form by including the option multiple times, for example: <code class="leafygreen-ui-1l06pbn"> -vvvvv </code> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --quiet </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--quiet" title="Permalink to this definition"> <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="std-option-mongos.--quiet"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Runs <code class="leafygreen-ui-1l06pbn"> mongos </code> in a quiet mode that attempts to limit the amount of output. </p> <p class="leafygreen-ui-1kp3ins"> This option suppresses: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> output from <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-database-command"> database commands </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> replication activity </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> connection accepted events </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> connection closed events </p> </li> </ul> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --port &lt;port&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--port" title="Permalink to this definition"> <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="std-option-mongos.--port"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : 27017 </p> <p class="leafygreen-ui-1kp3ins"> The TCP port on which the <code class="leafygreen-ui-1l06pbn"> mongos </code> instance listens for client connections. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> --port </code> option <!-- --> accepts a range of values between <code class="leafygreen-ui-1l06pbn"> 0 </code> and <code class="leafygreen-ui-1l06pbn"> 65535 </code> . Setting the port to <code class="leafygreen-ui-1l06pbn"> 0 </code> configures <code class="leafygreen-ui-1l06pbn"> mongos </code> to use an arbitrary port assigned by the operating system. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --bind_ip &lt;hostnames|ipaddresses|Unix domain socket paths&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--bind_ip" title="Permalink to this definition"> <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="std-option-mongos.--bind_ip"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : localhost </p> <p class="leafygreen-ui-1kp3ins"> The hostnames and/or IP addresses and/or full Unix domain socket paths on which <code class="leafygreen-ui-1l06pbn"> mongos </code> should listen for client connections. You may attach <code class="leafygreen-ui-1l06pbn"> mongos </code> to any interface. To bind to multiple addresses, enter a list of comma-separated values. </p> <div class="leafygreen-ui-vg7qwp" role="note"> <h2 class="leafygreen-ui-2xicti"> Example </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> localhost,/tmp/mongod.sock </strong> </h3> <div class="leafygreen-ui-9mycqc"> </div> </div> <p class="leafygreen-ui-1kp3ins"> You can specify both IPv4 and IPv6 addresses, or hostnames that resolve to an IPv4 or IPv6 address. </p> <div class="leafygreen-ui-vg7qwp" role="note"> <h2 class="leafygreen-ui-2xicti"> Example </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> localhost, 2001:0DB8:e132:ba26:0d5c:2774:e7f9:d513 </strong> </h3> <div class="leafygreen-ui-9mycqc"> </div> </div> <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 specifying an IPv6 address <em> or </em> a hostname that resolves to an IPv6 address to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--bind_ip" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --bind_ip </code> </span> </a> , you must start <code class="leafygreen-ui-1l06pbn"> mongos </code> with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ipv6" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ipv6 </code> </span> </a> to enable IPv6 support. Specifying an IPv6 address to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--bind_ip" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --bind_ip </code> </span> </a> does not enable IPv6 support. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> If specifying a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Link-local_address#IPv6" rel="noopener noreferrer"> <span> link-local IPv6 address </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> ( <code class="leafygreen-ui-1l06pbn"> fe80::/10 </code> ), you must append the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/IPv6_address#Scoped_literal_IPv6_addresses_(with_zone_index)" rel="noopener noreferrer"> <span> zone index </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> to that address (i.e. <code class="leafygreen-ui-1l06pbn"> fe80::&lt;address&gt;%&lt;adapter-name&gt; </code> ). </p> <div class="leafygreen-ui-vg7qwp" role="note"> <h2 class="leafygreen-ui-2xicti"> Example </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> localhost,fe80::a00:27ff:fee0:1fcf%enp0s3 </strong> </h3> <div class="leafygreen-ui-9mycqc"> </div> </div> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> To avoid configuration updates due to IP address changes, use DNS hostnames instead of IP addresses. It is particularly important to use a DNS hostname instead of an IP address when configuring replica set members or sharded cluster members. </p> <p class="leafygreen-ui-1kp3ins"> Use hostnames instead of IP addresses to configure clusters across a split network horizon. Starting in MongoDB 5.0, nodes that are only configured with an IP address fail startup validation and do not start. </p> </div> </div> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist"> Security Checklist for Self-Managed Deployments </a> . At minimum, consider <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-checklist-auth"> enabling authentication </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-hardening/#std-label-network-config-hardening"> hardening network infrastructure <!-- --> . </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> For more information about IP Binding, refer to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-mongodb-configuration/"> IP Binding in Self-Managed Deployments </a> documentation. </p> <p class="leafygreen-ui-1kp3ins"> To bind to all IPv4 addresses, enter <code class="leafygreen-ui-1l06pbn"> 0.0.0.0 </code> . </p> <p class="leafygreen-ui-1kp3ins"> To bind to all IPv4 and IPv6 addresses, enter <code class="leafygreen-ui-1l06pbn"> ::,0.0.0.0 </code> or an asterisk <code class="leafygreen-ui-1l06pbn"> "*" </code> (enclose the asterisk in quotes to avoid filename pattern expansion). Alternatively, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIpAll"> <code class="leafygreen-ui-1l06pbn"> net.bindIpAll </code> </a> setting. </p> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> --bind_ip </code> and <code class="leafygreen-ui-1l06pbn"> --bind_ip_all </code> are mutually exclusive. Specifying both options causes <code class="leafygreen-ui-1l06pbn"> mongos </code> to throw an error and terminate. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The command-line option <code class="leafygreen-ui-1l06pbn"> --bind </code> overrides the configuration file setting <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> net.bindIp </code> . </a> </p> </li> </ul> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --bind_ip_all </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--bind_ip_all" title="Permalink to this definition"> <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="std-option-mongos.--bind_ip_all"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> If specified, the <code class="leafygreen-ui-1l06pbn"> mongos </code> instance binds to all IPv4 addresses (i.e. <code class="leafygreen-ui-1l06pbn"> 0.0.0.0 </code> ). If <code class="leafygreen-ui-1l06pbn"> mongos </code> starts with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ipv6" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ipv6 </code> </span> </a> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--bind_ip_all" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --bind_ip_all </code> </span> </a> also binds to all IPv6 addresses (i.e. <code class="leafygreen-ui-1l06pbn"> :: </code> ). </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> mongos </code> only supports IPv6 if started with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ipv6" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ipv6 </code> </span> </a> . Specifying <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--bind_ip_all" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --bind_ip_all </code> </span> </a> alone does not enable IPv6 support. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist"> Security Checklist for Self-Managed Deployments </a> . At minimum, consider <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-checklist-auth"> enabling authentication </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-hardening/#std-label-network-config-hardening"> hardening network infrastructure <!-- --> . </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> For more information about IP Binding, refer to the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-mongodb-configuration/"> IP Binding in Self-Managed Deployments </a> documentation. </p> <p class="leafygreen-ui-1kp3ins"> Alternatively, you can set the <code class="leafygreen-ui-1l06pbn"> --bind_ip </code> option to <code class="leafygreen-ui-1l06pbn"> ::,0.0.0.0 </code> or to an asterisk <code class="leafygreen-ui-1l06pbn"> "*" </code> (enclose the asterisk in quotes to avoid filename pattern expansion). </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"> <code class="leafygreen-ui-1l06pbn"> --bind_ip </code> and <code class="leafygreen-ui-1l06pbn"> --bind_ip_all </code> are mutually exclusive. That is, you can specify one or the other, but not both. </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --listenBacklog &lt;number&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--listenBacklog" title="Permalink to this definition"> <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="std-option-mongos.--listenBacklog"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : Target system <code class="leafygreen-ui-1l06pbn"> SOMAXCONN </code> constant </p> <p class="leafygreen-ui-1kp3ins"> The maximum number of connections that can exist in the listen queue. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Consult your local system's documentation to understand the limitations and configuration requirements before using this parameter. </p> </div> </div> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> To prevent undefined behavior, specify a value for this parameter between <code class="leafygreen-ui-1l06pbn"> 1 </code> and the local system <code class="leafygreen-ui-1l06pbn"> SOMAXCONN </code> constant. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> The default value for the <code class="leafygreen-ui-1l06pbn"> listenBacklog </code> parameter is set at compile time to the target system <code class="leafygreen-ui-1l06pbn"> SOMAXCONN </code> constant. <code class="leafygreen-ui-1l06pbn"> SOMAXCONN </code> is the maximum valid value that is documented for the <em> backlog </em> parameter to the <em> listen </em> system call. </p> <p class="leafygreen-ui-1kp3ins"> Some systems may interpret <code class="leafygreen-ui-1l06pbn"> SOMAXCONN </code> symbolically, and others numerically. The actual <em> listen backlog </em> applied in practice may differ from any numeric interpretation of the <code class="leafygreen-ui-1l06pbn"> SOMAXCONN </code> constant or argument to <code class="leafygreen-ui-1l06pbn"> --listenBacklog </code> , and may also be constrained by system settings like <code class="leafygreen-ui-1l06pbn"> net.core.somaxconn </code> on Linux. </p> <p class="leafygreen-ui-1kp3ins"> Passing a value for the <code class="leafygreen-ui-1l06pbn"> listenBacklog </code> parameter that exceeds the <code class="leafygreen-ui-1l06pbn"> SOMAXCONN </code> constant for the local system is, by the letter of the standards, undefined behavior. Higher values may be silently integer truncated, may be ignored, may cause unexpected resource consumption, or have other adverse consequences. </p> <p class="leafygreen-ui-1kp3ins"> On systems with workloads that exhibit connection spikes, for which it is empirically known that the local system can honor higher values for the <em> backlog </em> parameter than the <code class="leafygreen-ui-1l06pbn"> SOMAXCONN </code> constant, setting the <code class="leafygreen-ui-1l06pbn"> listenBacklog </code> parameter to a higher value may reduce operation latency as observed by the client by reducing the number of connections which are forced into a backoff state. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --maxConns &lt;number&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--maxConns" title="Permalink to this definition"> <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="std-option-mongos.--maxConns"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The maximum number of simultaneous connections that <code class="leafygreen-ui-1l06pbn"> mongos </code> accepts. This setting has no effect if it is higher than your operating system's configured maximum connection tracking threshold. </p> <p class="leafygreen-ui-1kp3ins"> Do not assign too low of a value to this option, or you will encounter errors during normal application operation. </p> <p class="leafygreen-ui-1kp3ins"> This is particularly useful for a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-binary-bin.mongos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongos </code> </span> </a> if you have a client that creates multiple connections and allows them to timeout rather than closing them. </p> <p class="leafygreen-ui-1kp3ins"> In this case, set <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.maxIncomingConnections"> <code class="leafygreen-ui-1l06pbn"> maxIncomingConnections </code> </a> to a value slightly higher than the maximum number of connections that the client creates, or the maximum size of the connection pool. </p> <p class="leafygreen-ui-1kp3ins"> This setting prevents the <code class="leafygreen-ui-1l06pbn"> mongos </code> from causing connection spikes on the individual <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard"> shards </a> . Spikes like these may disrupt the operation and memory allocation of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster <!-- --> . </a> </p> </dd> </dl> <span class="leafygreen-ui-1qnjd6d" id="std-label-mongos-log-options-section"> </span> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --logpath &lt;path&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--logpath" title="Permalink to this definition"> <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="std-option-mongos.--logpath"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Sends all diagnostic logging information to a log file instead of to standard output or to the host's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-syslog"> syslog </a> system. MongoDB creates the log file at the path you specify. </p> <p class="leafygreen-ui-1kp3ins"> By default, MongoDB will move any existing log file rather than overwrite it. To instead append to the log file, set the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--logappend" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --logappend </code> </span> </a> option. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --syslog </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--syslog" title="Permalink to this definition"> <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="std-option-mongos.--syslog"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Sends all logging output to the host's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-syslog"> syslog </a> system rather than to standard output or to a log file ( <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--logpath" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --logpath </code> </span> </a> ). </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--syslog" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --syslog </code> </span> </a> option is not supported on Windows. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> syslog </code> daemon generates timestamps when it logs a message, not when MongoDB issues the message. This can lead to misleading timestamps for log entries, especially when the system is under heavy load. We recommend using the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--logpath" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --logpath </code> </span> </a> option for production systems to ensure accurate timestamps. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> MongoDB includes the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-components"> component </a> in its log messages to <code class="leafygreen-ui-1l06pbn"> syslog </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"... ACCESS [repl writer worker 5] Unsupported modification to roles collection ..."} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" 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">... ACCESS [repl writer worker 5] Unsupported modification to roles collection ...</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> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --syslogFacility &lt;string&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--syslogFacility" title="Permalink to this definition"> <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="std-option-mongos.--syslogFacility"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : user </p> <p class="leafygreen-ui-1kp3ins"> Specifies the facility level used when logging messages to syslog. The value you specify must be supported by your operating system's implementation of syslog. To use this option, you must enable the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--syslog" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --syslog </code> </span> </a> option. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --logappend </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--logappend" title="Permalink to this definition"> <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="std-option-mongos.--logappend"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Appends new entries to the end of the existing log file when the <code class="leafygreen-ui-1l06pbn"> mongos </code> instance restarts. Without this option, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> will back up the existing log and create a new file. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --logRotate &lt;string&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--logRotate" title="Permalink to this definition"> <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="std-option-mongos.--logRotate"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : rename </p> <p class="leafygreen-ui-1kp3ins"> Determines the behavior for the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/logRotate/#mongodb-dbcommand-dbcmd.logRotate"> <code class="leafygreen-ui-1l06pbn"> logRotate </code> </a> command when rotating the server log and/or the audit log. Specify either <code class="leafygreen-ui-1l06pbn"> rename </code> or <code class="leafygreen-ui-1l06pbn"> reopen </code> : </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> rename </code> renames the log file. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> reopen </code> closes and reopens the log file following the typical Linux/Unix log rotate behavior. Use <code class="leafygreen-ui-1l06pbn"> reopen </code> when using the Linux/Unix logrotate utility to avoid log loss. </p> <p class="leafygreen-ui-1kp3ins"> If you specify <code class="leafygreen-ui-1l06pbn"> reopen </code> , you must also use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--logappend" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --logappend </code> . </span> </a> </p> </li> </ul> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --redactClientLogData </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--redactClientLogData" title="Permalink to this definition"> <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="std-option-mongos.--redactClientLogData"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Available in MongoDB Enterprise only. </em> </p> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> mongos </code> running with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--redactClientLogData" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --redactClientLogData </code> </span> </a> redacts any message accompanying a given log event before logging. This prevents the <code class="leafygreen-ui-1l06pbn"> mongos </code> from writing potentially sensitive data stored on the database to the diagnostic log. Metadata such as error or operation codes, line numbers, and source file names are still visible in the logs. </p> <p class="leafygreen-ui-1kp3ins"> Use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--redactClientLogData" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --redactClientLogData </code> </span> </a> in conjunction with <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/"> Encryption at Rest </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-transport-encryption/"> TLS/SSL (Transport Encryption) </a> to assist compliance with regulatory requirements. </p> <p class="leafygreen-ui-1kp3ins"> For example, a MongoDB deployment might store Personally Identifiable Information (PII) in one or more collections. The <code class="leafygreen-ui-1l06pbn"> mongos </code> logs events such as those related to CRUD operations, sharding metadata, etc. It is possible that the <code class="leafygreen-ui-1l06pbn"> mongos </code> may expose PII as a part of these logging operations. A <code class="leafygreen-ui-1l06pbn"> mongos </code> running with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--redactClientLogData" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --redactClientLogData </code> </span> </a> removes any message accompanying these events before being output to the log, effectively removing the PII. </p> <p class="leafygreen-ui-1kp3ins"> Diagnostics on a <code class="leafygreen-ui-1l06pbn"> mongos </code> running with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--redactClientLogData" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --redactClientLogData </code> </span> </a> may be more difficult due to the lack of data related to a log event. See the <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/monitoring/#std-label-monitoring-log-redaction"> process logging </a> manual page for an example of the effect of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--redactClientLogData" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --redactClientLogData </code> </span> </a> on log output. </p> <p class="leafygreen-ui-1kp3ins"> On a running <code class="leafygreen-ui-1l06pbn"> mongos </code> , use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter"> <code class="leafygreen-ui-1l06pbn"> setParameter </code> </a> with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.redactClientLogData"> <code class="leafygreen-ui-1l06pbn"> redactClientLogData </code> </a> parameter to configure this setting. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --timeStampFormat &lt;string&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--timeStampFormat" title="Permalink to this definition"> <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="std-option-mongos.--timeStampFormat"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : iso8601-local </p> <p class="leafygreen-ui-1kp3ins"> The time format for timestamps in log messages. Specify one of the following values: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:40%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> iso8601-utc </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Displays timestamps in Coordinated Universal Time (UTC) in the ISO-8601 format. For example, for New York at the start of the Epoch: <code class="leafygreen-ui-1l06pbn"> 1970-01-01T00:00:00.000Z </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> iso8601-local </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Displays timestamps in local time in the ISO-8601 format. For example, for New York at the start of the Epoch: <code class="leafygreen-ui-1l06pbn"> 1969-12-31T19:00:00.000-05:00 </code> </div> </div> </td> </tr> </tbody> </table> </div> <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 class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--timeStampFormat" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --timeStampFormat </code> </span> </a> no longer supports <code class="leafygreen-ui-1l06pbn"> ctime </code> . An example of <code class="leafygreen-ui-1l06pbn"> ctime </code> formatted date is: <code class="leafygreen-ui-1l06pbn"> Wed Dec 31 18:17:54.811 </code> . </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --pidfilepath &lt;path&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--pidfilepath" title="Permalink to this definition"> <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="std-option-mongos.--pidfilepath"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies a file location to store the process ID (PID) of the <code class="leafygreen-ui-1l06pbn"> mongos </code> process. The user running the <code class="leafygreen-ui-1l06pbn"> mongod </code> or <code class="leafygreen-ui-1l06pbn"> mongos </code> process must be able to write to this path. If the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--pidfilepath" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --pidfilepath </code> </span> </a> option is not specified, the process does not create a PID file. This option is generally only useful in combination with the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--fork" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --fork </code> </span> </a> option. </p> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Linux </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> On Linux, PID file management is generally the responsibility of your distro's init system: usually a service file in the <code class="leafygreen-ui-1l06pbn"> /etc/init.d </code> directory, or a systemd unit file registered with <code class="leafygreen-ui-1l06pbn"> systemctl </code> . Only use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--pidfilepath" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --pidfilepath </code> </span> </a> option if you are not using one of these init systems. For more information, please see the respective <a class="leafygreen-ui-tqgtui" href="/docs/manual/installation/#std-label-tutorial-installation"> Installation Guide </a> for your operating system. </p> </div> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> macOS </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> On macOS, PID file management is generally handled by <code class="leafygreen-ui-1l06pbn"> brew </code> . Only use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--pidfilepath" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --pidfilepath </code> </span> </a> option if you are not using <code class="leafygreen-ui-1l06pbn"> brew </code> on your macOS system. For more information, please see the respective Installation Guide for your operating system. </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --keyFile &lt;file&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--keyFile" title="Permalink to this definition"> <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="std-option-mongos.--keyFile"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies the path to a key file that stores the shared secret that MongoDB instances use to authenticate to each other in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set"> replica set </a> . <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--keyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --keyFile </code> </span> </a> implies <code class="leafygreen-ui-1l06pbn"> client authorization </code> . See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-inter-process-auth"> Self-Managed Internal/Membership Authentication </a> for more information. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-internal-auth-keyfile"> Keyfiles for internal membership authentication </a> use YAML format to allow for multiple keys in a keyfile. The YAML format accepts either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A single key string (same as in earlier versions) </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A sequence of key strings </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The YAML format is compatible with the existing single-key keyfiles that use the text file format. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --setParameter &lt;options&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--setParameter" title="Permalink to this definition"> <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="std-option-mongos.--setParameter"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies one of the MongoDB parameters described in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/"> MongoDB Server Parameters for a Self-Managed Deployment </a> . You can specify multiple <code class="leafygreen-ui-1l06pbn"> setParameter </code> fields. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --noscripting </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--noscripting" title="Permalink to this definition"> <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="std-option-mongos.--noscripting"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Disables the scripting engine. When disabled, you cannot use operations that perform server-side execution of JavaScript code, such as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/where/#mongodb-query-op.-where"> <code class="leafygreen-ui-1l06pbn"> $where </code> </a> query operator, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce"> <code class="leafygreen-ui-1l06pbn"> mapReduce </code> </a> command, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator"> <code class="leafygreen-ui-1l06pbn"> $accumulator </code> </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function"> <code class="leafygreen-ui-1l06pbn"> $function </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> If you do not use these operations, disable server-side scripting. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --nounixsocket </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--nounixsocket" title="Permalink to this definition"> <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="std-option-mongos.--nounixsocket"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Disables listening on the UNIX domain socket. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--nounixsocket" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --nounixsocket </code> </span> </a> applies only to Unix-based systems. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> mongos </code> process always listens on the UNIX socket unless one of the following is true: </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="#std-option-mongos.--nounixsocket" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --nounixsocket </code> </span> </a> is set </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> net.bindIp </code> </a> is not set </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> net.bindIp </code> </a> does not specify <code class="leafygreen-ui-1l06pbn"> localhost </code> or its associated IP address </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> mongos </code> installed from official <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-debian/"> .deb </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-red-hat/"> .rpm </a> packages have the <code class="leafygreen-ui-1l06pbn"> bind_ip </code> configuration set to <code class="leafygreen-ui-1l06pbn"> 127.0.0.1 </code> by default. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --unixSocketPrefix &lt;path&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--unixSocketPrefix" title="Permalink to this definition"> <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="std-option-mongos.--unixSocketPrefix"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : /tmp </p> <p class="leafygreen-ui-1kp3ins"> The path for the UNIX socket. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--unixSocketPrefix" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --unixSocketPrefix </code> </span> </a> applies only to Unix-based systems. </p> <p class="leafygreen-ui-1kp3ins"> If this option has no value, the <code class="leafygreen-ui-1l06pbn"> mongos </code> process creates a socket with <code class="leafygreen-ui-1l06pbn"> /tmp </code> as a prefix. MongoDB creates and listens on a UNIX socket unless one of the following is true: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.unixDomainSocket.enabled"> <code class="leafygreen-ui-1l06pbn"> net.unixDomainSocket.enabled </code> </a> is <code class="leafygreen-ui-1l06pbn"> false </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--nounixsocket" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --nounixsocket </code> </span> </a> is set </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> net.bindIp </code> </a> is not set </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp"> <code class="leafygreen-ui-1l06pbn"> net.bindIp </code> </a> does not specify <code class="leafygreen-ui-1l06pbn"> localhost </code> or its associated IP address </p> </li> </ul> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --filePermissions &lt;path&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--filePermissions" title="Permalink to this definition"> <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="std-option-mongos.--filePermissions"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : <code class="leafygreen-ui-1l06pbn"> 0700 </code> </p> <p class="leafygreen-ui-1kp3ins"> Sets the permission for the UNIX domain socket file. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--filePermissions" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --filePermissions </code> </span> </a> applies only to Unix-based systems. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --fork </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--fork" title="Permalink to this definition"> <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="std-option-mongos.--fork"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Enables a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-daemon"> daemon </a> mode that runs the <code class="leafygreen-ui-1l06pbn"> mongos </code> process in the background. The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--fork" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --fork </code> </span> </a> option is not supported on Windows. </p> <p class="leafygreen-ui-1kp3ins"> By default <code class="leafygreen-ui-1l06pbn"> mongos </code> does not run as a daemon. You run <code class="leafygreen-ui-1l06pbn"> mongos </code> as a daemon by using either <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--fork" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --fork </code> </span> </a> or a controlling process that handles daemonization, such as <code class="leafygreen-ui-1l06pbn"> upstart </code> or <code class="leafygreen-ui-1l06pbn"> systemd </code> . </p> <p class="leafygreen-ui-1kp3ins"> Using the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--fork" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --fork </code> </span> </a> option requires that you configure log output for the <code class="leafygreen-ui-1l06pbn"> mongos </code> with one of the following: </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="#std-option-mongos.--logpath" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --logpath </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--syslog" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --syslog </code> </span> </a> </p> </li> </ul> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --transitionToAuth </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--transitionToAuth" title="Permalink to this definition"> <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="std-option-mongos.--transitionToAuth"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Allows the <code class="leafygreen-ui-1l06pbn"> mongos </code> to accept and create authenticated and non-authenticated connections to and from other <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> and <code class="leafygreen-ui-1l06pbn"> mongos </code> instances in the deployment. Used for performing rolling transition of replica sets or sharded clusters from a no-auth configuration to <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-inter-process-auth"> internal authentication </a> . Requires specifying a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-inter-process-auth"> internal authentication </a> mechanism such as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--keyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --keyFile </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> For example, if using <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-internal-auth-keyfile"> keyfiles </a> for <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-inter-process-auth"> internal authentication </a> , the <code class="leafygreen-ui-1l06pbn"> mongos </code> creates an authenticated connection with any <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> or <code class="leafygreen-ui-1l06pbn"> mongos </code> in the deployment using a matching keyfile. If the security mechanisms do not match, the <code class="leafygreen-ui-1l06pbn"> mongos </code> utilizes a non-authenticated connection instead. </p> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> mongos </code> running with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--transitionToAuth" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --transitionToAuth </code> </span> </a> does not enforce <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization"> user access controls </a> . Users may connect to your deployment without any access control checks and perform read, write, and administrative operations. </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"> A <code class="leafygreen-ui-1l06pbn"> mongos </code> running with <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-inter-process-auth"> internal authentication </a> and <em> without </em> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--transitionToAuth" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --transitionToAuth </code> </span> </a> requires clients to connect using <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization"> user access controls </a> . Update clients to connect to the <code class="leafygreen-ui-1l06pbn"> mongos </code> using the appropriate <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-users/#std-label-users"> user </a> prior to restarting <code class="leafygreen-ui-1l06pbn"> mongos </code> without <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--transitionToAuth" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --transitionToAuth </code> . </span> </a> </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --networkMessageCompressors &lt;string&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--networkMessageCompressors" title="Permalink to this definition"> <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="std-option-mongos.--networkMessageCompressors"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : snappy,zstd,zlib </p> <p class="leafygreen-ui-1kp3ins"> Specifies the default compressor(s) to use for communication between this <code class="leafygreen-ui-1l06pbn"> mongos </code> instance and: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> other members of the sharded cluster </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> drivers that support the <code class="leafygreen-ui-1l06pbn"> OP_COMPRESSED </code> message format. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> MongoDB supports the following compressors: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-snappy"> snappy </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zlib"> zlib </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zstd"> zstd </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Both <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> and <code class="leafygreen-ui-1l06pbn"> mongos </code> instances default to <code class="leafygreen-ui-1l06pbn"> snappy,zstd,zlib </code> compressors, in that order. </p> <p class="leafygreen-ui-1kp3ins"> To disable network compression, set the value to <code class="leafygreen-ui-1l06pbn"> disabled </code> . </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Messages are compressed when both parties enable network compression. Otherwise, messages between the parties are uncompressed. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> If you specify multiple compressors, then the order in which you list the compressors matter as well as the communication initiator. For example, if <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> specifies the following network compressors <code class="leafygreen-ui-1l06pbn"> zlib,snappy </code> and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> specifies <code class="leafygreen-ui-1l06pbn"> snappy,zlib </code> , messages between <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> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> uses <code class="leafygreen-ui-1l06pbn"> zlib </code> . </p> <p class="leafygreen-ui-1kp3ins"> If the parties do not share at least one common compressor, messages between the parties are uncompressed. For example, if <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> specifies the network compressor <code class="leafygreen-ui-1l06pbn"> zlib </code> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> specifies <code class="leafygreen-ui-1l06pbn"> snappy </code> , messages between <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> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> are not compressed. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --timeZoneInfo &lt;path&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--timeZoneInfo" title="Permalink to this definition"> <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="std-option-mongos.--timeZoneInfo"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The full path from which to load the time zone database. If this option is not provided, then MongoDB uses its built-in time zone database. </p> <p class="leafygreen-ui-1kp3ins"> The configuration file included with Linux and macOS packages sets the time zone database path to <code class="leafygreen-ui-1l06pbn"> /usr/share/zoneinfo </code> by default. </p> <p class="leafygreen-ui-1kp3ins"> The built-in time zone database is a copy of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.iana.org/time-zones" rel="noopener noreferrer"> <span> Olson/IANA time zone database </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> . It is updated along with MongoDB releases, but the time zone database release cycle differs from the MongoDB release cycle. The most recent release of the time zone database is available on our <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://downloads.mongodb.org/olson_tz_db/timezonedb-latest.zip" rel="noopener noreferrer"> <span> download site </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> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"wget https://downloads.mongodb.org/olson_tz_db/timezonedb-latest.zip\nunzip timezonedb-latest.zip\nmongos --timeZoneInfo timezonedb-2017b/","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">wget https:/<!-- -->/downloads.mongodb.org/olson_tz_db/timezonedb-latest.zip</td></tr><tr class=""><td class="leafygreen-ui-7razhx">unzip timezonedb-latest.zip</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongos --timeZoneInfo timezonedb-2017b/</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 class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> MongoDB uses the third party <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/derickr/timelib" rel="noopener noreferrer"> <span> timelib </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> library to provide accurate conversions between timezones. Due to a recent update, <code class="leafygreen-ui-1l06pbn"> timelib </code> could create inaccurate time zone conversions in older versions of MongoDB. </p> <p class="leafygreen-ui-1kp3ins"> To explicitly link to the time zone database in versions of MongoDB prior to 5.0, download the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://downloads.mongodb.org/olson_tz_db/timezonedb-latest.zip" rel="noopener noreferrer"> <span> time zone database </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> . and use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--timeZoneInfo"> <code class="leafygreen-ui-1l06pbn"> timeZoneInfo </code> </a> parameter. </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --outputConfig </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--outputConfig" title="Permalink to this definition"> <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="std-option-mongos.--outputConfig"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Outputs the <code class="leafygreen-ui-1l06pbn"> mongos </code> instance's configuration options, formatted in YAML, to <code class="leafygreen-ui-1l06pbn"> stdout </code> and exits the <code class="leafygreen-ui-1l06pbn"> mongos </code> instance. For configuration options that uses <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/expansion-directives/#std-label-externally-sourced-values"> Externally Sourced Configuration File Values for Self-Managed Deployments </a> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--outputConfig" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --outputConfig </code> </span> </a> returns the resolved value for those options. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This may include any configured passwords or secrets previously obfuscated through the external source. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> For usage examples, see: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/expansion-directives/#std-label-expansion-directive-output"> Output the Configuration File with Resolved Expansion Directive Values </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/convert-command-line-options-to-yaml/"> Convert Self-Managed Command-Line Options to YAML </a> </p> </li> </ul> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Sharded Cluster Options <a class="headerlink leafygreen-ui-1kepx47" href="#sharded-cluster-options" 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-options"> </div> </a> </h3> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --configdb &lt;replicasetName&gt;/&lt;config1&gt;,&lt;config2&gt;... </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--configdb" title="Permalink to this definition"> <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="std-option-mongos.--configdb"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-config-servers/#std-label-sharding-config-server"> configuration servers </a> for the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Config servers for sharded clusters are deployed as a <a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/"> replica set </a> . The replica set config servers must run the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/"> WiredTiger storage engine <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Specify the config server replica set name and the hostname and port of at least one of the members of the config server replica set. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sharding:\n configDB: &lt;configreplsetname&gt;/cfg1.example.net:27019, cfg2.example.net:27019,...","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">sharding</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">configDB</span>: &lt;<!-- -->configReplSetName<!-- -->&gt;<!-- -->/<!-- -->cfg1.<span class="lg-highlight-property">example</span>.<span class="lg-highlight-property">net</span>:<span class="lg-highlight-number">27019</span>, <!-- -->cfg2.<span class="lg-highlight-property">example</span>.<span class="lg-highlight-property">net</span>:<span class="lg-highlight-number">27019</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> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> mongos </code> instances for the sharded cluster must specify the same config server replica set name but can specify hostname and port of different members of the replica set. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --localThreshold </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--localThreshold" title="Permalink to this definition"> <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="std-option-mongos.--localThreshold"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : 15 </p> <p class="leafygreen-ui-1kp3ins"> Specifies the ping time, in milliseconds, that <code class="leafygreen-ui-1l06pbn"> mongos </code> uses to determine which secondary replica set members to pass read operations from clients. The default value of <code class="leafygreen-ui-1l06pbn"> 15 </code> corresponds to the default value in all of the client <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> drivers <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> When <code class="leafygreen-ui-1l06pbn"> mongos </code> receives a request that permits reads to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary"> secondary </a> members, it: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Finds the member of the set with the lowest ping time. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Constructs a list of replica set members that is within a ping time of 15 milliseconds of the nearest suitable member of the set. </p> <p class="leafygreen-ui-1kp3ins"> If you specify a value for the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--localThreshold" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --localThreshold </code> </span> </a> option, <code class="leafygreen-ui-1l06pbn"> mongos </code> constructs the list of replica members that are within the latency allowed by this value. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Selects a member to read from at random from this list. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The ping time used for a member compared by the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--localThreshold" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --localThreshold </code> </span> </a> setting is a moving average of recent ping times, calculated at most every 10 seconds. As a result, some queries may reach members above the threshold until the <code class="leafygreen-ui-1l06pbn"> mongos </code> recalculates the average. </p> <p class="leafygreen-ui-1kp3ins"> See the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-member-selection"> Read Preference for Replica Sets </a> section of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#std-label-read-preference"> read preference </a> documentation for more information. </p> </dd> </dl> <span class="leafygreen-ui-1qnjd6d" id="std-label-mongos-tls-options"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> TLS Options <a class="headerlink leafygreen-ui-1kepx47" href="#tls-options" 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="tls-options"> </div> </a> </h3> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> See: </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> for full documentation of MongoDB's support. </p> </div> </div> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsMode &lt;mode&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsMode" title="Permalink to this definition"> <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="std-option-mongos.--tlsMode"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Enables TLS used for all network connections. The argument to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsMode" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsMode </code> </span> </a> option can be one of the following: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:40%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> disabled </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The server does not use TLS. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> allowTLS </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Connections between servers do not use TLS. For incoming connections, the server accepts both TLS and non-TLS. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> preferTLS </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Connections between servers use TLS. For incoming connections, the server accepts both TLS and non-TLS. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> requireTLS </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The server uses and accepts only TLS encrypted connections. </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> --tlsCAFile </code> or <code class="leafygreen-ui-1l06pbn"> tls.CAFile </code> is not specified and you are not using x.509 authentication, you must set the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.tlsUseSystemCA"> <code class="leafygreen-ui-1l06pbn"> tlsUseSystemCA </code> </a> parameter to <code class="leafygreen-ui-1l06pbn"> true </code> . This makes MongoDB use the system-wide CA certificate store when connecting to a TLS-enabled server. </p> <p class="leafygreen-ui-1kp3ins"> If using x.509 authentication, <code class="leafygreen-ui-1l06pbn"> --tlsCAFile </code> or <code class="leafygreen-ui-1l06pbn"> tls.CAFile </code> must be specified unless using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCertificateSelector"> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateKeyFile &lt;filename&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsCertificateKeyFile" title="Permalink to this definition"> <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="std-option-mongos.--tlsCertificateKeyFile"> </div> </a> </dt> <dd> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> On macOS or Windows, you can use a certificate from the operating system's secure store instead of specifying a PEM file. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> . </span> </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Specifies the <code class="file docutils literal"> <span class="pre"> .pem </span> </code> file that contains both the TLS certificate and key. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> On Linux/BSD, you must specify <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateKeyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateKeyFile </code> </span> </a> when TLS is enabled. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> On Windows or macOS, you must specify either <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateKeyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateKeyFile </code> </span> </a> or <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> </span> </a> when TLS is enabled. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateKeyFilePassword &lt;value&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsCertificateKeyFilePassword" title="Permalink to this definition"> <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="std-option-mongos.--tlsCertificateKeyFilePassword"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies the password to decrypt the certificate-key file (i.e. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateKeyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateKeyFile </code> </span> </a> ). Use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateKeyFilePassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateKeyFilePassword </code> </span> </a> option only if the certificate-key file is encrypted. In all cases, the <code class="leafygreen-ui-1l06pbn"> mongos </code> redacts the password from all logging and reporting output. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> On Linux/BSD, if the private key in the PEM file is encrypted and you do not specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateKeyFilePassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateKeyFilePassword </code> </span> </a> option, MongoDB prompts for a passphrase. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/#std-label-ssl-certificate-password"> TLS/SSL Certificate Passphrase <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> On macOS or Windows, if the private key in the PEM file is encrypted, you must explicitly specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateKeyFilePassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateKeyFilePassword </code> </span> </a> option. Alternatively, you can use a certificate from the secure system store (see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> </span> </a> ) instead of a PEM file or use an unencrypted PEM file. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --clusterAuthMode &lt;option&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--clusterAuthMode" title="Permalink to this definition"> <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="std-option-mongos.--clusterAuthMode"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : keyFile </p> <p class="leafygreen-ui-1kp3ins"> The authentication mode used for cluster authentication. If you use <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-x509-member-authentication/#std-label-x509-internal-authentication"> internal x.509 authentication </a> , specify so here. This option can have one of the following values: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:40%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> keyFile </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Use a keyfile for authentication. Accept only keyfiles. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> sendKeyFile </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> For rolling upgrade purposes. Send a keyfile for authentication but can accept both keyfiles and x.509 certificates. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> sendX509 </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> For rolling upgrade purposes. Send the x.509 certificate for authentication but can accept both keyfiles and x.509 certificates. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> x509 </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Recommended. Send the x.509 certificate for authentication and accept only x.509 certificates. </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> --tlsCAFile </code> or <code class="leafygreen-ui-1l06pbn"> tls.CAFile </code> is not specified and you are not using x.509 authentication, you must set the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.tlsUseSystemCA"> <code class="leafygreen-ui-1l06pbn"> tlsUseSystemCA </code> </a> parameter to <code class="leafygreen-ui-1l06pbn"> true </code> . This makes MongoDB use the system-wide CA certificate store when connecting to a TLS-enabled server. </p> <p class="leafygreen-ui-1kp3ins"> If using x.509 authentication, <code class="leafygreen-ui-1l06pbn"> --tlsCAFile </code> or <code class="leafygreen-ui-1l06pbn"> tls.CAFile </code> must be specified unless using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCertificateSelector"> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsClusterFile &lt;filename&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsClusterFile" title="Permalink to this definition"> <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="std-option-mongos.--tlsClusterFile"> </div> </a> </dt> <dd> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> On macOS or Windows, you can use a certificate from the operating system's secure store instead of a PEM file. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCertificateSelector </code> . </span> </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Specifies the <code class="file docutils literal"> <span class="pre"> .pem </span> </code> file that contains the x.509 certificate-key file for <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-x509-member-authentication/#std-label-x509-internal-authentication"> membership authentication </a> for the cluster or replica set. </p> <p class="leafygreen-ui-1kp3ins"> If <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterFile </code> </span> </a> does not specify the <code class="leafygreen-ui-1l06pbn"> .pem </code> file for internal cluster authentication or the alternative <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCertificateSelector </code> </span> </a> , the cluster uses the <code class="leafygreen-ui-1l06pbn"> .pem </code> file specified in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateKeyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateKeyFile </code> </span> </a> option or the certificate returned by the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> If using x.509 authentication, <code class="leafygreen-ui-1l06pbn"> --tlsCAFile </code> or <code class="leafygreen-ui-1l06pbn"> tls.CAFile </code> must be specified unless using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCertificateSelector"> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-binary-bin.mongos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongos </code> </span> </a> logs a warning on connection if the presented x.509 certificate expires within <code class="leafygreen-ui-1l06pbn"> 30 </code> days of the <code class="leafygreen-ui-1l06pbn"> mongod/mongos </code> host system time. </p> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsClusterPassword &lt;value&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsClusterPassword" title="Permalink to this definition"> <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="std-option-mongos.--tlsClusterPassword"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies the password to decrypt the x.509 certificate-key file specified with <code class="leafygreen-ui-1l06pbn"> --tlsClusterFile </code> . Use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterPassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterPassword </code> </span> </a> option only if the certificate-key file is encrypted. In all cases, the <code class="leafygreen-ui-1l06pbn"> mongos </code> redacts the password from all logging and reporting output. </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> On Linux/BSD, if the private key in the x.509 file is encrypted and you do not specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterPassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterPassword </code> </span> </a> option, MongoDB prompts for a passphrase. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/#std-label-ssl-certificate-password"> TLS/SSL Certificate Passphrase <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> On macOS or Windows, if the private key in the x.509 file is encrypted, you must explicitly specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterPassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterPassword </code> </span> </a> option. Alternatively, you can either use a certificate from the secure system store (see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCertificateSelector </code> </span> </a> ) instead of a cluster PEM file or use an unencrypted PEM file. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsCAFile &lt;filename&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsCAFile" title="Permalink to this definition"> <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="std-option-mongos.--tlsCAFile"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies the <code class="file docutils literal"> <span class="pre"> .pem </span> </code> file that contains the root certificate chain from the Certificate Authority. Specify the file name of the <code class="file docutils literal"> <span class="pre"> .pem </span> </code> file using relative or absolute paths. </p> <p class="leafygreen-ui-1kp3ins"> On macOS or Windows, you can use a certificate from the operating system's secure store instead of a PEM key file. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> </span> </a> . When using the secure store, you do not need to, but can, also specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCAFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCAFile </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCAFile &lt;filename&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsClusterCAFile" title="Permalink to this definition"> <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="std-option-mongos.--tlsClusterCAFile"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies the <code class="file docutils literal"> <span class="pre"> .pem </span> </code> file that contains the root certificate chain from the Certificate Authority used to validate the certificate presented by a client establishing a connection. Specify the file name of the <code class="file docutils literal"> <span class="pre"> .pem </span> </code> file using relative or absolute paths. </p> <p class="leafygreen-ui-1kp3ins"> If <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterCAFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCAFile </code> </span> </a> does not specify the <code class="file docutils literal"> <span class="pre"> .pem </span> </code> file for validating the certificate from a client establishing a connection, the cluster uses the <code class="file docutils literal"> <span class="pre"> .pem </span> </code> file specified in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCAFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCAFile </code> </span> </a> option. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterCAFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCAFile </code> </span> </a> lets you use separate Certificate Authorities to verify the client to server and server to client portions of the TLS handshake. </p> <p class="leafygreen-ui-1kp3ins"> On macOS or Windows, you can use a certificate from the operating system's secure store instead of a PEM key file. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCertificateSelector </code> </span> </a> . When using the secure store, you do not need to, but can, also specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterCAFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCAFile </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> Requires that <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCAFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCAFile </code> </span> </a> is set. </p> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector &lt;parameter&gt;=&lt;value&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsCertificateSelector" title="Permalink to this definition"> <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="std-option-mongos.--tlsCertificateSelector"> </div> </a> </dt> <dd> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Available on Windows and macOS as an alternative to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateKeyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateKeyFile </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateKeyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateKeyFile </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> </span> </a> options are mutually exclusive. You can only specify one. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Specifies a certificate property in order to select a matching certificate from the operating system's certificate store. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> </span> </a> accepts an argument of the format <code class="leafygreen-ui-1l06pbn"> &lt;property&gt;=&lt;value&gt; </code> where the property can be one of the following: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Property </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> subject </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> ASCII string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Subject name or common name on certificate </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> thumbprint </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> hex string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> A sequence of bytes, expressed as hexadecimal, used to identify a public key by its SHA-1 digest. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> thumbprint </code> is sometimes referred to as a <code class="leafygreen-ui-1l06pbn"> fingerprint </code> . </p> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> When using the system SSL certificate store, OCSP (Online Certificate Status Protocol) is used to validate the revocation status of certificates. </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"> You cannot use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/rotateCertificates/#mongodb-dbcommand-dbcmd.rotateCertificates"> <code class="leafygreen-ui-1l06pbn"> rotateCertificates </code> </a> command or the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.rotateCertificates/#mongodb-method-db.rotateCertificates"> <code class="leafygreen-ui-1l06pbn"> db.rotateCertificates() </code> </a> shell method when using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.certificateSelector"> <code class="leafygreen-ui-1l06pbn"> net.tls.certificateSelector </code> </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCertificateSelector"> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> </a> set to <code class="leafygreen-ui-1l06pbn"> thumbprint </code> </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCertificateSelector &lt;parameter&gt;=&lt;value&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsClusterCertificateSelector" title="Permalink to this definition"> <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="std-option-mongos.--tlsClusterCertificateSelector"> </div> </a> </dt> <dd> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Available on Windows and macOS as an alternative to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterFile </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterFile </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCertificateSelector </code> </span> </a> options are mutually exclusive. You can only specify one. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Specifies a certificate property in order to select a matching certificate from the operating system's certificate store to use for internal authentication. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsClusterCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsClusterCertificateSelector </code> </span> </a> accepts an argument of the format <code class="leafygreen-ui-1l06pbn"> &lt;property&gt;=&lt;value&gt; </code> where the property can be one of the following: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Property </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> subject </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> ASCII string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Subject name or common name on certificate </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> thumbprint </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> hex string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> A sequence of bytes, expressed as hexadecimal, used to identify a public key by its SHA-1 digest. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> thumbprint </code> is sometimes referred to as a <code class="leafygreen-ui-1l06pbn"> fingerprint </code> . </p> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-binary-bin.mongos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongos </code> </span> </a> logs a warning on connection if the presented x.509 certificate expires within <code class="leafygreen-ui-1l06pbn"> 30 </code> days of the <code class="leafygreen-ui-1l06pbn"> mongod/mongos </code> host system time. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsCRLFile &lt;filename&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsCRLFile" title="Permalink to this definition"> <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="std-option-mongos.--tlsCRLFile"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies the <code class="file docutils literal"> <span class="pre"> .pem </span> </code> file that contains the Certificate Revocation List. Specify the file name of the <code class="file docutils literal"> <span class="pre"> .pem </span> </code> file using relative or absolute paths. </p> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> You cannot specify a CRL file on macOS. Instead, you can use the system SSL certificate store, which uses OCSP (Online Certificate Status Protocol) to validate the revocation status of certificates. To use the system SSL certificate store, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsCertificateSelector" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsCertificateSelector </code> . </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To check for certificate revocation, MongoDB <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.ocspEnabled"> <code class="leafygreen-ui-1l06pbn"> enables </code> </a> the use of OCSP (Online Certificate Status Protocol) by default as an alternative to specifying a CRL file or using the system SSL certificate store. </p> </li> </ul> </div> </div> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsAllowConnectionsWithoutCertificates </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsAllowConnectionsWithoutCertificates" title="Permalink to this definition"> <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="std-option-mongos.--tlsAllowConnectionsWithoutCertificates"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> By default, the server bypasses client certificate validation unless the server is configured to use a CA file. If a CA file is provided, the following rules apply: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For clients that don't provide certificates, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> or <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-binary-bin.mongos" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongos </code> </span> </a> encrypts the TLS/SSL connection, assuming the connection is successfully made. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For clients that present a certificate, <code class="leafygreen-ui-1l06pbn"> mongos </code> performs certificate validation using the root certificate chain specified by <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCAFile"> <code class="leafygreen-ui-1l06pbn"> --tlsCAFile </code> </a> and reject clients with invalid certificates. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsAllowConnectionsWithoutCertificates" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsAllowConnectionsWithoutCertificates </code> </span> </a> option if you have a mixed deployment that includes clients that do not or cannot present certificates to the <code class="leafygreen-ui-1l06pbn"> mongos </code> . </p> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsAllowInvalidCertificates </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsAllowInvalidCertificates" title="Permalink to this definition"> <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="std-option-mongos.--tlsAllowInvalidCertificates"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Bypasses the validation checks for TLS certificates on other servers in the cluster and allows the use of invalid certificates to connect. </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 specify <code class="leafygreen-ui-1l06pbn"> --tlsAllowInvalidCertificates </code> or <code class="leafygreen-ui-1l06pbn"> tls.allowInvalidCertificates: true </code> when using x.509 authentication, an invalid certificate is only sufficient to establish a TLS connection but is <em> insufficient </em> for authentication. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> When using the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsAllowInvalidCertificates" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsAllowInvalidCertificates </code> </span> </a> setting, MongoDB logs a warning regarding the use of the invalid certificate. </p> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsAllowInvalidHostnames </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsAllowInvalidHostnames" title="Permalink to this definition"> <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="std-option-mongos.--tlsAllowInvalidHostnames"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Disables the validation of the hostnames in TLS certificates, when connecting to other members of the replica set or sharded cluster for inter-process authentication. This allows <code class="leafygreen-ui-1l06pbn"> mongos </code> to connect to other members if the hostnames in their certificates do not match their configured hostname. </p> <p class="leafygreen-ui-1kp3ins"> For more information about TLS and MongoDB, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsDisabledProtocols &lt;protocol(s)&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsDisabledProtocols" title="Permalink to this definition"> <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="std-option-mongos.--tlsDisabledProtocols"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Prevents a MongoDB server running with TLS from accepting incoming connections that use a specific protocol or protocols. To specify multiple protocols, use a comma separated list of protocols. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsDisabledProtocols" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsDisabledProtocols </code> </span> </a> recognizes the following protocols: <code class="leafygreen-ui-1l06pbn"> TLS1_0 </code> , <code class="leafygreen-ui-1l06pbn"> TLS1_1 </code> , <code class="leafygreen-ui-1l06pbn"> TLS1_2 </code> , and <code class="leafygreen-ui-1l06pbn"> TLS1_3 </code> . </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> On macOS, you cannot disable <code class="leafygreen-ui-1l06pbn"> TLS1_1 </code> and leave both <code class="leafygreen-ui-1l06pbn"> TLS1_0 </code> and <code class="leafygreen-ui-1l06pbn"> TLS1_2 </code> enabled. You must disable at least one of the other two, for example, <code class="leafygreen-ui-1l06pbn"> TLS1_0,TLS1_1 </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To list multiple protocols, specify as a comma separated list of protocols. For example <code class="leafygreen-ui-1l06pbn"> TLS1_0,TLS1_1 </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specifying an unrecognized protocol prevents the server from starting. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The specified disabled protocols overrides any default disabled protocols. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> MongoDB disables the use of TLS 1.0 if TLS 1.1+ is available on the system. To enable the disabled TLS 1.0, specify <code class="leafygreen-ui-1l06pbn"> none </code> to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsDisabledProtocols" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsDisabledProtocols </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> Members of replica sets and sharded clusters must speak at least one protocol in common. </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/tutorial/configure-ssl/#std-label-ssl-disallow-protocols"> Disallow Protocols </a> </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --tlsFIPSMode </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--tlsFIPSMode" title="Permalink to this definition"> <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="std-option-mongos.--tlsFIPSMode"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Directs the <code class="leafygreen-ui-1l06pbn"> mongos </code> to use the FIPS mode of the TLS library. Your system must have a FIPS compliant library to use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--tlsFIPSMode" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --tlsFIPSMode </code> </span> </a> option. </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"> FIPS-compatible TLS/SSL is available only in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self"> <span> MongoDB Enterprise </span> </a> . See <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-fips/"> Configure MongoDB for FIPS </a> for more information. </p> </div> </div> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Audit Options <a class="headerlink leafygreen-ui-1kepx47" href="#audit-options" 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="audit-options"> </div> </a> </h3> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --auditCompressionMode </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--auditCompressionMode" title="Permalink to this definition"> <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="std-option-mongos.--auditCompressionMode"> </div> </a> </dt> <dd> <div> <p> <em> New <!-- --> in version <!-- --> 5.3 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Specifies the compression mode for <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/#std-label-security-encryption-at-rest-audit-log"> audit log encryption </a> . You must also enable audit log encryption using either <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditEncryptionKeyUID" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditEncryptionKeyUID </code> </span> </a> or <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditLocalKeyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditLocalKeyFile </code> </span> </a> . </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditCompressionMode" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditCompressionMode </code> </span> </a> can be set to one of these values: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:15%"/> <col style="width:50%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> zstd </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zstd"> zstd </a> algorithm to compress the audit log. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> none </code> <em> (default) </em> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Do not compress the audit log. </div> </div> </td> </tr> </tbody> </table> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Available only in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self"> <span> MongoDB Enterprise </span> </a> . MongoDB Enterprise and Atlas have different configuration requirements. </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --auditDestination </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--auditDestination" title="Permalink to this definition"> <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="std-option-mongos.--auditDestination"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Enables <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/#std-label-auditing"> auditing </a> and specifies where <code class="leafygreen-ui-1l06pbn"> mongos </code> sends all audit events. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditDestination" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditDestination </code> </span> </a> can have one of the following values: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:15%"/> <col style="width:50%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> syslog </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Output the audit events to syslog in JSON format. Not available on Windows. Audit messages have a syslog severity level of <code class="leafygreen-ui-1l06pbn"> info </code> and a facility level of <code class="leafygreen-ui-1l06pbn"> user </code> . </p> <p class="leafygreen-ui-1kp3ins"> The syslog message limit can result in the truncation of audit messages. The auditing system neither detects the truncation nor errors upon its occurrence. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> console </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Output the audit events to <code class="leafygreen-ui-1l06pbn"> stdout </code> in JSON format. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> file </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Output the audit events to the file specified in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditPath" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditPath </code> </span> </a> in the format specified in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditFormat" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditFormat </code> . </span> </a> </div> </div> </td> </tr> </tbody> </table> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Available only in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self"> <span> MongoDB Enterprise </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://cloud.mongodb.com/user#/atlas/login" target="_self"> <span> MongoDB Atlas </span> </a> . </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --auditEncryptionKeyUID </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--auditEncryptionKeyUID" title="Permalink to this definition"> <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="std-option-mongos.--auditEncryptionKeyUID"> </div> </a> </dt> <dd> <div> <p> <em> New <!-- --> in version <!-- --> 6.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Specifies the unique identifier of the Key Management Interoperability Protocol (KMIP) key for <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/#std-label-security-encryption-at-rest-audit-log"> audit log encryption <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> You cannot use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditEncryptionKeyUID" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditEncryptionKeyUID </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditLocalKeyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditLocalKeyFile </code> </span> </a> together. </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"> Available only in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self"> <span> MongoDB Enterprise </span> </a> . MongoDB Enterprise and Atlas have different configuration requirements. </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --auditFormat </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--auditFormat" title="Permalink to this definition"> <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="std-option-mongos.--auditFormat"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies the format of the output file for <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/"> auditing </a> if <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditDestination" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditDestination </code> </span> </a> is <code class="leafygreen-ui-1l06pbn"> file </code> . The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditFormat" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditFormat </code> </span> </a> option can have one of the following values: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:15%"/> <col style="width:50%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> JSON </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Output the audit events in JSON format to the file specified in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditPath" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditPath </code> . </span> </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> BSON </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Output the audit events in BSON binary format to the file specified in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditPath" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditPath </code> . </span> </a> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Printing audit events to a file in JSON format degrades server performance more than printing to a file in BSON format. </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"> Available only in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self"> <span> MongoDB Enterprise </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://cloud.mongodb.com/user#/atlas/login" target="_self"> <span> MongoDB Atlas </span> </a> . </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --auditLocalKeyFile </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--auditLocalKeyFile" title="Permalink to this definition"> <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="std-option-mongos.--auditLocalKeyFile"> </div> </a> </dt> <dd> <div> <p> <em> New <!-- --> in version <!-- --> 5.3 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Specifies the path and file name for a local audit key file for <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/#std-label-security-encryption-at-rest-audit-log"> audit log encryption <!-- --> . </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"> Only use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditLocalKeyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditLocalKeyFile </code> </span> </a> for testing because the key is not secured. To secure the key, use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditEncryptionKeyUID" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditEncryptionKeyUID </code> </span> </a> and an external Key Management Interoperability Protocol (KMIP) server. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> You cannot use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditLocalKeyFile" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditLocalKeyFile </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditEncryptionKeyUID" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditEncryptionKeyUID </code> </span> </a> together. </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"> Available only in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self"> <span> MongoDB Enterprise </span> </a> . MongoDB Enterprise and Atlas have different configuration requirements. </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --auditPath </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--auditPath" title="Permalink to this definition"> <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="std-option-mongos.--auditPath"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies the output file for auditing if <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditDestination" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditDestination </code> </span> </a> has value of <code class="leafygreen-ui-1l06pbn"> file </code> . The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--auditPath" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --auditPath </code> </span> </a> option can take either a full path name or a relative path name. </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"> Available only in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self"> <span> MongoDB Enterprise </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://cloud.mongodb.com/user#/atlas/login" target="_self"> <span> MongoDB Atlas </span> </a> . </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --auditFilter </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--auditFilter" title="Permalink to this definition"> <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="std-option-mongos.--auditFilter"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Specifies the filter to limit the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/mongo/#std-label-audit-action-details-results"> types of operations </a> the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/"> audit system </a> records. The option takes a string representation of a query document of the form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ &lt;field1&gt;: &lt;expression1&gt;, ... }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ &lt;<!-- -->field1<!-- -->&gt;<!-- -->: &lt;<!-- -->expression1<!-- -->&gt;<!-- -->,<!-- --> <!-- -->...<!-- --> }</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"> The <code class="leafygreen-ui-1l06pbn"> &lt;field&gt; </code> can be <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/"> any field in the audit message </a> , including fields returned in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/mongo/#std-label-audit-action-details-results"> param </a> document. The <code class="leafygreen-ui-1l06pbn"> &lt;expression&gt; </code> is a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/#std-label-query-selectors"> query condition expression <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> To specify an audit filter, enclose the filter document in single quotes to pass the document as a string. </p> <p class="leafygreen-ui-1kp3ins"> To specify the audit filter in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-configuration-options"> configuration file </a> , you must use the YAML format of the configuration file. </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"> Available only in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self"> <span> MongoDB Enterprise </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://cloud.mongodb.com/user#/atlas/login" target="_self"> <span> MongoDB Atlas </span> </a> . </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --auditSchema </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--auditSchema" title="Permalink to this definition"> <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="std-option-mongos.--auditSchema"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Type </em> : string </p> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : <code class="leafygreen-ui-1l06pbn"> mongo </code> </p> <div> <p> <em> New <!-- --> in version <!-- --> 8.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Specifies the format used for audit logs. You can specify one of the following values for <code class="leafygreen-ui-1l06pbn"> --auditSchema </code> : </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:10%"/> <col style="width:20%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> mongo </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Logs are written in a format designed by MongoDB. </p> <p class="leafygreen-ui-1kp3ins"> For example log messages, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/mongo/#std-label-event-audit-messages-mongo"> mongo Schema Audit Messages <!-- --> . </a> </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> OCSF </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Logs are written in <span class="leafygreen-ui-vm4wms" tabindex="0"> OCSF </span> format. This option provides logs in a standardized format compatible with log processors. </p> <p class="leafygreen-ui-1kp3ins"> For example log messages, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/ocsf/#std-label-event-audit-messages-ocsf"> OCSF Schema Audit Messages <!-- --> . </a> </p> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Profiler Options <a class="headerlink leafygreen-ui-1kepx47" href="#profiler-options" 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="profiler-options"> </div> </a> </h3> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --slowms &lt;integer&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--slowms" title="Permalink to this definition"> <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="std-option-mongos.--slowms"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : 100 </p> <p class="leafygreen-ui-1kp3ins"> The <em> slow </em> operation time threshold, in milliseconds. Operations that run for longer than this threshold are considered <em> slow </em> . </p> <p class="leafygreen-ui-1kp3ins"> When <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.logLevel"> <code class="leafygreen-ui-1l06pbn"> logLevel </code> </a> is set to <code class="leafygreen-ui-1l06pbn"> 0 </code> , MongoDB records <em> slow </em> operations to the diagnostic log at a rate determined by <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-operationProfiling.slowOpSampleRate"> <code class="leafygreen-ui-1l06pbn"> slowOpSampleRate </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> At higher <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.logLevel"> <code class="leafygreen-ui-1l06pbn"> logLevel </code> </a> settings, all operations appear in the diagnostic log regardless of their latency. </p> <p class="leafygreen-ui-1kp3ins"> For <code class="leafygreen-ui-1l06pbn"> mongos </code> instances, affects the diagnostic log only and not the profiler since profiling is not available on <code class="leafygreen-ui-1l06pbn"> mongos </code> . </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --slowOpSampleRate &lt;double&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--slowOpSampleRate" title="Permalink to this definition"> <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="std-option-mongos.--slowOpSampleRate"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : 1.0 </p> <p class="leafygreen-ui-1kp3ins"> The fraction of <em> slow </em> operations that should be logged. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--slowOpSampleRate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --slowOpSampleRate </code> </span> </a> accepts values between 0 and 1, inclusive. </p> <p class="leafygreen-ui-1kp3ins"> For <code class="leafygreen-ui-1l06pbn"> mongos </code> instances, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--slowOpSampleRate" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --slowOpSampleRate </code> </span> </a> affects the diagnostic log only and not the profiler since profiling is not available on <code class="leafygreen-ui-1l06pbn"> mongos </code> . </p> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> LDAP Authentication and Authorization Options <a class="headerlink leafygreen-ui-1kepx47" href="#ldap-authentication-and-authorization-options" 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="ldap-authentication-and-authorization-options"> </div> </a> </h3> <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, LDAP authentication and authorization is deprecated. LDAP is available and will continue to operate without changes throughout the lifetime of MongoDB 8. LDAP will be removed in a future major release. </p> <p class="leafygreen-ui-1kp3ins"> For details, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/LDAP-deprecation/#std-label-ldap-deprecation"> LDAP Deprecation <!-- --> . </a> </p> </div> </div> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ldapServers &lt;host1&gt;:&lt;port&gt;,&lt;host2&gt;:&lt;port&gt;,...,&lt;hostN&gt;:&lt;port&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ldapServers" title="Permalink to this definition"> <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="std-option-mongos.--ldapServers"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Available in MongoDB Enterprise only. </em> </p> <p class="leafygreen-ui-1kp3ins"> The LDAP server against which the <code class="leafygreen-ui-1l06pbn"> mongos </code> authenticates users or determines what actions a user is authorized to perform on a given database. If the LDAP server specified has any replicated instances, you may specify the host and port of each replicated server in a comma-delimited list. </p> <p class="leafygreen-ui-1kp3ins"> If your LDAP infrastructure partitions the LDAP directory over multiple LDAP servers, specify <em> one </em> LDAP server or any of its replicated instances to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapServers" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapServers </code> </span> </a> . MongoDB supports following LDAP referrals as defined in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.rfc-editor.org/rfc/rfc4511.txt" rel="noopener noreferrer"> <span> RFC 4511 4.1.10 </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> . Do not use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapServers" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapServers </code> </span> </a> for listing every LDAP server in your infrastructure. </p> <p class="leafygreen-ui-1kp3ins"> This setting can be configured on a running <code class="leafygreen-ui-1l06pbn"> mongos </code> using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter"> <code class="leafygreen-ui-1l06pbn"> setParameter </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> If unset, <code class="leafygreen-ui-1l06pbn"> mongos </code> cannot use <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-ldap/"> LDAP authentication or authorization <!-- --> . </a> </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ldapValidateLDAPServerConfig &lt;boolean&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ldapValidateLDAPServerConfig" title="Permalink to this definition"> <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="std-option-mongos.--ldapValidateLDAPServerConfig"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Available in MongoDB Enterprise </em> </p> <p class="leafygreen-ui-1kp3ins"> A flag that determines if the <code class="leafygreen-ui-1l06pbn"> mongos </code> instance checks the availability of the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapServers" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> LDAP server(s) </code> </span> </a> as part of its startup: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> true </code> , the <code class="leafygreen-ui-1l06pbn"> mongos </code> instance performs the availability check and only continues to start up if the LDAP server is available. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> false </code> , the <code class="leafygreen-ui-1l06pbn"> mongos </code> instance skips the availability check; i.e. the instance starts up even if the LDAP server is unavailable. </p> </li> </ul> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ldapQueryUser &lt;string&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ldapQueryUser" title="Permalink to this definition"> <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="std-option-mongos.--ldapQueryUser"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Available in MongoDB Enterprise only. </em> </p> <p class="leafygreen-ui-1kp3ins"> The identity with which <code class="leafygreen-ui-1l06pbn"> mongos </code> binds as, when connecting to or performing queries on an LDAP server. </p> <p class="leafygreen-ui-1kp3ins"> Only required if any of the following are true: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Using <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-ldap-external/#std-label-security-ldap-external"> LDAP authorization <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Using an LDAP query for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapUserToDNMapping" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> username transformation </code> . </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The LDAP server disallows anonymous binds </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> You must use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryUser" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryUser </code> </span> </a> with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryPassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryPassword </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> If unset, <code class="leafygreen-ui-1l06pbn"> mongos </code> doesn't attempt to bind to the LDAP server. </p> <p class="leafygreen-ui-1kp3ins"> This setting can be configured on a running <code class="leafygreen-ui-1l06pbn"> mongos </code> using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter"> <code class="leafygreen-ui-1l06pbn"> setParameter </code> . </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"> Windows MongoDB deployments can use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapBindWithOSDefaults" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapBindWithOSDefaults </code> </span> </a> instead of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryUser" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryUser </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryPassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryPassword </code> </span> </a> . You cannot specify both <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryUser" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryUser </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapBindWithOSDefaults" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapBindWithOSDefaults </code> </span> </a> at the same time. </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ldapQueryPassword &lt;string&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ldapQueryPassword" title="Permalink to this definition"> <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="std-option-mongos.--ldapQueryPassword"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Available in MongoDB Enterprise only. </em> </p> <p class="leafygreen-ui-1kp3ins"> The password used to bind to an LDAP server when using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryUser" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryUser </code> </span> </a> . You must use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryPassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryPassword </code> </span> </a> with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryUser" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryUser </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> If unset, <code class="leafygreen-ui-1l06pbn"> mongos </code> doesn't attempt to bind to the LDAP server. </p> <p class="leafygreen-ui-1kp3ins"> This setting can be configured on a running <code class="leafygreen-ui-1l06pbn"> mongos </code> using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter"> <code class="leafygreen-ui-1l06pbn"> setParameter </code> . </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"> Windows MongoDB deployments can use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapBindWithOSDefaults" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapBindWithOSDefaults </code> </span> </a> instead of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryPassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryPassword </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryPassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryPassword </code> </span> </a> . You cannot specify both <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryPassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryPassword </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapBindWithOSDefaults" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapBindWithOSDefaults </code> </span> </a> at the same time. </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ldapBindWithOSDefaults &lt;bool&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ldapBindWithOSDefaults" title="Permalink to this definition"> <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="std-option-mongos.--ldapBindWithOSDefaults"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : false </p> <p class="leafygreen-ui-1kp3ins"> Available in MongoDB Enterprise for the Windows platform only. </p> <p class="leafygreen-ui-1kp3ins"> Allows <code class="leafygreen-ui-1l06pbn"> mongos </code> to authenticate, or bind, using your Windows login credentials when connecting to the LDAP server. </p> <p class="leafygreen-ui-1kp3ins"> Only required if: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Using <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-ldap-external/#std-label-security-ldap-external"> LDAP authorization <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Using an LDAP query for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapUserToDNMapping" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> username transformation </code> . </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The LDAP server disallows anonymous binds </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapBindWithOSDefaults" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapBindWithOSDefaults </code> </span> </a> to replace <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryUser" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryUser </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryPassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryPassword </code> . </span> </a> </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ldapBindMethod &lt;string&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ldapBindMethod" title="Permalink to this definition"> <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="std-option-mongos.--ldapBindMethod"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : simple </p> <p class="leafygreen-ui-1kp3ins"> <em> Available in MongoDB Enterprise only. </em> </p> <p class="leafygreen-ui-1kp3ins"> The method <code class="leafygreen-ui-1l06pbn"> mongos </code> uses to authenticate to an LDAP server. Use with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryUser" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryUser </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapQueryPassword" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapQueryPassword </code> </span> </a> to connect to the LDAP server. </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapBindMethod" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapBindMethod </code> </span> </a> supports the following values: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> simple </code> - <code class="leafygreen-ui-1l06pbn"> mongos </code> uses simple authentication. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> sasl </code> - <code class="leafygreen-ui-1l06pbn"> mongos </code> uses SASL protocol for authentication </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> If you specify <code class="leafygreen-ui-1l06pbn"> sasl </code> , you can configure the available SASL mechanisms using <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapBindSaslMechanisms" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapBindSaslMechanisms </code> </span> </a> . <code class="leafygreen-ui-1l06pbn"> mongos </code> defaults to using <code class="leafygreen-ui-1l06pbn"> DIGEST-MD5 </code> mechanism. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ldapBindSaslMechanisms &lt;string&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ldapBindSaslMechanisms" title="Permalink to this definition"> <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="std-option-mongos.--ldapBindSaslMechanisms"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : DIGEST-MD5 </p> <p class="leafygreen-ui-1kp3ins"> <em> Available in MongoDB Enterprise only. </em> </p> <p class="leafygreen-ui-1kp3ins"> A comma-separated list of SASL mechanisms <code class="leafygreen-ui-1l06pbn"> mongos </code> can use when authenticating to the LDAP server. The <code class="leafygreen-ui-1l06pbn"> mongos </code> and the LDAP server must agree on at least one mechanism. The <code class="leafygreen-ui-1l06pbn"> mongos </code> dynamically loads any SASL mechanism libraries installed on the host machine at runtime. </p> <p class="leafygreen-ui-1kp3ins"> Install and configure the appropriate libraries for the selected SASL mechanism(s) on both the <code class="leafygreen-ui-1l06pbn"> mongos </code> host and the remote LDAP server host. Your operating system may include certain SASL libraries by default. Defer to the documentation associated with each SASL mechanism for guidance on installation and configuration. </p> <p class="leafygreen-ui-1kp3ins"> If using the <code class="leafygreen-ui-1l06pbn"> GSSAPI </code> SASL mechanism for use with <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-security-kerberos"> Kerberos Authentication on Self-Managed Deployments </a> , verify the following for the <code class="leafygreen-ui-1l06pbn"> mongos </code> host machine: </p> <dl> <dt> <code class="leafygreen-ui-1l06pbn"> Linux </code> </dt> <dd class="css-1ufxuu7"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> KRB5_CLIENT_KTNAME </code> environment variable resolves to the name of the client <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-keytab-files"> Linux Keytab Files </a> for the host machine. For more on Kerberos environment variables, please defer to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://web.mit.edu/kerberos/krb5-1.13/doc/admin/env_variables.html" rel="noopener noreferrer"> <span> Kerberos documentation <!-- --> . </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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The client keytab includes a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-kerberos-user-principal"> User Principal </a> for the <code class="leafygreen-ui-1l06pbn"> mongos </code> to use when connecting to the LDAP server and execute LDAP queries. </p> </li> </ul> </dd> <dt> <code class="leafygreen-ui-1l06pbn"> Windows </code> </dt> <dd class="css-1ufxuu7"> If connecting to an Active Directory server, the Windows Kerberos configuration automatically generates a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa380510(v=vs.85).aspx" rel="noopener noreferrer"> <span> Ticket-Granting-Ticket </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> when the user logs onto the system. Set <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapBindWithOSDefaults" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapBindWithOSDefaults </code> </span> </a> to <code class="leafygreen-ui-1l06pbn"> true </code> to allow <code class="leafygreen-ui-1l06pbn"> mongos </code> to use the generated credentials when connecting to the Active Directory server and execute queries. </dd> </dl> <p class="leafygreen-ui-1kp3ins"> Set <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapBindMethod" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapBindMethod </code> </span> </a> to <code class="leafygreen-ui-1l06pbn"> sasl </code> to use this option. </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"> For a complete list of SASL mechanisms see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml" rel="noopener noreferrer"> <span> IANA listing </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> . Defer to the documentation for your LDAP or Active Directory service for identifying the SASL mechanisms compatible with the service. </p> <p class="leafygreen-ui-1kp3ins"> MongoDB is not a source of SASL mechanism libraries, nor is the MongoDB documentation a definitive source for installing or configuring any given SASL mechanism. For documentation and support, defer to the SASL mechanism library vendor or owner. </p> <p class="leafygreen-ui-1kp3ins"> For more information on SASL, defer to the following resources: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For Linux, please see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.cyrusimap.org/sasl/" rel="noopener noreferrer"> <span> Cyrus SASL documentation <!-- --> . </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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> For Windows, please see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://msdn.microsoft.com/en-us/library/cc223500.aspx" rel="noopener noreferrer"> <span> Windows SASL documentation <!-- --> . </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> </p> </li> </ul> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ldapTransportSecurity &lt;string&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ldapTransportSecurity" title="Permalink to this definition"> <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="std-option-mongos.--ldapTransportSecurity"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : tls </p> <p class="leafygreen-ui-1kp3ins"> <em> Available in MongoDB Enterprise only. </em> </p> <p class="leafygreen-ui-1kp3ins"> By default, <code class="leafygreen-ui-1l06pbn"> mongos </code> creates a TLS/SSL secured connection to the LDAP server. </p> <p class="leafygreen-ui-1kp3ins"> For Linux deployments, you must configure the appropriate TLS Options in <code class="leafygreen-ui-1l06pbn"> /etc/openldap/ldap.conf </code> file. Your operating system's package manager creates this file as part of the MongoDB Enterprise installation, via the <code class="leafygreen-ui-1l06pbn"> libldap </code> dependency. See the documentation for <code class="leafygreen-ui-1l06pbn"> TLS Options </code> in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.openldap.org/software/man.cgi?query=ldap.conf&amp;manpath=OpenLDAP+2.4-Release" rel="noopener noreferrer"> <span> ldap.conf OpenLDAP documentation </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> for more complete instructions. </p> <p class="leafygreen-ui-1kp3ins"> For Windows deployment, you must add the LDAP server CA certificates to the Windows certificate management tool. The exact name and functionality of the tool may vary depending on operating system version. Please see the documentation for your version of Windows for more information on certificate management. </p> <p class="leafygreen-ui-1kp3ins"> Set <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapTransportSecurity" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapTransportSecurity </code> </span> </a> to <code class="leafygreen-ui-1l06pbn"> none </code> to disable TLS/SSL between <code class="leafygreen-ui-1l06pbn"> mongos </code> and the LDAP server. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Setting <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapTransportSecurity" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapTransportSecurity </code> </span> </a> to <code class="leafygreen-ui-1l06pbn"> none </code> transmits plaintext information and possibly credentials between <code class="leafygreen-ui-1l06pbn"> mongos </code> and the LDAP server. </p> </div> </div> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ldapTimeoutMS &lt;int&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ldapTimeoutMS" title="Permalink to this definition"> <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="std-option-mongos.--ldapTimeoutMS"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : 10000 </p> <p class="leafygreen-ui-1kp3ins"> <em> Available in MongoDB Enterprise only. </em> </p> <p class="leafygreen-ui-1kp3ins"> The amount of time in milliseconds <code class="leafygreen-ui-1l06pbn"> mongos </code> should wait for an LDAP server to respond to a request. </p> <p class="leafygreen-ui-1kp3ins"> Increasing the value of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapTimeoutMS" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapTimeoutMS </code> </span> </a> may prevent connection failure between the MongoDB server and the LDAP server, if the source of the failure is a connection timeout. Decreasing the value of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapTimeoutMS" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapTimeoutMS </code> </span> </a> reduces the time MongoDB waits for a response from the LDAP server. </p> <p class="leafygreen-ui-1kp3ins"> This setting can be configured on a running <code class="leafygreen-ui-1l06pbn"> mongos </code> using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter"> <code class="leafygreen-ui-1l06pbn"> setParameter </code> . </a> </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ldapRetryCount &lt;int&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ldapRetryCount" title="Permalink to this definition"> <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="std-option-mongos.--ldapRetryCount"> </div> </a> </dt> <dd> <div> <p> <em> New <!-- --> in version <!-- --> 6.1 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> <em> Default </em> : 0 </p> <p class="leafygreen-ui-1kp3ins"> <em> Available in MongoDB Enterprise only. </em> </p> <p class="leafygreen-ui-1kp3ins"> Number of operation retries by the server LDAP manager after a network error. </p> </dd> </dl> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ldapUserToDNMapping &lt;string&gt; </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ldapUserToDNMapping" title="Permalink to this definition"> <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="std-option-mongos.--ldapUserToDNMapping"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <em> Available in MongoDB Enterprise only. </em> </p> <p class="leafygreen-ui-1kp3ins"> Maps the username provided to <code class="leafygreen-ui-1l06pbn"> mongos </code> for authentication to a LDAP Distinguished Name (DN). You may need to use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapUserToDNMapping" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapUserToDNMapping </code> </span> </a> to transform a username into an LDAP DN in the following scenarios: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Performing LDAP authentication with simple LDAP binding, where users authenticate to MongoDB with usernames that are not full LDAP DNs. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Using an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--ldapAuthzQueryTemplate"> <code class="leafygreen-ui-1l06pbn"> LDAP authorization query template </code> </a> that requires a DN. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Transforming the usernames of clients authenticating to Mongo DB using different authentication mechanisms, such as x.509 or kerberos, to a full LDAP DN for authorization. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapUserToDNMapping" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapUserToDNMapping </code> </span> </a> expects a quote-enclosed JSON-string representing an ordered array of documents. Each document contains a regular expression <code class="leafygreen-ui-1l06pbn"> match </code> and either a <code class="leafygreen-ui-1l06pbn"> substitution </code> or <code class="leafygreen-ui-1l06pbn"> ldapQuery </code> template used for transforming the incoming username. </p> <p class="leafygreen-ui-1kp3ins"> Each document in the array has the following form: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n match: \"&lt;regex&gt;\"\n substitution: \"&lt;ldap&gt;\" | ldapQuery: \"&lt;ldap&gt;\"\n}","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">match</span>: <span class="lg-highlight-string">"&lt;regex&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">substitution</span>: <span class="lg-highlight-string">"&lt;LDAP DN&gt;"</span> <!-- -->| <span class="lg-highlight-attr">ldapQuery</span>: <span class="lg-highlight-string">"&lt;LDAP Query&gt;"</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 class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:10%"/> <col style="width:70%"/> <col style="width:20%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Example </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> match </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An ECMAScript-formatted regular expression (regex) to match against a provided username. Each parenthesis-enclosed section represents a regex capture group used by <code class="leafygreen-ui-1l06pbn"> substitution </code> or <code class="leafygreen-ui-1l06pbn"> ldapQuery </code> . </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> "(.+)ENGINEERING" </code> <code class="leafygreen-ui-1l06pbn"> "(.+)DBA" </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> substitution </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> An LDAP distinguished name (DN) formatting template that converts the authentication name matched by the <code class="leafygreen-ui-1l06pbn"> match </code> regex into a LDAP DN. Each curly bracket-enclosed numeric value is replaced by the corresponding <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.regular-expressions.info/refcapture.html" rel="noopener noreferrer"> <span> regex capture group </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> extracted from the authentication username via the <code class="leafygreen-ui-1l06pbn"> match </code> regex. </p> <p class="leafygreen-ui-1kp3ins"> The result of the substitution must be an <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.ietf.org/rfc/rfc4514.txt" rel="noopener noreferrer"> <span> RFC4514 </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> escaped string. </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> "cn={0},ou=engineering, dc=example,dc=com" </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> ldapQuery </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> A LDAP query formatting template that inserts the authentication name matched by the <code class="leafygreen-ui-1l06pbn"> match </code> regex into an LDAP query URI encoded respecting RFC4515 and RFC4516. Each curly bracket-enclosed numeric value is replaced by the corresponding <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.regular-expressions.info/refcapture.html" rel="noopener noreferrer"> <span> regex capture group </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> extracted from the authentication username via the <code class="leafygreen-ui-1l06pbn"> match </code> expression. <code class="leafygreen-ui-1l06pbn"> mongos </code> executes the query against the LDAP server to retrieve the LDAP DN for the authenticated user. <code class="leafygreen-ui-1l06pbn"> mongos </code> requires exactly one returned result for the transformation to be successful, or <code class="leafygreen-ui-1l06pbn"> mongos </code> skips this transformation. </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> "ou=engineering,dc=example, dc=com??one?(user={0})" </code> </div> </div> </td> </tr> </tbody> </table> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> An explanation of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.ietf.org/rfc/rfc4514.txt" rel="noopener noreferrer"> <span> RFC4514 </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> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4515" rel="noopener noreferrer"> <span> RFC4515 </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> , <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4516" rel="noopener noreferrer"> <span> RFC4516 </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> , or LDAP queries is out of scope for the MongoDB Documentation. Please review the RFC directly or use your preferred LDAP resource. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> For each document in the array, you must use either <code class="leafygreen-ui-1l06pbn"> substitution </code> or <code class="leafygreen-ui-1l06pbn"> ldapQuery </code> . You <em> cannot </em> specify both in the same document. </p> <p class="leafygreen-ui-1kp3ins"> When performing authentication or authorization, <code class="leafygreen-ui-1l06pbn"> mongos </code> steps through each document in the array in the given order, checking the authentication username against the <code class="leafygreen-ui-1l06pbn"> match </code> filter. If a match is found, <code class="leafygreen-ui-1l06pbn"> mongos </code> applies the transformation and uses the output for authenticating the user. <code class="leafygreen-ui-1l06pbn"> mongos </code> does not check the remaining documents in the array. </p> <p class="leafygreen-ui-1kp3ins"> If the given document does not match the provided authentication name, <code class="leafygreen-ui-1l06pbn"> mongos </code> continues through the list of documents to find additional matches. If no matches are found in any document, or the transformation the document describes fails, <code class="leafygreen-ui-1l06pbn"> mongos </code> returns an error. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> mongos </code> also returns an error if one of the transformations cannot be evaluated due to networking or authentication failures to the LDAP server. <code class="leafygreen-ui-1l06pbn"> mongos </code> rejects the connection request and does not check the remaining documents in the array. </p> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.0, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapUserToDNMapping" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapUserToDNMapping </code> </span> </a> accepts an empty string <code class="leafygreen-ui-1l06pbn"> "" </code> or empty array <code class="leafygreen-ui-1l06pbn"> [ ] </code> in place of a mapping documnent. If providing an empty string or empty array to <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapUserToDNMapping" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapUserToDNMapping </code> </span> </a> , MongoDB maps the authenticated username as the LDAP DN. Previously, providing an empty mapping document would cause mapping to fail. </p> <div class="leafygreen-ui-vg7qwp" role="note"> <h2 class="leafygreen-ui-2xicti"> Example </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The following shows two transformation documents. The first document matches against any string ending in <code class="leafygreen-ui-1l06pbn"> @ENGINEERING </code> , placing anything preceeding the suffix into a regex capture group. The second document matches against any string ending in <code class="leafygreen-ui-1l06pbn"> @DBA </code> , placing anything preceeding the suffix into a regex capture group. </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> You must pass the array to --ldapUserToDNMapping as a string. </strong> </h3> <div class="leafygreen-ui-9mycqc"> </div> </div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"[\n {\n match: \"(.+)@ENGINEERING.EXAMPLE.COM\",\n substitution: \"cn={0},ou=engineering,dc=example,dc=com\"\n },\n {\n match: \"(.+)@DBA.EXAMPLE.COM\",\n ldapQuery: \"ou=dba,dc=example,dc=com??one?(user={0})\"\n\n }\n\n]\""} </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">"[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> match: "(.+)@ENGINEERING.EXAMPLE.COM",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> substitution: "cn={0},ou=engineering,dc=example,dc=com"</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> match: "(.+)@DBA.EXAMPLE.COM",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ldapQuery: "ou=dba,dc=example,dc=com??one?(user={0})"</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></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">]"</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"> A user with username <code class="leafygreen-ui-1l06pbn"> [email protected] </code> matches the first document. The regex capture group <code class="leafygreen-ui-1l06pbn"> {0} </code> corresponds to the string <code class="leafygreen-ui-1l06pbn"> alice </code> . The resulting output is the DN <code class="leafygreen-ui-1l06pbn"> "cn=alice,ou=engineering,dc=example,dc=com" </code> . </p> <p class="leafygreen-ui-1kp3ins"> A user with username <code class="leafygreen-ui-1l06pbn"> [email protected] </code> matches the second document. The regex capture group <code class="leafygreen-ui-1l06pbn"> {0} </code> corresponds to the string <code class="leafygreen-ui-1l06pbn"> bob </code> . The resulting output is the LDAP query <code class="leafygreen-ui-1l06pbn"> "ou=dba,dc=example,dc=com??one?(user=bob)" </code> . <code class="leafygreen-ui-1l06pbn"> mongos </code> executes this query against the LDAP server, returning the result <code class="leafygreen-ui-1l06pbn"> "cn=bob,ou=dba,dc=example,dc=com" </code> . </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> If <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ldapUserToDNMapping" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ldapUserToDNMapping </code> </span> </a> is unset, <code class="leafygreen-ui-1l06pbn"> mongos </code> applies no transformations to the username when attempting to authenticate or authorize a user against the LDAP server. </p> <p class="leafygreen-ui-1kp3ins"> This setting can be configured on a running <code class="leafygreen-ui-1l06pbn"> mongos </code> using the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter"> <code class="leafygreen-ui-1l06pbn"> setParameter </code> </a> database command. </p> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Additional Options <a class="headerlink leafygreen-ui-1kepx47" href="#additional-options" 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-options"> </div> </a> </h3> <dl class="option"> <dt> <code class="leafygreen-ui-1l06pbn"> --ipv6 </code> <a class="headerlink leafygreen-ui-1kepx47" href="#std-option-mongos.--ipv6" title="Permalink to this definition"> <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="std-option-mongos.--ipv6"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Enables IPv6 support. <code class="leafygreen-ui-1l06pbn"> mongos </code> disables IPv6 support by default. </p> <p class="leafygreen-ui-1kp3ins"> Setting <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--ipv6" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --ipv6 </code> </span> </a> does <em> not </em> direct the <code class="leafygreen-ui-1l06pbn"> mongos </code> to listen on any local IPv6 addresses or interfaces. To configure the <code class="leafygreen-ui-1l06pbn"> mongos </code> to listen on an IPv6 interface, you must either: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Configure <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--bind_ip" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --bind_ip </code> </span> </a> with one or more IPv6 addresses or hostnames that resolve to IPv6 addresses, <strong> or </strong> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Set <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-option-mongos.--bind_ip_all" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> --bind_ip_all </code> </span> </a> to <code class="leafygreen-ui-1l06pbn"> true </code> . </p> </li> </ul> </dd> </dl> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/expansion-directives/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Externally Sourced Configuration File Values for Self-Managed Deployments <a class="headerlink leafygreen-ui-1kepx47" href="#externally-sourced-configuration-file-values-for-self-managed-deployments" 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="externally-sourced-configuration-file-values-for-self-managed-deployments"> </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="#use-the-__rest-expansion-directive" target="_self"> <span> Use the <code class="css-1kekw28 e1wawog0"> __rest </code> Expansion Directive </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#use-the-__exec-expansion-directive" target="_self"> <span> Use the <code class="css-1kekw28 e1wawog0"> __exec </code> Expansion Directive </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#expansion-directives-reference" target="_self"> <span> Expansion Directives Reference </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#output-the-configuration-file-with-resolved-expansion-directive-values" target="_self"> <span> Output the Configuration File with Resolved Expansion Directive Values </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> MongoDB supports using expansion directives in configuration files to load externally sourced values. Expansion directives can load values for specific <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-configuration-options"> configuration file options </a> <em> or </em> load the entire configuration file. Expansion directives help obscure confidential information like security certificates and passwords. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"storage:\n dbPath: \"/var/lib/mongo\"\nsystemLog:\n destination: file\n path: \"/var/log/mongodb/mongod.log\"\nnet:\n bindIp:\n __exec: \"python /home/user/getIPAddresses.py\"\n type: \"string\"\n trim: \"whitespace\"\n digest: 85fed8997aac3f558e779625f2e51b4d142dff11184308dc6aca06cff26ee9ad\n digest_key: 68656c6c30303030307365637265746d796f6c64667269656e64\n tls:\n mode: requireTLS\n certificateKeyFile: \"/etc/tls/mongod.pem\"\n certificateKeyFilePassword:\n __rest: \"https://myrestserver.example.net/api/config/myCertKeyFilePassword\"\n type: \"string\"\n digest: b08519162ba332985ac18204851949611ef73835ec99067b85723e10113f5c26\n digest_key: 6d795365637265744b65795374756666","programmingLanguage":"YAML"} </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 yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbPath:</span> <span class="lg-highlight-string">"/var/lib/mongo"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">systemLog:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">destination:</span> <span class="lg-highlight-string">file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path:</span> <span class="lg-highlight-string">"/var/log/mongodb/mongod.log"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">__exec:</span> <span class="lg-highlight-string">"python /home/user/getIPAddresses.py"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type:</span> <span class="lg-highlight-string">"string"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">trim:</span> <span class="lg-highlight-string">"whitespace"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">digest:</span> <span class="lg-highlight-string">85fed8997aac3f558e779625f2e51b4d142dff11184308dc6aca06cff26ee9ad</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">digest_key:</span> <span class="lg-highlight-string">68656c6c30303030307365637265746d796f6c64667269656e64</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tls:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode:</span> <span class="lg-highlight-string">requireTLS</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFile:</span> <span class="lg-highlight-string">"/etc/tls/mongod.pem"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFilePassword:</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">__rest:</span> <span class="lg-highlight-string">"https://myrestserver.example.net/api/config/myCertKeyFilePassword"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type:</span> <span class="lg-highlight-string">"string"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">digest:</span> <span class="lg-highlight-string">b08519162ba332985ac18204851949611ef73835ec99067b85723e10113f5c26</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">digest_key:</span> <span class="lg-highlight-string">6d795365637265744b65795374756666</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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the configuration file includes the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> expansion, on Linux/macOS, the read access to the configuration file must be limited to the user running the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> process only. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the configuration file includes the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> expansion, on Linux/macOS, the write access to the configuration file must be limited to the user running the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> process only. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> To use expansion directives, you must specify the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand"> <code class="leafygreen-ui-1l06pbn"> --configExpand </code> </a> command-line option with the complete list of expansion directives used: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --config \"/path/to/config/mongod.conf\" --configExpand \"rest,exec\"","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --config <span class="lg-highlight-string">"/path/to/config/mongod.conf"</span> --configExpand <span class="lg-highlight-string">"rest,exec"</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> <p class="leafygreen-ui-1kp3ins"> If you omit the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand"> <code class="leafygreen-ui-1l06pbn"> --configExpand </code> </a> option <em> or </em> if you do not specify the complete list of expansion directives used in the configuration file, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> returns an error and terminates. You can only specify the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand"> <code class="leafygreen-ui-1l06pbn"> --configExpand </code> </a> option on the command line. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-expansion-directive-rest"> </span> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Use the <code class="leafygreen-ui-1l06pbn"> __rest </code> Expansion Directive <a class="headerlink leafygreen-ui-1kepx47" href="#use-the-__rest-expansion-directive" 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="use-the-__rest-expansion-directive"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> expansion directive loads configuration file values from a <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint. <code class="leafygreen-ui-1l06pbn"> __rest </code> supports loading specific values in the configuration file <em> or </em> loading the entire configuration file. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-5"> <div aria-label="Tabs to describe usage of full-file-rest/single-val-rest" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_2p9gdxyvi" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_6q8y86xrr" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Specific Value </div> </button> <button aria-controls="_jw7l1tp7i" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_c8oy494lf" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Full Configuration File </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="_4kpkbet32" class="" id="_x0p1v4m2p" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> The following configuration file uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> expansion directive to load the setting <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.certificateKeyFilePassword"> <code class="leafygreen-ui-1l06pbn"> net.tls.certificateKeyFilePassword </code> </a> value from an external <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"storage:\n dbPath: \"/var/lib/mongo\"\nsystemLog:\n destination: file\n path: \"/var/log/mongodb/mongod.log\"\nnet:\n bindIp: 192.51.100.24,127.0.0.1\n tls:\n mode: requireTLS\n certificateKeyFile: \"/etc/tls/mongod.pem\"\n certificateKeyFilePassword:\n __rest: \"https://myrestserver.example.net/api/config/myCertKeyFilePassword\"\n type: \"string\"","programmingLanguage":"YAML"} </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 yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbPath:</span> <span class="lg-highlight-string">"/var/lib/mongo"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">systemLog:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">destination:</span> <span class="lg-highlight-string">file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path:</span> <span class="lg-highlight-string">"/var/log/mongodb/mongod.log"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span> <span class="lg-highlight-number">192.51</span><span class="lg-highlight-number">.100</span><span class="lg-highlight-number">.24</span><span class="lg-highlight-string">,127.0.0.1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tls:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode:</span> <span class="lg-highlight-string">requireTLS</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFile:</span> <span class="lg-highlight-string">"/etc/tls/mongod.pem"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFilePassword:</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">__rest:</span> <span class="lg-highlight-string">"https://myrestserver.example.net/api/config/myCertKeyFilePassword"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type:</span> <span class="lg-highlight-string">"string"</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> <dl> <dt> File Permission </dt> <dd class="css-1ufxuu7"> If the configuration file includes the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> expansion, on Linux/macOS, the read access to the configuration file must be limited to the user running the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> process only. </dd> <dt> Expansion Parsing </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> To parse the <code class="leafygreen-ui-1l06pbn"> __rest </code> blocks, start the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand"> <code class="leafygreen-ui-1l06pbn"> --configExpand "rest" </code> </a> option. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> issues a <code class="leafygreen-ui-1l06pbn"> GET </code> request against specified URL. If successful, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> replaces the value of <code class="leafygreen-ui-1l06pbn"> certificateKeyFilePassword </code> with the returned value. If the URL fails to resolve or if the <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint returns an invalid value, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> throws an error and terminates. </p> </dd> </dl> </div> </div> </div> <div> <div aria-labelledby="_5kf6ca95a" class="leafygreen-ui-38lglc" id="_jkugjbb5w" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> The following configuration file uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> expansion directive to load the configuration file from an external <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint. The expansion directive and its options <strong> must </strong> be the only values specified in the configuration file. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"__rest: \"https://myrestserver.example.net/api/config/fullConfig\"\ntype: \"yaml\"","programmingLanguage":"YAML"} </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 yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">__rest:</span> <span class="lg-highlight-string">"https://myrestserver.example.net/api/config/fullConfig"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">type:</span> <span class="lg-highlight-string">"yaml"</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> <dl> <dt> File Permission </dt> <dd class="css-1ufxuu7"> If the configuration file includes the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> expansion, on Linux/macOS, the read access to the configuration file must be limited to the user running the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> process only. </dd> <dt> Expansion Parsing </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> To parse the <code class="leafygreen-ui-1l06pbn"> __rest </code> blocks, start the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand"> <code class="leafygreen-ui-1l06pbn"> --configExpand "rest" </code> </a> option. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> issues a <code class="leafygreen-ui-1l06pbn"> GET </code> request against the specified URL. If successful, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> parses the returned configuration <code class="leafygreen-ui-1l06pbn"> yaml </code> file and uses it during startup. If the URL fails to resolve or return a properly formatted <code class="leafygreen-ui-1l06pbn"> yaml </code> file, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> throws an error and terminates. </p> </dd> </dl> </div> </div> </div> </div> </div> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The value returned by the specified <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint <strong> cannot </strong> include any additional expansion directives. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> does <strong> not </strong> perform additional processing on the returned data and will terminate with an error code if the returned data includes additional expansion directives. </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-expansion-directive-exec"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Use the <code class="leafygreen-ui-1l06pbn"> __exec </code> Expansion Directive <a class="headerlink leafygreen-ui-1kepx47" href="#use-the-__exec-expansion-directive" 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="use-the-__exec-expansion-directive"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> expansion directive loads configuration file values from a shell or terminal command. <code class="leafygreen-ui-1l06pbn"> __exec </code> supports loading specific values in the configuration file <em> or </em> loading the entire configuration file. </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-7"> <div aria-label="Tabs to describe usage of full-file-yaml/single-val-yaml" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_bk5d2wdpj" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_42ie21jga" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Specific Value </div> </button> <button aria-controls="_yyfg6joq3" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_q3tl781op" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Full Configuration File </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="_ksti6j8jw" class="" id="_w59tvbvv0" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> The following example configuration file uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> expansion directive to to load the setting <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.certificateKeyFilePassword"> <code class="leafygreen-ui-1l06pbn"> net.tls.certificateKeyFilePassword </code> </a> value from the output of a shell or terminal command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"storage:\n dbPath: \"/var/lib/mongo\"\nsystemLog:\n destination: file\n path: \"/var/log/mongodb/mongod.log\"\nnet:\n bindIp: 192.51.100.24,127.0.0.1\n tls:\n mode: requireTLS\n certificateKeyFile: \"/etc/tls/mongod.pem\"\n certificateKeyFilePassword:\n __exec: \"python /home/myUserName/getPEMPassword.py\"\n type: \"string\"","programmingLanguage":"YAML"} </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 yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbPath:</span> <span class="lg-highlight-string">"/var/lib/mongo"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">systemLog:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">destination:</span> <span class="lg-highlight-string">file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path:</span> <span class="lg-highlight-string">"/var/log/mongodb/mongod.log"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span> <span class="lg-highlight-number">192.51</span><span class="lg-highlight-number">.100</span><span class="lg-highlight-number">.24</span><span class="lg-highlight-string">,127.0.0.1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tls:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode:</span> <span class="lg-highlight-string">requireTLS</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFile:</span> <span class="lg-highlight-string">"/etc/tls/mongod.pem"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFilePassword:</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">__exec:</span> <span class="lg-highlight-string">"python /home/myUserName/getPEMPassword.py"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type:</span> <span class="lg-highlight-string">"string"</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> <dl> <dt> File Permission </dt> <dd class="css-1ufxuu7"> If the configuration file includes the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> expansion, on Linux/macOS, the write access to the configuration file must be limited to the user running the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> process only. </dd> <dt> Expansion Parsing </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> To parse the <code class="leafygreen-ui-1l06pbn"> __exec </code> blocks, start the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand"> <code class="leafygreen-ui-1l06pbn"> --configExpand "exec" </code> </a> option. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> attempts to execute the specified operation. If the command executes successfully, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> replaces the value of <code class="leafygreen-ui-1l06pbn"> certificateKeyFilePassword </code> with the returned value. If the command fails or returns an invalid value for the configuration file setting, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> throws an error and terminates. </p> </dd> </dl> </div> </div> </div> <div> <div aria-labelledby="_61aogwqrv" class="leafygreen-ui-38lglc" id="_9giydpxoc" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> The following example configuration file uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> expansion directive to load the configuration file from the output of a shell or terminal command. The <code class="leafygreen-ui-1l06pbn"> __exec </code> expansion directive and its options <strong> must </strong> be the only values specified in the configuration file. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"__exec: \"python /home/myUserName/getFullConfig.py\"\ntype: \"yaml\"","programmingLanguage":"YAML"} </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 yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">__exec:</span> <span class="lg-highlight-string">"python /home/myUserName/getFullConfig.py"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">type:</span> <span class="lg-highlight-string">"yaml"</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> <dl> <dt> File Permission </dt> <dd class="css-1ufxuu7"> If the configuration file includes the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> expansion, on Linux/macOS, the write access to the configuration file must be limited to the user running the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> process only. </dd> <dt> Expansion Parsing </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> To parse the <code class="leafygreen-ui-1l06pbn"> __exec </code> blocks, start the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand"> <code class="leafygreen-ui-1l06pbn"> --configExpand "rest" </code> </a> option. </p> <p class="leafygreen-ui-1kp3ins"> If the command executes successfully, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> parses the returned configuration <code class="leafygreen-ui-1l06pbn"> yaml </code> file and uses it during startup. If the command fails or returns an invalid <code class="leafygreen-ui-1l06pbn"> yaml </code> file, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> throws an error and terminates. </p> </dd> </dl> </div> </div> </div> </div> </div> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The data returned by executing the specified <code class="leafygreen-ui-1l06pbn"> __exec </code> string <strong> cannot </strong> include any additional expansion directives. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> does <strong> not </strong> perform additional processing on the returned data and will terminate with an error code if the returned data includes additional expansion directives. </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-expansion-directives"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Expansion Directives Reference <a class="headerlink leafygreen-ui-1kepx47" href="#expansion-directives-reference" 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="expansion-directives-reference"> </div> </a> </h2> <dl class="configexpansion"> <dt> <code class="leafygreen-ui-1l06pbn"> __rest </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-configexpansion-configexpansion.__rest" title="Permalink to this definition"> <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="mongodb-configexpansion-configexpansion.__rest"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> expansion directive loads configuration file values from a <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> supports loading specific values in the configuration file <em> or </em> loading the entire configuration file. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> then starts using the externally sourced values as part of its configuration. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> expansion directive has the following syntax: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To specify a <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint for a specific configuration file setting or settings: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;some&gt;:\n __rest: \"&lt;string&gt;\"\n type: \"string\"\n trim: \"none|whitespace\"\n digest: \"&lt;string&gt;\"\n digest_key: \"&lt;string&gt;\"","programmingLanguage":"YAML"} </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 yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">&lt;some</span> <span class="lg-highlight-string">configuration</span> <span class="lg-highlight-string">file</span> <span class="lg-highlight-string">setting&gt;:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">__rest:</span> <span class="lg-highlight-string">"&lt;string&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type:</span> <span class="lg-highlight-string">"string"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">trim:</span> <span class="lg-highlight-string">"none|whitespace"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">digest:</span> <span class="lg-highlight-string">"&lt;string&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">digest_key:</span> <span class="lg-highlight-string">"&lt;string&gt;"</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To specify a <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint for the entire configuration file: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"__rest: \"&lt;string&gt;\"\ntype: \"yaml\"\ntrim: \"none|whitespace\"","programmingLanguage":"YAML"} </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 yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">__rest:</span> <span class="lg-highlight-string">"&lt;string&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">type:</span> <span class="lg-highlight-string">"yaml"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">trim:</span> <span class="lg-highlight-string">"none|whitespace"</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> <p class="leafygreen-ui-1kp3ins"> If specifying the entire configuration file via <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint, the expansion directive and its options <strong> must </strong> be the only values specified in the configuration file. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> takes the following fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:15%"/> <col style="width:15%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-rest" target="_self"> <span> __rest </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-expansion-rest"> </span> <p class="leafygreen-ui-1kp3ins"> <em> Required </em> The URL against which the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> issues a <code class="leafygreen-ui-1l06pbn"> GET </code> request to retrieve the externally sourced value. </p> <p class="leafygreen-ui-1kp3ins"> For non-localhost <code class="leafygreen-ui-1l06pbn"> REST </code> endpoints (e.g. a <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint hosted on a remote server), <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> requires encrypted ( <code class="leafygreen-ui-1l06pbn"> https:// </code> ) URLs where both the host machine and the remote server support TLS 1.1 or later. </p> <p class="leafygreen-ui-1kp3ins"> If the <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint specified in the URL requires authentication, encode credentials into the URL with the standard <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc3986#section-3.2.1" rel="noopener noreferrer"> <span> RFC 3986 User Information </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> format. </p> <p class="leafygreen-ui-1kp3ins"> For localhost <code class="leafygreen-ui-1l06pbn"> REST </code> endpoints (e.g. a <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint listening on the host machine), <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> allows unencrypted ( <code class="leafygreen-ui-1l06pbn"> http:// </code> ) URLs. </p> <p class="leafygreen-ui-1kp3ins"> <strong class="css-rws738"> IMPORTANT: </strong> The value returned by the specified <code class="leafygreen-ui-1l06pbn"> REST </code> endpoint <strong> cannot </strong> include any additional expansion directives. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> does <strong> not </strong> perform additional processing on the returned data and will terminate with an error code if the returned data includes additional expansion directives. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> type </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> <em> Optional </em> Controls how <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> parses the returned value from the specified URL. </p> <p class="leafygreen-ui-1kp3ins"> Possible values are: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> string </code> ( <em> Default </em> ) </p> <p class="leafygreen-ui-1kp3ins"> Directs <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> to parse the returned data as a literal string. If specifying <code class="leafygreen-ui-1l06pbn"> string </code> , the entire <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> block and supporting options must be nested under the field for which you are loading externally sourced values. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> yaml </code> </p> <p class="leafygreen-ui-1kp3ins"> Directs <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> to parse the returned data as a <code class="leafygreen-ui-1l06pbn"> yaml </code> formatted file. If specifying <code class="leafygreen-ui-1l06pbn"> yaml </code> , the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> block must be the only content in the configuration file. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> replaces the configuration file contents with the <code class="leafygreen-ui-1l06pbn"> yaml </code> retrieved from the REST resource. </p> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> trim </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <em> Optional </em> Specify <code class="leafygreen-ui-1l06pbn"> whitespace </code> to direct <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> to trim any leading or trailing whitespace, specifically occurrences of <code class="leafygreen-ui-1l06pbn"> " " </code> , <code class="leafygreen-ui-1l06pbn"> "\r" </code> , <code class="leafygreen-ui-1l06pbn"> "\n" </code> , <code class="leafygreen-ui-1l06pbn"> "\t" </code> , <code class="leafygreen-ui-1l06pbn"> "\v" </code> , and <code class="leafygreen-ui-1l06pbn"> "\f" </code> . Defaults to <code class="leafygreen-ui-1l06pbn"> none </code> , or no trimming. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-rest-digest" target="_self"> <span> digest </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-expansion-rest-digest"> </span> <p class="leafygreen-ui-1kp3ins"> <em> Optional </em> . The SHA-256 digest of the expansion result. </p> <p class="leafygreen-ui-1kp3ins"> If specified, you must also specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-rest-digest-key" target="_self"> <span> digest_key <!-- --> . </span> </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-rest-digest-key" target="_self"> <span> digest_key </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-expansion-rest-digest-key"> </span> <p class="leafygreen-ui-1kp3ins"> <em> Optional </em> . The hexadecimal string representation of the secret used to calculate the SHA-256 <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-rest-digest" target="_self"> <span> digest <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> If specified, you must also specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-rest-digest" target="_self"> <span> digest <!-- --> . </span> </a> </p> </div> </div> </td> </tr> </tbody> </table> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the configuration file includes the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> expansion, on Linux/macOS, the read access to the configuration file must be limited to the user running the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> process only. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To enable parsing of the <code class="leafygreen-ui-1l06pbn"> __rest </code> expansion directive, start the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand"> <code class="leafygreen-ui-1l06pbn"> --configExpand "rest" </code> </a> option. </p> </li> </ul> </div> </div> <p class="leafygreen-ui-1kp3ins"> For examples, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-directive-rest" target="_self"> <span> Use the <code class="leafygreen-ui-1l06pbn"> __rest </code> Expansion Directive <!-- --> . </span> </a> </p> </dd> </dl> <dl class="configexpansion"> <dt> <code class="leafygreen-ui-1l06pbn"> __exec </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-configexpansion-configexpansion.__exec" title="Permalink to this definition"> <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="mongodb-configexpansion-configexpansion.__exec"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> expansion directive loads configuration file values from the output of a shell or terminal command. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> supports loading specific values in the configuration file <em> or </em> loading the entire configuration file. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> then starts using the externally sourced values as part of its configuration. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> expansion directive has the following syntax: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To specify a shell or terminal command for a specific configuration file setting or settings: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;some&gt;:\n __exec: \"&lt;string&gt;\"\n type: \"string\"\n trim: \"none|whitespace\"","programmingLanguage":"YAML"} </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 yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">&lt;some</span> <span class="lg-highlight-string">configuration</span> <span class="lg-highlight-string">file</span> <span class="lg-highlight-string">setting&gt;:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">__exec:</span> <span class="lg-highlight-string">"&lt;string&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type:</span> <span class="lg-highlight-string">"string"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">trim:</span> <span class="lg-highlight-string">"none|whitespace"</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> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To specify a a shell or terminal command for the entire configuration file: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"__exec: \"&lt;string&gt;\"\ntype: \"yaml\"\ntrim: \"none|whitespace\"","programmingLanguage":"YAML"} </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 yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">__exec:</span> <span class="lg-highlight-string">"&lt;string&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">type:</span> <span class="lg-highlight-string">"yaml"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">trim:</span> <span class="lg-highlight-string">"none|whitespace"</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> <p class="leafygreen-ui-1kp3ins"> If specifying the entire configuration file via a terminal or shell command, the expansion directive and its options <strong> must </strong> be the only values specified in the configuration file. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> takes the following fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:15%"/> <col style="width:15%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> __exec </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> <em> Required </em> The string which the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> executes on the terminal or shell to retrieve the externally sourced value. </p> <p class="leafygreen-ui-1kp3ins"> On Linux and OSX hosts, execution is handled via POSIX <code class="leafygreen-ui-1l06pbn"> popen() </code> . On Windows hosts, execution is handled via the process control API. <code class="leafygreen-ui-1l06pbn"> __exec </code> opens a read-only pipe as the same user that started the <code class="leafygreen-ui-1l06pbn"> mongod </code> or <code class="leafygreen-ui-1l06pbn"> mongos </code> . </p> <p class="leafygreen-ui-1kp3ins"> <strong class="css-rws738"> IMPORTANT: </strong> The data returned by executing the specified command <strong> cannot </strong> include any additional expansion directives. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> does <strong> not </strong> perform additional processing on the returned data and will terminate with an error code if the returned data includes additional expansion directives. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> type </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> <em> Optional </em> Controls how <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> parses the value returned by the executed command. </p> <p class="leafygreen-ui-1kp3ins"> Possible values are: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> string </code> ( <em> Default </em> ) </p> <p class="leafygreen-ui-1kp3ins"> Directs <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> to parse the returned data as a literal string. If specifying <code class="leafygreen-ui-1l06pbn"> string </code> , the entire <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> block and supporting options must be nested under the field for which you are loading externally sourced values. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> yaml </code> </p> <p class="leafygreen-ui-1kp3ins"> Directs <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> to parse the returned data as a <code class="leafygreen-ui-1l06pbn"> yaml </code> formatted file. If specifying <code class="leafygreen-ui-1l06pbn"> yaml </code> , the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> block must be the only content in the configuration file. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> replaces the configuration file contents with the <code class="leafygreen-ui-1l06pbn"> yaml </code> retrieved from the executed command. </p> </li> </ul> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> trim </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <em> Optional </em> Specify <code class="leafygreen-ui-1l06pbn"> whitespace </code> to direct <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> to trim any leading or trailing whitespace, specifically occurrences of <code class="leafygreen-ui-1l06pbn"> " " </code> , <code class="leafygreen-ui-1l06pbn"> "\r" </code> , <code class="leafygreen-ui-1l06pbn"> "\n" </code> , <code class="leafygreen-ui-1l06pbn"> "\t" </code> , <code class="leafygreen-ui-1l06pbn"> "\v" </code> , and <code class="leafygreen-ui-1l06pbn"> "\f" </code> . Defaults to <code class="leafygreen-ui-1l06pbn"> none </code> , or no trimming. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-exec-digest" target="_self"> <span> digest </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-expansion-exec-digest"> </span> <p class="leafygreen-ui-1kp3ins"> <em> Optional </em> . The SHA-256 digest of the expansion result. </p> <p class="leafygreen-ui-1kp3ins"> If specified, you must also specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-exec-digest-key" target="_self"> <span> digest_key </span> </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-exec-digest-key" target="_self"> <span> digest_key </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-expansion-exec-digest-key"> </span> <p class="leafygreen-ui-1kp3ins"> <em> Optional </em> . The hexadecimal string representation of the secret used to calculate the SHA-256 <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-exec-digest" target="_self"> <span> digest <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> If specified, you must also specify the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-exec-digest" target="_self"> <span> digest </span> </a> </p> </div> </div> </td> </tr> </tbody> </table> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If the configuration file includes the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__exec" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __exec </code> </span> </a> expansion, on Linux/macOS, the write access to the configuration file must be limited to the user running the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> process only. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> To enable parsing of the <code class="leafygreen-ui-1l06pbn"> __exec </code> expansion directives, start the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand"> <code class="leafygreen-ui-1l06pbn"> --configExpand "exec" </code> </a> option. </p> </li> </ul> </div> </div> <p class="leafygreen-ui-1kp3ins"> For examples, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-expansion-directive-exec" target="_self"> <span> Use the <code class="leafygreen-ui-1l06pbn"> __exec </code> Expansion Directive <!-- --> . </span> </a> </p> </dd> </dl> <span class="leafygreen-ui-1qnjd6d" id="std-label-expansion-directive-output"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Output the Configuration File with Resolved Expansion Directive Values <a class="headerlink leafygreen-ui-1kepx47" href="#output-the-configuration-file-with-resolved-expansion-directive-values" 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="output-the-configuration-file-with-resolved-expansion-directive-values"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> You can test the final output of a configuration file that specifies one or more expansion directives by starting the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--outputConfig"> <code class="leafygreen-ui-1l06pbn"> --outputConfig </code> </a> option. A <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> started with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--outputConfig"> <code class="leafygreen-ui-1l06pbn"> --outputConfig </code> </a> outputs the resolved YAML configuration document to <code class="leafygreen-ui-1l06pbn"> stdout </code> and halts. If any expansion directive specified in the configuration file returns additional expansion directives, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> throws an error and terminates. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--outputConfig"> <code class="leafygreen-ui-1l06pbn"> --outputConfig </code> </a> option returns the resolved values for any field using an expansion directive. This includes any private or sensitive information previously obscured by using an external source for the configuration option. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> For example, the following configuration file <code class="leafygreen-ui-1l06pbn"> mongod.conf </code> contains a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> expansion directive: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"storage:\n dbPath: \"/var/lib/mongo\"\nsystemLog:\n destination: file\n path: \"/var/log/mongodb/mongod.log\"\nnet:\n port:\n __rest: \"https://mongoconf.example.net:8080/record/1\"\n type: string","programmingLanguage":"YAML"} </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 yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbPath:</span> <span class="lg-highlight-string">"/var/lib/mongo"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">systemLog:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">destination:</span> <span class="lg-highlight-string">file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path:</span> <span class="lg-highlight-string">"/var/log/mongodb/mongod.log"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">port:</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">__rest:</span> <span class="lg-highlight-string">"https://mongoconf.example.net:8080/record/1"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type:</span> <span class="lg-highlight-string">string</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> <p class="leafygreen-ui-1kp3ins"> The string recorded at the specified URL is <code class="leafygreen-ui-1l06pbn"> 20128 </code> </p> <p class="leafygreen-ui-1kp3ins"> If the configuration file includes the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-configexpansion-configexpansion.__rest" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> __rest </code> </span> </a> expansion, on Linux/macOS, the read access to the configuration file must be limited to the user running the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> process only. </p> <p class="leafygreen-ui-1kp3ins"> Start the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand"> <code class="leafygreen-ui-1l06pbn"> --configExpand "rest" </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--outputConfig"> <code class="leafygreen-ui-1l06pbn"> --outputConfig </code> </a> options: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod -f mongod.conf --configExpand rest --outputConfig","programmingLanguage":"YAML"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">mongod</span> <span class="lg-highlight-string">-f</span> <span class="lg-highlight-string">mongod.conf</span> <span class="lg-highlight-string">--configExpand</span> <span class="lg-highlight-string">rest</span> <span class="lg-highlight-string">--outputConfig</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> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> outputs the following to <code class="leafygreen-ui-1l06pbn"> stdout </code> before terminating: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"config: mongod.conf\nstorage:\n dbPath: \"/var/lib/mongo\"\nsystemLog:\n destination: file\n path: \"/var/log/mongodb/mongod.log\"\nnet:\n port: 20128\noutputConfig: true","programmingLanguage":"YAML"} </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 yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">config:</span> <span class="lg-highlight-string">mongod.conf</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbPath:</span> <span class="lg-highlight-string">"/var/lib/mongo"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">systemLog:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">destination:</span> <span class="lg-highlight-string">file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path:</span> <span class="lg-highlight-string">"/var/log/mongodb/mongod.log"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">port:</span> <span class="lg-highlight-number">20128</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">outputConfig:</span> <span class="lg-highlight-literal">true</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> </section> </section>
https://www.mongodb.com/docs/manual/reference/mongodb-extended-json-v1/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> MongoDB Extended JSON (v1) <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-extended-json--v1-" 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="mongodb-extended-json--v1-"> </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="#mongodb-extended-json-v1-and-mongodb-drivers" target="_self"> <span> MongoDB Extended JSON v1 and MongoDB Drivers </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#parsers-and-supported-format" target="_self"> <span> Parsers and Supported Format </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#bson-data-types-and-associated-representations" target="_self"> <span> BSON Data Types and Associated Representations </span> </a> </li> </ul> </div> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Disambiguation </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The following page discusses MongoDB Extended JSON v1 (Legacy extended JSON). For discussion on MongoDB Extended JSON v2, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/"> MongoDB Extended JSON (v2) <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> For supported data types in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> , see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/" target="_self"> <span> mongosh Data Types <!-- --> . </span> </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-JSON"> JSON </a> can only represent a subset of the types supported by <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-BSON"> BSON </a> . To preserve type information, MongoDB adds the following extensions to the JSON format: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <em> Strict mode </em> . Strict mode representations of BSON types conform to the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.json.org" rel="noopener noreferrer"> <span> JSON RFC </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> . Any JSON parser can parse these strict mode representations as key/value pairs; however, only the MongoDB internal JSON parser recognizes the type information conveyed by the format. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> mongo </code> <em> Shell mode </em> . The MongoDB internal JSON parser and the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> shell can parse this mode. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The representation used for the various data types depends on the context in which the JSON is parsed. </p> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> MongoDB Extended JSON v1 and MongoDB Drivers <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-extended-json-v1-and-mongodb-drivers" 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="mongodb-extended-json-v1-and-mongodb-drivers"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following drivers use the Extended JSON v1.0 (Legacy) </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> C# </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ruby </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For the other drivers, refer to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/"> MongoDB Extended JSON (v2) <!-- --> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Parsers and Supported Format <a class="headerlink leafygreen-ui-1kepx47" href="#parsers-and-supported-format" 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="parsers-and-supported-format"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Input in Strict Mode <a class="headerlink leafygreen-ui-1kepx47" href="#input-in-strict-mode" 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="input-in-strict-mode"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following can parse representations in strict mode <em> with </em> recognition of the type information. </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/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoimport </code> </span> </a> version 4.0 and earlier </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> --query </code> option of various MongoDB tools </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/products/compass" target="_self"> <span> MongoDB Compass </span> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Other JSON parsers, including <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> shell, can parse strict mode representations as key/value pairs, but <em> without </em> recognition of the type information. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Input in <code class="leafygreen-ui-1l06pbn"> mongo </code> Shell Mode <a class="headerlink leafygreen-ui-1kepx47" href="#input-in-mongo-shell-mode" 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="input-in-mongo-shell-mode"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following can parse representations in <code class="leafygreen-ui-1l06pbn"> mongo </code> shell mode <em> with </em> recognition of the type information. </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/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoimport </code> </span> </a> version 4.0 and earlier </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> --query </code> option of various MongoDB tools </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> shell </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Output in Strict mode <a class="headerlink leafygreen-ui-1kepx47" href="#output-in-strict-mode" 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="output-in-strict-mode"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Before version 4.2, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongoexport </code> </span> </a> outputs data in <em> Strict mode </em> of MongoDB Extended JSON v1. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Output in <code class="leafygreen-ui-1l06pbn"> mongo </code> Shell Mode <a class="headerlink leafygreen-ui-1kepx47" href="#output-in-mongo-shell-mode" 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="output-in-mongo-shell-mode"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Before version 4.2, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/bsondump/#mongodb-binary-bin.bsondump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> bsondump </code> </span> </a> outputs in <code class="leafygreen-ui-1l06pbn"> mongo </code> <em> Shell mode </em> . </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> BSON Data Types and Associated Representations <a class="headerlink leafygreen-ui-1kepx47" href="#bson-data-types-and-associated-representations" 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="bson-data-types-and-associated-representations"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following presents the BSON data types and the associated representations in <em> Strict mode </em> and <code class="leafygreen-ui-1l06pbn"> mongo </code> <em> Shell mode </em> . </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Binary <a class="headerlink leafygreen-ui-1kepx47" href="#binary" 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="binary"> </div> </a> </h3> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> data_binary </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-data_binary" title="Permalink to this definition"> <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="mongodb-bsontype-data_binary"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Strict Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> Shell Mode </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$binary\": \"&lt;bindata&gt;\", \"$type\": \"&lt;t&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{ "$binary": "&lt;bindata&gt;", "$type": "&lt;t&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"BinData ( &lt;t&gt;, &lt;bindata&gt; )"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">BinData ( &lt;t&gt;, &lt;bindata&gt; )</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;bindata&gt; </code> is the base64 representation of a binary string. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;t&gt; </code> is a representation of a single byte indicating the data type. In <em> Strict mode </em> it is a hexadecimal string, and in <em> Shell mode </em> it is an integer. See the extended bson documentation. <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://bsonspec.org/spec.html" rel="noopener noreferrer"> <span> http://bsonspec.org/spec.html </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> </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Date <a class="headerlink leafygreen-ui-1kepx47" href="#date" 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="date"> </div> </a> </h3> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> data_date </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-data_date" title="Permalink to this definition"> <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="mongodb-bsontype-data_date"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Strict Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> Shell Mode </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$date\": \"&lt;date&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$date": "&lt;date&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"new Date ( &lt;date&gt; )"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">new Date ( &lt;date&gt; )</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> In <em> Strict mode </em> , <code class="leafygreen-ui-1l06pbn"> &lt;date&gt; </code> is an ISO-8601 date format with a mandatory time zone field following the template <code class="leafygreen-ui-1l06pbn"> YYYY-MM-DDTHH:mm:ss.mmm&lt;+/-Offset&gt; </code> . </p> <p class="leafygreen-ui-1kp3ins"> In <em> Shell mode </em> , <code class="leafygreen-ui-1l06pbn"> &lt;date&gt; </code> is the JSON representation of a 64-bit signed integer giving the number of milliseconds since epoch UTC. </p> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Timestamp <a class="headerlink leafygreen-ui-1kepx47" href="#timestamp" 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="timestamp"> </div> </a> </h3> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> data_timestamp </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-data_timestamp" title="Permalink to this definition"> <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="mongodb-bsontype-data_timestamp"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Strict Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> Shell Mode </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$timestamp\": { \"t\": &lt;t&gt;, \"i\": <i> } }</i>"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{ "$timestamp": { "t": &lt;t&gt;, "i": &lt;i&gt; } }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Timestamp( &lt;t&gt;, <i> )</i>"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">Timestamp( &lt;t&gt;, &lt;i&gt; )</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;t&gt; </code> is the JSON representation of a 32-bit unsigned integer for seconds since epoch. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;i&gt; </code> is a 32-bit unsigned integer for the increment. </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Regular Expression <a class="headerlink leafygreen-ui-1kepx47" href="#regular-expression" 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="regular-expression"> </div> </a> </h3> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> data_regex </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-data_regex" title="Permalink to this definition"> <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="mongodb-bsontype-data_regex"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Strict Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> Shell Mode </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$regex\": \"&lt;sregex&gt;\", \"$options\": \"&lt;soptions&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{ "$regex": "&lt;sRegex&gt;", "$options": "&lt;sOptions&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"/&lt;jregex&gt;/&lt;joptions&gt;"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">/&lt;jRegex&gt;/&lt;jOptions&gt;</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;sRegex&gt; </code> is a string of valid JSON characters. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;jRegex&gt; </code> is a string that may contain valid JSON characters and unescaped double quote ( <code class="leafygreen-ui-1l06pbn"> " </code> ) characters, but may not contain unescaped forward slash ( <code class="leafygreen-ui-1l06pbn"> / </code> ) characters. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;sOptions&gt; </code> is a string containing the regex options represented by the letters of the alphabet. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;jOptions&gt; </code> is a string that may contain only the characters 'g', 'i', 'm' and 's' (added in v1.9). Because the <code class="leafygreen-ui-1l06pbn"> JavaScript </code> and <code class="leafygreen-ui-1l06pbn"> mongo Shell </code> representations support a limited range of options, any nonconforming options will be dropped when converting to this representation. </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> OID <a class="headerlink leafygreen-ui-1kepx47" href="#oid" 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="oid"> </div> </a> </h3> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> data_oid </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-data_oid" title="Permalink to this definition"> <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="mongodb-bsontype-data_oid"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Strict Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> Shell Mode </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$oid\": \"&lt;id&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$oid": "&lt;id&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ObjectId( \"&lt;id&gt;\" )"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">ObjectId( "&lt;id&gt;" )</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;id&gt; </code> is a 24-character hexadecimal string. </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> DB Reference <a class="headerlink leafygreen-ui-1kepx47" href="#db-reference" 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="db-reference"> </div> </a> </h3> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> data_ref </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-data_ref" title="Permalink to this definition"> <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="mongodb-bsontype-data_ref"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Strict Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> Shell Mode </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$ref\": \"&lt;name&gt;\", \"$id\": \"&lt;id&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{ "$ref": "&lt;name&gt;", "$id": "&lt;id&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"DBRef(\"&lt;name&gt;\", \"&lt;id&gt;\")"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">DBRef("&lt;name&gt;", "&lt;id&gt;")</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <p class="leafygreen-ui-1kp3ins"> Where the values are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;name&gt; </code> is a string of valid JSON characters. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> &lt;id&gt; </code> is any valid extended JSON type. </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Undefined Type <a class="headerlink leafygreen-ui-1kepx47" href="#undefined-type" 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="undefined-type"> </div> </a> </h3> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> data_undefined </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-data_undefined" title="Permalink to this definition"> <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="mongodb-bsontype-data_undefined"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Strict Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> Shell Mode </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$undefined\": true }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$undefined": true }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"undefined"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">undefined</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> The representation for the JavaScript/BSON undefined type. </p> <p class="leafygreen-ui-1kp3ins"> You <em> cannot </em> use <code class="leafygreen-ui-1l06pbn"> undefined </code> in query documents. Consider the following document inserted into the <code class="leafygreen-ui-1l06pbn"> people </code> collection using the legacy <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> shell: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.insertOne( { name : \"Sally\", age : undefined } )","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.people.insertOne( { name : <span class="lg-highlight-string">"Sally"</span>, age : undefined } )</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"> The following queries return an error: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.find( { age : undefined } )\ndb.people.find( { age : { $gte : undefined } } )","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.people.find( { age : undefined } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.people.find( { age : { <span class="lg-highlight-variable">$gte</span> : undefined } } )</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"> However, you can query for undefined values using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/type/#mongodb-query-op.-type"> <code class="leafygreen-ui-1l06pbn"> $type </code> </a> , as in: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.find( { age : { $type : 6 } } )","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.people.find( { age : { <span class="lg-highlight-variable">$type</span> : 6 } } )</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"> This query returns all documents for which the <code class="leafygreen-ui-1l06pbn"> age </code> field has value <code class="leafygreen-ui-1l06pbn"> undefined </code> . </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The undefined BSON type is <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://bsonspec.org/spec.html" rel="noopener noreferrer"> <span> deprecated </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> . <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> stores a null value instead. </p> <p class="leafygreen-ui-1kp3ins"> For example, use the same code to insert a document in <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> and in the legacy <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> shell: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.insertOne( { name : \"Sally\", age : undefined } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">people</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{ <!-- -->name <!-- -->: <span class="lg-highlight-string">"Sally"</span>, <!-- -->age <!-- -->: <span class="lg-highlight-literal">undefined</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> <p class="leafygreen-ui-1kp3ins"> The resulting documents are different: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"name\" : \"Sally\", \"age\" : null }\n{ \"name\" : \"Sally\", \"age\" : undefined }"} </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "name" : "Sally", "age" : null }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ "name" : "Sally", "age" : undefined }</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> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> MinKey <a class="headerlink leafygreen-ui-1kepx47" href="#minkey" 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="minkey"> </div> </a> </h3> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> data_minkey </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-data_minkey" title="Permalink to this definition"> <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="mongodb-bsontype-data_minkey"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Strict Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> Shell Mode </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$minKey\": 1 }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$minKey": 1 }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MinKey"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">MinKey</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> The representation of the MinKey BSON data type that compares lower than all other types. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-type-comparison-order/#std-label-faq-dev-compare-order-for-BSON-types"> Comparison/Sort Order </a> for more information on comparison order for BSON types. </p> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> MaxKey <a class="headerlink leafygreen-ui-1kepx47" href="#maxkey" 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="maxkey"> </div> </a> </h3> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> data_maxkey </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-data_maxkey" title="Permalink to this definition"> <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="mongodb-bsontype-data_maxkey"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Strict Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> Shell Mode </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$maxKey\": 1 }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$maxKey": 1 }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MaxKey"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">MaxKey</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> The representation of the MaxKey BSON data type that compares higher than all other types. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-type-comparison-order/#std-label-faq-dev-compare-order-for-BSON-types"> Comparison/Sort Order </a> for more information on comparison order for BSON types. </p> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> NumberLong <a class="headerlink leafygreen-ui-1kepx47" href="#numberlong" 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="numberlong"> </div> </a> </h3> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> data_numberlong </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-data_numberlong" title="Permalink to this definition"> <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="mongodb-bsontype-data_numberlong"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Strict Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> Shell Mode </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$numberLong\": \"&lt;number&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ "$numberLong": "&lt;number&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"NumberLong( \"&lt;number&gt;\" )"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">NumberLong( "&lt;number&gt;" )</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> NumberLong </code> is a 64 bit signed integer. In the legacy <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> shell, you must use quotation marks to insert a <code class="leafygreen-ui-1l06pbn"> NumberLong </code> or the operation will produce an error. </p> <p class="leafygreen-ui-1kp3ins"> For example, the following commands attempt to insert <code class="leafygreen-ui-1l06pbn"> 9223372036854775807 </code> as a <code class="leafygreen-ui-1l06pbn"> NumberLong </code> with and without quotation marks around the integer value: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.json.insertOne( { longQuoted : NumberLong(\"9223372036854775807\") } )\ndb.json.insertOne( { longUnQuoted : NumberLong(9223372036854775807) } )","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.json.insertOne( { longQuoted : NumberLong(<span class="lg-highlight-string">"9223372036854775807"</span>) } )</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">db.json.insertOne( { longUnQuoted : NumberLong(9223372036854775807) } )</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"> The highlighted line produces an error in the legacy <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> shell. The insert succeeds in <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> </p> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> NumberDecimal <a class="headerlink leafygreen-ui-1kepx47" href="#numberdecimal" 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="numberdecimal"> </div> </a> </h3> <dl class="bsontype"> <dt> <code class="leafygreen-ui-1l06pbn"> data_numberdecimal </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-bsontype-data_numberdecimal" title="Permalink to this definition"> <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="mongodb-bsontype-data_numberdecimal"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Strict Mode </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> Shell Mode </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"$numberDecimal\": \"&lt;number&gt;\" }"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" 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">{ "$numberDecimal": "&lt;number&gt;" }</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"NumberDecimal( \"&lt;number&gt;\" )"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">NumberDecimal( "&lt;number&gt;" )</td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> NumberDecimal </code> is a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst" rel="noopener noreferrer"> <span> high-precision decimal </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> . You must include quotation marks, or the input number will be treated as a double, resulting in data loss. </p> <p class="leafygreen-ui-1kp3ins"> For example, the following commands insert <code class="leafygreen-ui-1l06pbn"> 123.40 </code> as a <code class="leafygreen-ui-1l06pbn"> NumberDecimal </code> with and without quotation marks around the value: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.json.insertOne( { decimalQuoted : NumberDecimal(\"123.40\") } )\ndb.json.insertOne( { decimalUnQuoted : NumberDecimal(123.40) } )","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.json.insertOne( { decimalQuoted : NumberDecimal(<span class="lg-highlight-string">"123.40"</span>) } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.json.insertOne( { decimalUnQuoted : NumberDecimal(123.40) } )</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"> When you retrieve the documents, the value of <code class="leafygreen-ui-1l06pbn"> decimalUnQuoted </code> has changed, while <code class="leafygreen-ui-1l06pbn"> decimalQuoted </code> retains its specified precision: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.json.find()\n{ \"_id\" : ObjectId(\"596f88b7b613bb04f80a1ea9\"), \"decimalQuoted\" : NumberDecimal(\"123.40\") }\n{ \"_id\" : ObjectId(\"596f88c9b613bb04f80a1eaa\"), \"decimalUnQuoted\" : NumberDecimal(\"123.400000000000\") }","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.json.<span class="lg-highlight-title lg-highlight-function">find</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"596f88b7b613bb04f80a1ea9"</span>), <span class="lg-highlight-string">"decimalQuoted"</span> : NumberDecimal(<span class="lg-highlight-string">"123.40"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"596f88c9b613bb04f80a1eaa"</span>), <span class="lg-highlight-string">"decimalUnQuoted"</span> : NumberDecimal(<span class="lg-highlight-string">"123.400000000000"</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 class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This insert behavior is different in <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> </p> <p class="leafygreen-ui-1kp3ins"> The quoted string format, <code class="leafygreen-ui-1l06pbn"> NumberDecimal("123.40") </code> , is deprecated. The insert succeeds, but also produces a warning. </p> <p class="leafygreen-ui-1kp3ins"> The unquoted string format, <code class="leafygreen-ui-1l06pbn"> NumberDecimal(123.40) </code> , stores the value as <code class="leafygreen-ui-1l06pbn"> 123.4 </code> . The trailing <code class="leafygreen-ui-1l06pbn"> 0 </code> is dropped. </p> </div> </div> </dd> </dl> </section> </section> </section>
https://www.mongodb.com/docs/manual/core/sharding-shard-a-collection/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Shard a Collection <a class="headerlink leafygreen-ui-1kepx47" href="#shard-a-collection" 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-a-collection"> </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="#shard-key-fields-and-values" target="_self"> <span> Shard Key Fields and Values </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#missing-shard-key-fields" target="_self"> <span> Missing Shard Key Fields </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#change-a-document-s-shard-key-value" target="_self"> <span> Change a Document's Shard Key Value </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#change-a-collection-s-shard-key" target="_self"> <span> Change a Collection's Shard Key </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> To shard a collection, you must specify the full namespace of the collection that you want to shard and the shard key. You can use 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> method <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection"> <code class="leafygreen-ui-1l06pbn"> sh.shardCollection() </code> </a> to shard a collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.shardCollection(&lt;namespace&gt;, &lt;key&gt;) // Optional parameters omitted","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">shardCollection</span>(&lt;<!-- -->namespace<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->key<!-- -->&gt;<!-- -->) <span class="lg-highlight-comment">// Optional parameters omitted</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 class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> namespace </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Specify the full namespace of the collection that you want to shard ( <code class="leafygreen-ui-1l06pbn"> "&lt;database&gt;.&lt;collection&gt;" </code> ). </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> key </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Specify a document <code class="leafygreen-ui-1l06pbn"> { &lt;shard key field1&gt;: &lt;1|"hashed"&gt;, ... } </code> where </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> 1 </code> indicates <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/ranged-sharding/#std-label-sharding-ranged"> range-based sharding </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> "hashed" </code> indicates <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/#std-label-sharding-hashed"> hashed sharding <!-- --> . </a> </p> </li> </ul> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> For more information on the sharding method, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection"> <code class="leafygreen-ui-1l06pbn"> sh.shardCollection() </code> . </a> </p> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Shard Key Fields and Values <a class="headerlink leafygreen-ui-1kepx47" href="#shard-key-fields-and-values" 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-fields-and-values"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Missing Shard Key Fields <a class="headerlink leafygreen-ui-1kepx47" href="#missing-shard-key-fields" 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="missing-shard-key-fields"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Documents in sharded collections can be missing the shard key fields. A missing shard key falls into the same range as a <code class="leafygreen-ui-1l06pbn"> null </code> -valued shard key. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key-missing"> Missing Shard Key Fields <!-- --> . </a> </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Change a Document's Shard Key Value <a class="headerlink leafygreen-ui-1kepx47" href="#change-a-document-s-shard-key-value" 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-a-document-s-shard-key-value"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> You can update a document's shard key value unless the shard key field is the immutable <code class="leafygreen-ui-1l06pbn"> _id </code> field. </p> <p class="leafygreen-ui-1kp3ins"> For details on updating the shard key value, 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> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Change a Collection's Shard Key <a class="headerlink leafygreen-ui-1kepx47" href="#change-a-collection-s-shard-key" 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-a-collection-s-shard-key"> </div> </a> </h3> <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 document's shard key. </p> <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> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/query/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Query and Projection Operators <a class="headerlink leafygreen-ui-1kepx47" href="#query-and-projection-operators" 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="query-and-projection-operators"> </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="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#query-selectors" target="_self"> <span> Query Selectors </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#projection-operators" target="_self"> <span> Projection Operators </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#miscellaneous-operators" target="_self"> <span> Miscellaneous Operators </span> </a> </li> </ul> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> For details on a specific operator, including syntax and examples, click on the link to the operator's reference page. </p> </div> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> You can use <!-- --> query and projection operators <!-- --> for deployments hosted 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> </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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> <div class="leafygreen-ui-13vw3ie" role="note"> <h2 class="leafygreen-ui-1fn4p2b"> Tip </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> You can use operators when querying your data with <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> methods, the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/" target="_self"> <span> Atlas UI </span> </a> , or <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/compass/current/" target="_self"> <span> Compass <!-- --> . </span> </a> </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-query-selectors"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Query Selectors <a class="headerlink leafygreen-ui-1kepx47" href="#query-selectors" 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="query-selectors"> </div> </a> </h2> <span class="leafygreen-ui-1qnjd6d" id="std-label-query-comparison"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Comparison <a class="headerlink leafygreen-ui-1kepx47" href="#comparison" 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="comparison"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> For comparison of different BSON type values, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-type-comparison-order/#std-label-bson-types-comparison-order"> specified BSON comparison order <!-- --> . </a> </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/eq/#mongodb-query-op.-eq"> <code class="leafygreen-ui-1l06pbn"> $eq </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches values that are equal to a specified value. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/gt/#mongodb-query-op.-gt"> <code class="leafygreen-ui-1l06pbn"> $gt </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches values that are greater than a specified value. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/gte/#mongodb-query-op.-gte"> <code class="leafygreen-ui-1l06pbn"> $gte </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches values that are greater than or equal to a specified value. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/in/#mongodb-query-op.-in"> <code class="leafygreen-ui-1l06pbn"> $in </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches any of the values specified in an array. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/lt/#mongodb-query-op.-lt"> <code class="leafygreen-ui-1l06pbn"> $lt </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches values that are less than a specified value. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/lte/#mongodb-query-op.-lte"> <code class="leafygreen-ui-1l06pbn"> $lte </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches values that are less than or equal to a specified value. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/ne/#mongodb-query-op.-ne"> <code class="leafygreen-ui-1l06pbn"> $ne </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches all values that are not equal to a specified value. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nin/#mongodb-query-op.-nin"> <code class="leafygreen-ui-1l06pbn"> $nin </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches none of the values specified in an array. </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Logical <a class="headerlink leafygreen-ui-1kepx47" href="#logical" 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="logical"> </div> </a> </h3> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/and/#mongodb-query-op.-and"> <code class="leafygreen-ui-1l06pbn"> $and </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Joins query clauses with a logical <code class="leafygreen-ui-1l06pbn"> AND </code> returns all documents that match the conditions of both clauses. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/not/#mongodb-query-op.-not"> <code class="leafygreen-ui-1l06pbn"> $not </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Inverts the effect of a query predicate and returns documents that do <em> not </em> match the query predicate. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nor/#mongodb-query-op.-nor"> <code class="leafygreen-ui-1l06pbn"> $nor </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Joins query clauses with a logical <code class="leafygreen-ui-1l06pbn"> NOR </code> returns all documents that fail to match both clauses. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/or/#mongodb-query-op.-or"> <code class="leafygreen-ui-1l06pbn"> $or </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Joins query clauses with a logical <code class="leafygreen-ui-1l06pbn"> OR </code> returns all documents that match the conditions of either clause. </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Element <a class="headerlink leafygreen-ui-1kepx47" href="#element" 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="element"> </div> </a> </h3> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/exists/#mongodb-query-op.-exists"> <code class="leafygreen-ui-1l06pbn"> $exists </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches documents that have the specified field. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/type/#mongodb-query-op.-type"> <code class="leafygreen-ui-1l06pbn"> $type </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Selects documents if a field is of the specified type. </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Evaluation <a class="headerlink leafygreen-ui-1kepx47" href="#evaluation" 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="evaluation"> </div> </a> </h3> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr"> <code class="leafygreen-ui-1l06pbn"> $expr </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Allows use of aggregation expressions within the query language. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/jsonSchema/#mongodb-query-op.-jsonSchema"> <code class="leafygreen-ui-1l06pbn"> $jsonSchema </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Validate documents against the given JSON Schema. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/mod/#mongodb-query-op.-mod"> <code class="leafygreen-ui-1l06pbn"> $mod </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Performs a modulo operation on the value of a field and selects documents with a specified result. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/regex/#mongodb-query-op.-regex"> <code class="leafygreen-ui-1l06pbn"> $regex </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Selects documents where values match a specified regular expression. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/text/#mongodb-query-op.-text"> <code class="leafygreen-ui-1l06pbn"> $text </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Performs text search. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $text </code> provides text query capabilities for self-managed (non-Atlas) deployments. For data hosted on MongoDB Atlas, MongoDB offers an improved full-text query solution, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self"> <span> Atlas Search <!-- --> . </span> </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/where/#mongodb-query-op.-where"> <code class="leafygreen-ui-1l06pbn"> $where </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches documents that satisfy a JavaScript expression. </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Geospatial <a class="headerlink leafygreen-ui-1kepx47" href="#geospatial" 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="geospatial"> </div> </a> </h3> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoIntersects/#mongodb-query-op.-geoIntersects"> <code class="leafygreen-ui-1l06pbn"> $geoIntersects </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Selects geometries that intersect with a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-GeoJSON"> GeoJSON </a> geometry. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index"> 2dsphere </a> index supports <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoIntersects/#mongodb-query-op.-geoIntersects"> <code class="leafygreen-ui-1l06pbn"> $geoIntersects </code> . </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin"> <code class="leafygreen-ui-1l06pbn"> $geoWithin </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Selects geometries within a bounding <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/geojson/#std-label-geospatial-indexes-store-geojson"> GeoJSON geometry </a> . The <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index"> 2dsphere </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index"> 2d </a> indexes support <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin"> <code class="leafygreen-ui-1l06pbn"> $geoWithin </code> . </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/near/#mongodb-query-op.-near"> <code class="leafygreen-ui-1l06pbn"> $near </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns geospatial objects in proximity to a point. Requires a geospatial index. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index"> 2dsphere </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index"> 2d </a> indexes support <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/near/#mongodb-query-op.-near"> <code class="leafygreen-ui-1l06pbn"> $near </code> . </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nearSphere/#mongodb-query-op.-nearSphere"> <code class="leafygreen-ui-1l06pbn"> $nearSphere </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index"> 2dsphere </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index"> 2d </a> indexes support <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nearSphere/#mongodb-query-op.-nearSphere"> <code class="leafygreen-ui-1l06pbn"> $nearSphere </code> . </a> </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-operator-query-array"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Array <a class="headerlink leafygreen-ui-1kepx47" href="#array" 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="array"> </div> </a> </h3> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/all/#mongodb-query-op.-all"> <code class="leafygreen-ui-1l06pbn"> $all </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches arrays that contain all elements specified in the query. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/elemMatch/#mongodb-query-op.-elemMatch"> <code class="leafygreen-ui-1l06pbn"> $elemMatch </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Selects documents if element in the array field matches all the specified <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/elemMatch/#mongodb-query-op.-elemMatch"> <code class="leafygreen-ui-1l06pbn"> $elemMatch </code> </a> conditions. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/size/#mongodb-query-op.-size"> <code class="leafygreen-ui-1l06pbn"> $size </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Selects documents if the array field is a specified size. </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Bitwise <a class="headerlink leafygreen-ui-1kepx47" href="#bitwise" 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="bitwise"> </div> </a> </h3> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/bitsAllClear/#mongodb-query-op.-bitsAllClear"> <code class="leafygreen-ui-1l06pbn"> $bitsAllClear </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches numeric or binary values in which a set of bit positions <em> all </em> have a value of <code class="leafygreen-ui-1l06pbn"> 0 </code> . </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/bitsAllSet/#mongodb-query-op.-bitsAllSet"> <code class="leafygreen-ui-1l06pbn"> $bitsAllSet </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches numeric or binary values in which a set of bit positions <em> all </em> have a value of <code class="leafygreen-ui-1l06pbn"> 1 </code> . </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/bitsAnyClear/#mongodb-query-op.-bitsAnyClear"> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches numeric or binary values in which <em> any </em> bit from a set of bit positions has a value of <code class="leafygreen-ui-1l06pbn"> 0 </code> . </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/bitsAnySet/#mongodb-query-op.-bitsAnySet"> <code class="leafygreen-ui-1l06pbn"> $bitsAnySet </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Matches numeric or binary values in which <em> any </em> bit from a set of bit positions has a value of <code class="leafygreen-ui-1l06pbn"> 1 </code> . </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-query-projection-operators"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Projection Operators <a class="headerlink leafygreen-ui-1kepx47" href="#projection-operators" 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="projection-operators"> </div> </a> </h2> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/positional/#mongodb-projection-proj.-"> <code class="leafygreen-ui-1l06pbn"> $ </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Projects the first element in an array that matches the query condition. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/elemMatch/#mongodb-projection-proj.-elemMatch"> <code class="leafygreen-ui-1l06pbn"> $elemMatch </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Projects the first element in an array that matches the specified <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/elemMatch/#mongodb-projection-proj.-elemMatch"> <code class="leafygreen-ui-1l06pbn"> $elemMatch </code> </a> condition. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/meta/#mongodb-expression-exp.-meta"> <code class="leafygreen-ui-1l06pbn"> $meta </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Projects the document's score assigned during the <code class="leafygreen-ui-1l06pbn"> $text </code> operation. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $text </code> provides text query capabilities for self-managed (non-Atlas) deployments. For data hosted on MongoDB Atlas, MongoDB offers an improved full-text query solution, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self"> <span> Atlas Search <!-- --> . </span> </a> </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/slice/#mongodb-projection-proj.-slice"> <code class="leafygreen-ui-1l06pbn"> $slice </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Limits the number of elements projected from an array. Supports skip and limit slices. </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-query-miscelaneous-operators"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Miscellaneous Operators <a class="headerlink leafygreen-ui-1kepx47" href="#miscellaneous-operators" 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="miscellaneous-operators"> </div> </a> </h2> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:25%"/> <col style="width:75%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/rand/#mongodb-query-op.-rand"> <code class="leafygreen-ui-1l06pbn"> $rand </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Generates a random float between 0 and 1. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/meta/natural/#mongodb-operator-metaOp.-natural"> <code class="leafygreen-ui-1l06pbn"> $natural </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> A special hint that can be provided via the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#mongodb-method-cursor.sort"> <code class="leafygreen-ui-1l06pbn"> sort() </code> </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.hint/#mongodb-method-cursor.hint"> <code class="leafygreen-ui-1l06pbn"> hint() </code> </a> methods that can be used to force either a forward or reverse collection scan. </div> </div> </td> </tr> </tbody> </table> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/query/rand/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $rand <a class="headerlink leafygreen-ui-1kepx47" href="#-rand" 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="-rand"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="query"> <dt> <code class="leafygreen-ui-1l06pbn"> $rand </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-query-op.-rand" title="Permalink to this definition"> <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="mongodb-query-op.-rand"> </div> </a> </dt> <dd> </dd> </dl> <p class="leafygreen-ui-1kp3ins"> Returns a pseudo-random floating point number in the interval [0, 1). 0 included, 1 is excluded. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $rand </code> has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $rand: {} }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$rand</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Generate Random Data Points <a class="headerlink leafygreen-ui-1kepx47" href="#generate-random-data-points" 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="generate-random-data-points"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The examples in this section illustrate charitable donations. The following collection contains a list of donors: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.donors.insertMany(\n [\n { donorId: 1000, amount: 0, frequency: 1 },\n { donorId: 1001, amount: 0, frequency: 2 },\n { donorId: 1002, amount: 0, frequency: 1 },\n { donorId: 1003, amount: 0, frequency: 2 },\n { donorId: 1004, amount: 0, frequency: 1 }\n ]\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">db.<span class="lg-highlight-property">donors</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">donorId</span>: <span class="lg-highlight-number">1000</span>, <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">frequency</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">donorId</span>: <span class="lg-highlight-number">1001</span>, <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">frequency</span>: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">donorId</span>: <span class="lg-highlight-number">1002</span>, <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">frequency</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">donorId</span>: <span class="lg-highlight-number">1003</span>, <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">frequency</span>: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">donorId</span>: <span class="lg-highlight-number">1004</span>, <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">frequency</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">)</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"> The following example updates each document in the <code class="leafygreen-ui-1l06pbn"> donors </code> collection with a random donation amount: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.donors.updateMany(\n {},\n [\n { $set:\n { amount:\n { $floor:\n { $multiply: [ { $rand: {} }, 100 ] }\n }\n }\n }\n ]\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">db.<span class="lg-highlight-property">donors</span>.<span class="lg-highlight-title lg-highlight-function">updateMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">amount</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$floor</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$multiply</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$rand</span>: <!-- -->{<!-- -->} }<!-- -->, <span class="lg-highlight-number">100</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <p class="leafygreen-ui-1kp3ins"> The empty update filter matches every document in the collection. </p> <p class="leafygreen-ui-1kp3ins"> For each document we generate a value between 0 and 1 using <code class="leafygreen-ui-1l06pbn"> $rand </code> then scale the value with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/multiply/#mongodb-expression-exp.-multiply"> <code class="leafygreen-ui-1l06pbn"> $multiply </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/floor/#mongodb-expression-exp.-floor"> <code class="leafygreen-ui-1l06pbn"> $floor </code> </a> operator removes the decimal portion so the updated <code class="leafygreen-ui-1l06pbn"> amount </code> is an integer value. </p> <p class="leafygreen-ui-1kp3ins"> After updating the collection, the documents look like this: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"donorId\" : 1000, \"amount\" : 2, \"frequency\" : 1 }\n{ \"donorId\" : 1001, \"amount\" : 58, \"frequency\" : 2 }\n{ \"donorId\" : 1002, \"amount\" : 27, \"frequency\" : 1 }\n{ \"donorId\" : 1003, \"amount\" : 26, \"frequency\" : 2 }\n{ \"donorId\" : 1004, \"amount\" : 42, \"frequency\" : 1 }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{ <span class="lg-highlight-string">"donorId"</span> <!-- -->: <span class="lg-highlight-number">1000</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"frequency"</span> <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"donorId"</span> <!-- -->: <span class="lg-highlight-number">1001</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">58</span>, <span class="lg-highlight-string">"frequency"</span> <!-- -->: <span class="lg-highlight-number">2</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"donorId"</span> <!-- -->: <span class="lg-highlight-number">1002</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">27</span>, <span class="lg-highlight-string">"frequency"</span> <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"donorId"</span> <!-- -->: <span class="lg-highlight-number">1003</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">26</span>, <span class="lg-highlight-string">"frequency"</span> <!-- -->: <span class="lg-highlight-number">2</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"donorId"</span> <!-- -->: <span class="lg-highlight-number">1004</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">42</span>, <span class="lg-highlight-string">"frequency"</span> <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Select Random Items From a Collection <a class="headerlink leafygreen-ui-1kepx47" href="#select-random-items-from-a-collection" 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="select-random-items-from-a-collection"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $rand </code> operator can be used to select random documents from a collection. Given a collection of voter records: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.voters.insertMany(\n [\n { name: \"Archibald\", voterId: 4321, district: 3, registered: true },\n { name: \"Beckham\", voterId: 4331, district: 3, registered: true },\n { name: \"Carolin\", voterId: 5321, district: 4, registered: true },\n { name: \"Debarge\", voterId: 4343, district: 3, registered: false },\n { name: \"Eckhard\", voterId: 4161, district: 3, registered: false },\n { name: \"Faberge\", voterId: 4300, district: 1, registered: true },\n { name: \"Grimwald\", voterId: 4111, district: 3, registered: true },\n { name: \"Humphrey\", voterId: 2021, district: 3, registered: true },\n { name: \"Idelfon\", voterId: 1021, district: 4, registered: true },\n { name: \"Justo\", voterId: 9891, district: 3, registered: false }\n ]\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">voters</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Archibald"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4321</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Beckham"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4331</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Carolin"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">5321</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Debarge"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4343</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">false</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Eckhard"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4161</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">false</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Faberge"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4300</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Grimwald"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4111</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Humphrey"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">2021</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Idelfon"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">1021</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Justo"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">9891</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <p class="leafygreen-ui-1kp3ins"> The following query retrieves a random selection of approximately half of the voters in district 3: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.voters.find(\n { district: 3,\n $expr: { $lt: [0.5, {$rand: {} } ] }\n },\n { _id: 0, name: 1, registered: 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">db.<span class="lg-highlight-property">voters</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$expr</span>: <!-- -->{ <span class="lg-highlight-attr">$lt</span>: <!-- -->[<span class="lg-highlight-number">0.5</span>, <!-- -->{<span class="lg-highlight-attr">$rand</span>: <!-- -->{<!-- -->} } ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">registered</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> <p class="leafygreen-ui-1kp3ins"> The intial match on the <code class="leafygreen-ui-1l06pbn"> district </code> field selects documents where the voter is from district 3. </p> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr"> <code class="leafygreen-ui-1l06pbn"> $expr </code> </a> operator uses <code class="leafygreen-ui-1l06pbn"> $rand </code> to further refine the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/find/#mongodb-dbcommand-dbcmd.find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> operation. For each document, <code class="leafygreen-ui-1l06pbn"> $rand </code> generates a value between 0 and 1. The threshold of <code class="leafygreen-ui-1l06pbn"> 0.5 </code> means the less than <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lt/#mongodb-expression-exp.-lt"> <code class="leafygreen-ui-1l06pbn"> ($lt) </code> </a> comparison will be true for about half the documents in the set. </p> <p class="leafygreen-ui-1kp3ins"> There are 7 voters in District 3, running the code selects about half of them. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"name\" : \"Beckham\", \"registered\" : true }\n{ \"name\" : \"Eckhard\", \"registered\" : false }\n{ \"name\" : \"Grimwald\", \"registered\" : true }\n{ \"name\" : \"Humphrey\", \"registered\" : true }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Beckham"</span>, <span class="lg-highlight-string">"registered"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Eckhard"</span>, <span class="lg-highlight-string">"registered"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Grimwald"</span>, <span class="lg-highlight-string">"registered"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Humphrey"</span>, <span class="lg-highlight-string">"registered"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> </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> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/rand/#mongodb-expression-exp.-rand"> <code class="leafygreen-ui-1l06pbn"> $rand (aggregation) </code> </a> </p> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $bitsAnyClear <a class="headerlink leafygreen-ui-1kepx47" href="#-bitsanyclear" 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="-bitsanyclear"> </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="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <dl class="query"> <dt> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-query-op.-bitsAnyClear" title="Permalink to this definition"> <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="mongodb-query-op.-bitsAnyClear"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnyClear" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </span> </a> matches documents where <em> any </em> of the bit positions given by the query are clear (i.e. <code class="leafygreen-ui-1l06pbn"> 0 </code> ) in <code class="leafygreen-ui-1l06pbn"> field </code> . </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { &lt;field&gt;: { $bitsAnyClear: &lt;numeric bitmask&gt; } } </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { &lt;field&gt;: { $bitsAnyClear: &lt; </code> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Binary"> <code class="leafygreen-ui-1l06pbn"> BinData </code> </a> <code class="leafygreen-ui-1l06pbn"> bitmask&gt; } } </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { &lt;field&gt;: { $bitsAnyClear: [ &lt;position1&gt;, &lt;position2&gt;, ... ] } } </code> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> field </code> value must be either numeric or a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Binary"> <code class="leafygreen-ui-1l06pbn"> BinData </code> </a> instance. Otherwise, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnyClear" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </span> </a> will not match the current document. </p> <dl> <dt> Numeric Bitmask </dt> <dd class="css-1ufxuu7"> You can provide a numeric bitmask to be matched against the operand field. The bitmask must be a non-negative 64-bit signed integer. Otherwise, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnyClear" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </span> </a> returns an error. </dd> <dt> BinData Bitmask </dt> <dd class="css-1ufxuu7"> You can also use an arbitrarily large <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Binary"> <code class="leafygreen-ui-1l06pbn"> BinData </code> </a> instance as a bitmask. </dd> <dt> Position List </dt> <dd class="css-1ufxuu7"> If querying a list of bit positions, each <code class="leafygreen-ui-1l06pbn"> &lt;position&gt; </code> must be a non-negative integer. Bit positions start at <code class="leafygreen-ui-1l06pbn"> 0 </code> from the least significant bit. For example, the decimal number <code class="leafygreen-ui-1l06pbn"> 254 </code> would have the following bit positions: </dd> </dl> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Bit Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 1 </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 1 </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 1 </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 1 </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 1 </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 1 </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 1 </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> 0 </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Position </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 7 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 6 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 5 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 4 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 3 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 1 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 0 </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-endianness"> endianness </a> of your system depends on the architecture of your machine. Numbers in BSON data are always stored as <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-little-endian"> little-endian </a> , if your system is <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-big-endian"> big-endian </a> this means that numeric data is converted between big and little endian. </p> <p class="leafygreen-ui-1kp3ins"> In the context of the bit-test match expression operators: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/bitsAnySet/#mongodb-query-op.-bitsAnySet"> <code class="leafygreen-ui-1l06pbn"> $bitsAnySet </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnyClear" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/bitsAllSet/#mongodb-query-op.-bitsAllSet"> <code class="leafygreen-ui-1l06pbn"> $bitsAllSet </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/bitsAllClear/#mongodb-query-op.-bitsAllClear"> <code class="leafygreen-ui-1l06pbn"> $bitsAllClear </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Binary"> <code class="leafygreen-ui-1l06pbn"> BinData </code> </a> values act as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Mask_(computing)" rel="noopener noreferrer"> <span> bitmasks </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> and are interpreted as though they are arbitrary-length unsigned little-endian numbers. The lowest-addressable byte is always interpreted as the least significant byte. Similarly, the highest-addressable byte in the <code class="leafygreen-ui-1l06pbn"> BinData </code> is always interpreted as the most significant byte. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Indexes <a class="headerlink leafygreen-ui-1kepx47" href="#indexes" 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="indexes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Queries cannot use indexes for the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnyClear" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </span> </a> portion of a query, although the other portions of a query can use indexes, if applicable. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Floating Point Values <a class="headerlink leafygreen-ui-1kepx47" href="#floating-point-values" 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="floating-point-values"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnyClear" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </span> </a> will not match numerical values that cannot be represented as a signed 64-bit integer. This can be the case if a value is either too large or too small to fit in a signed 64-bit integer, or if it has a fractional component. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Sign Extension <a class="headerlink leafygreen-ui-1kepx47" href="#sign-extension" 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="sign-extension"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Numbers are sign extended. For example, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnyClear" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </span> </a> considers bit position <code class="leafygreen-ui-1l06pbn"> 200 </code> to be set for the negative number <code class="leafygreen-ui-1l06pbn"> -5 </code> , but bit position <code class="leafygreen-ui-1l06pbn"> 200 </code> to be clear for the positive number <code class="leafygreen-ui-1l06pbn"> +5 </code> . </p> <p class="leafygreen-ui-1kp3ins"> In contrast, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Binary"> <code class="leafygreen-ui-1l06pbn"> BinData </code> </a> instances are zero-extended. For example, given the following document: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.insertOne({ x: BinData(0, \"ww==\"), binaryValueofA: \"11000011\" })","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>(<!-- -->{ <span class="lg-highlight-attr">x</span>: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"ww=="</span>)<!-- -->, <span class="lg-highlight-attr">binaryValueofA</span>: <span class="lg-highlight-string">"11000011"</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> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnyClear" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </span> </a> will consider all bits outside of <code class="leafygreen-ui-1l06pbn"> x </code> to be clear. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following examples will use a collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.insertMany([\n { _id: 1, a: 54, binaryValueofA: \"00110110\" },\n { _id: 2, a: 20, binaryValueofA: \"00010100\" },\n { _id: 3, a: 20.0, binaryValueofA: \"00010100\" },\n { _id: 4, a: BinData(0, \"Zg==\"), binaryValueofA: \"01100110\" }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">a</span>: <span class="lg-highlight-number">54</span>, <span class="lg-highlight-attr">binaryValueofA</span>: <span class="lg-highlight-string">"00110110"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">a</span>: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-attr">binaryValueofA</span>: <span class="lg-highlight-string">"00010100"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">a</span>: <span class="lg-highlight-number">20.0</span>, <span class="lg-highlight-attr">binaryValueofA</span>: <span class="lg-highlight-string">"00010100"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">a</span>: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"Zg=="</span>)<!-- -->, <span class="lg-highlight-attr">binaryValueofA</span>: <span class="lg-highlight-string">"01100110"</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> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Bit Position Array <a class="headerlink leafygreen-ui-1kepx47" href="#bit-position-array" 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="bit-position-array"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following query uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnyClear" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </span> </a> operator to test whether field <code class="leafygreen-ui-1l06pbn"> a </code> has either bit position <code class="leafygreen-ui-1l06pbn"> 1 </code> or bit position <code class="leafygreen-ui-1l06pbn"> 5 </code> clear, where the least significant bit is position <code class="leafygreen-ui-1l06pbn"> 0 </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find( { a: { $bitsAnyClear: [ 1, 5 ] } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">a</span>: <!-- -->{ <span class="lg-highlight-attr">$bitsAnyClear</span>: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">5</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> <p class="leafygreen-ui-1kp3ins"> The query matches the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 2, \"a\" : 20, \"binaryValueofA\" : \"00010100\" }\n{ \"_id\" : 3, \"a\" : 20.0, \"binaryValueofA\" : \"00010100\" }","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">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"a"</span> <!-- -->: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00010100"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"a"</span> <!-- -->: <span class="lg-highlight-number">20.0</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00010100"</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Integer Bitmask <a class="headerlink leafygreen-ui-1kepx47" href="#integer-bitmask" 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="integer-bitmask"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following query uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnyClear" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </span> </a> operator to test whether field <code class="leafygreen-ui-1l06pbn"> a </code> has any bits clear at positions <code class="leafygreen-ui-1l06pbn"> 0 </code> , <code class="leafygreen-ui-1l06pbn"> 1 </code> , and <code class="leafygreen-ui-1l06pbn"> 5 </code> (the binary representation of the bitmask <code class="leafygreen-ui-1l06pbn"> 35 </code> is <code class="leafygreen-ui-1l06pbn"> 00100011 </code> ). </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find( { a: { $bitsAnyClear: 35 } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">a</span>: <!-- -->{ <span class="lg-highlight-attr">$bitsAnyClear</span>: <span class="lg-highlight-number">35</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> <p class="leafygreen-ui-1kp3ins"> The query matches the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"a\" : 54, \"binaryValueofA\" : \"00110110\" }\n{ \"_id\" : 2, \"a\" : 20, \"binaryValueofA\" : \"00010100\" }\n{ \"_id\" : 3, \"a\" : 20.0, \"binaryValueofA\" : \"00010100\" }\n{ \"_id\" : 4, \"a\" : BinData(0,\"Zg==\"), \"binaryValueofA\" : \"01100110\" }","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"a"</span> <!-- -->: <span class="lg-highlight-number">54</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00110110"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"a"</span> <!-- -->: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00010100"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"a"</span> <!-- -->: <span class="lg-highlight-number">20.0</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00010100"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"a"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>,<span class="lg-highlight-string">"Zg=="</span>)<!-- -->, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"01100110"</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> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> BinData Bitmask <a class="headerlink leafygreen-ui-1kepx47" href="#bindata-bitmask" 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="bindata-bitmask"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The following query uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnyClear" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $bitsAnyClear </code> </span> </a> operator to test whether field <code class="leafygreen-ui-1l06pbn"> a </code> has any bits clear at positions <code class="leafygreen-ui-1l06pbn"> 4 </code> and <code class="leafygreen-ui-1l06pbn"> 5 </code> (the binary representation of <code class="leafygreen-ui-1l06pbn"> BinData(0, "MA==") </code> is <code class="leafygreen-ui-1l06pbn"> 00110000 </code> ). </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find( { a: { $bitsAnyClear: BinData(0, \"MA==\") } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">a</span>: <!-- -->{ <span class="lg-highlight-attr">$bitsAnyClear</span>: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"MA=="</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> <p class="leafygreen-ui-1kp3ins"> The query matches the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 2, \"a\" : 20, \"binaryValueofA\" : \"00010100\" }\n{ \"_id\" : 3, \"a\" : 20.0, \"binaryValueofA\" : \"00010100\" }\n{ \"_id\" : 4, \"a\" : BinData(0,\"Zg==\"), \"binaryValueofA\" : \"01100110\" }","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"a"</span> <!-- -->: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00010100"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"a"</span> <!-- -->: <span class="lg-highlight-number">20.0</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00010100"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"a"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>,<span class="lg-highlight-string">"Zg=="</span>)<!-- -->, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"01100110"</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> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/query/mod/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $mod <a class="headerlink leafygreen-ui-1kepx47" href="#-mod" 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="-mod"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="query"> <dt> <code class="leafygreen-ui-1l06pbn"> $mod </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-query-op.-mod" title="Permalink to this definition"> <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="mongodb-query-op.-mod"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Select documents where the value of a field divided by a divisor has the specified remainder. That is, <code class="leafygreen-ui-1l06pbn"> $mod </code> performs a modulo operation to select documents. The first argument is the dividend, and the second argument is the remainder. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To specify a <code class="leafygreen-ui-1l06pbn"> $mod </code> expression, use the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ field: { $mod: [ divisor, remainder ] } }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">field</span>: <!-- -->{ <span class="lg-highlight-attr">$mod</span>: <!-- -->[ <!-- -->divisor<!-- -->, <!-- -->remainder ] } }</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> <span class="leafygreen-ui-1qnjd6d" id="std-label-mod-behavior"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $mod </code> returns an error if the <code class="leafygreen-ui-1l06pbn"> [ divisor, remainder ] </code> array doesn't contain two elements. For examples, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-mod-not-enough-elements" target="_self"> <span> Not Enough Elements Error </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-mod-too-many-elements" target="_self"> <span> Too Many Elements Error </span> </a> respectively. </p> <p class="leafygreen-ui-1kp3ins"> Also, starting in MongoDB 5.1 (and 5.0.4), <code class="leafygreen-ui-1l06pbn"> $mod </code> returns an error if the <code class="leafygreen-ui-1l06pbn"> divisor </code> or <code class="leafygreen-ui-1l06pbn"> remainder </code> values evaluate to: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> NaN </code> (not a number). </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> Infinity </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A value that can't be represented using a 64-bit integer. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> If a document in the collection contains a field where the value is <code class="leafygreen-ui-1l06pbn"> NaN </code> (not a number) or <code class="leafygreen-ui-1l06pbn"> Infinity </code> , <code class="leafygreen-ui-1l06pbn"> $mod </code> doesn't include the document in the output. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Negative Dividend <a class="headerlink leafygreen-ui-1kepx47" href="#negative-dividend" 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="negative-dividend"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> When the dividend is negative, the remainder is also negative. For more details on this behavior, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder#description" rel="noopener noreferrer"> <span> official JavaScript documentation </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> . </p> <p class="leafygreen-ui-1kp3ins"> For an example, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-mod-qo-negative-dividend-example" target="_self"> <span> Negative Dividend <!-- --> . </span> </a> </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Use <code class="leafygreen-ui-1l06pbn"> $mod </code> to Select Documents <a class="headerlink leafygreen-ui-1kepx47" href="#use--mod-to-select-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="use--mod-to-select-documents"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Create an <code class="leafygreen-ui-1l06pbn"> inventory </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.insertMany( [\n { \"_id\" : 1, \"item\" : \"abc123\", \"qty\" : 0 },\n { \"_id\" : 2, \"item\" : \"xyz123\", \"qty\" : 5 },\n { \"_id\" : 3, \"item\" : \"ijk123\", \"qty\" : 12 }\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">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">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc123"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"xyz123"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ijk123"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">12</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> <p class="leafygreen-ui-1kp3ins"> Then, the following query selects those documents in the <code class="leafygreen-ui-1l06pbn"> inventory </code> collection where value of the <code class="leafygreen-ui-1l06pbn"> qty </code> field modulo <code class="leafygreen-ui-1l06pbn"> 4 </code> equals <code class="leafygreen-ui-1l06pbn"> 0 </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.find( { qty: { $mod: [ 4, 0 ] } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">qty</span>: <!-- -->{ <span class="lg-highlight-attr">$mod</span>: <!-- -->[ <span class="lg-highlight-number">4</span>, <span class="lg-highlight-number">0</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> <p class="leafygreen-ui-1kp3ins"> The query returns the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { '_id' : 1, 'item' : 'abc123', 'qty' : 0 },\n { '_id' : 3, 'item' : 'ijk123', 'qty' : 12 }\n]","programmingLanguage":"JSON"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> '_id' <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1</span><span class="lg-highlight-punctuation">,</span> 'item' <span class="lg-highlight-punctuation">:</span> 'abc123'<span class="lg-highlight-punctuation">,</span> 'qty' <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> '_id' <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">3</span><span class="lg-highlight-punctuation">,</span> 'item' <span class="lg-highlight-punctuation">:</span> 'ijk123'<span class="lg-highlight-punctuation">,</span> 'qty' <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">12</span> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">]</span></td></tr></tbody></table></code></pre> </div> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-mod-not-enough-elements"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Not Enough Elements Error <a class="headerlink leafygreen-ui-1kepx47" href="#not-enough-elements-error" 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="not-enough-elements-error"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-mod" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $mod </code> </span> </a> operator errors when passed an array with fewer than two elements. </p> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Array with Single Element <a class="headerlink leafygreen-ui-1kepx47" href="#array-with-single-element" 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="array-with-single-element"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> The following operation incorrectly passes the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-mod" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $mod </code> </span> </a> operator an array that contains a single element: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.find( { qty: { $mod: [ 4 ] } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">qty</span>: <!-- -->{ <span class="lg-highlight-attr">$mod</span>: <!-- -->[ <span class="lg-highlight-number">4</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> <p class="leafygreen-ui-1kp3ins"> The statement results in the following error: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoServerError: malformed mod, not enough elements","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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"><span class="lg-highlight-title lg-highlight-class">MongoServerError</span>: <!-- -->malformed mod<!-- -->, <!-- -->not enough elements</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Empty Array <a class="headerlink leafygreen-ui-1kepx47" href="#empty-array" 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="empty-array"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> The following operation incorrectly passes the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-mod" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $mod </code> </span> </a> operator an empty array: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.find( { qty: { $mod: [ ] } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">qty</span>: <!-- -->{ <span class="lg-highlight-attr">$mod</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> <p class="leafygreen-ui-1kp3ins"> The statement results in the following error: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoServerError: malformed mod, not enough elements","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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"><span class="lg-highlight-title lg-highlight-class">MongoServerError</span>: <!-- -->malformed mod<!-- -->, <!-- -->not enough elements</td></tr></tbody></table></code></pre> </div> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-mod-too-many-elements"> </span> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Too Many Elements Error <a class="headerlink leafygreen-ui-1kepx47" href="#too-many-elements-error" 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="too-many-elements-error"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-mod" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $mod </code> </span> </a> operator errors when passed an array with more than two elements. </p> <p class="leafygreen-ui-1kp3ins"> For example, the following operation attempts to use the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-mod" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $mod </code> </span> </a> operator with an array that contains four elements: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.find( { qty: { $mod: [ 4, 1, 2, 3 ] } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">qty</span>: <!-- -->{ <span class="lg-highlight-attr">$mod</span>: <!-- -->[ <span class="lg-highlight-number">4</span>, <span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>, <span class="lg-highlight-number">3</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> <p class="leafygreen-ui-1kp3ins"> The statement results in the following error: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoServerError: malformed mod, too many elements","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1agdxuk" 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"><span class="lg-highlight-title lg-highlight-class">MongoServerError</span>: <!-- -->malformed mod<!-- -->, <!-- -->too many elements</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Floating Point Arguments <a class="headerlink leafygreen-ui-1kepx47" href="#floating-point-arguments" 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="floating-point-arguments"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $mod </code> expression rounds decimal input towards zero. </p> <p class="leafygreen-ui-1kp3ins"> The following examples demonstrate this behavior: </p> <div class="leafygreen-ui-vg7qwp" role="note"> <h2 class="leafygreen-ui-2xicti"> Example </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Input query: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.find( { qty: { $mod: [ 4.0, 0 ] } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">qty</span>: <!-- -->{ <span class="lg-highlight-attr">$mod</span>: <!-- -->[ <span class="lg-highlight-number">4.0</span>, <span class="lg-highlight-number">0</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> <p class="leafygreen-ui-1kp3ins"> Results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: 1, item: 'abc123', qty: 0 },\n { _id: 3, item: 'ijk123', qty: 12 }\n]","programmingLanguage":"JSON"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> _id<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1</span><span class="lg-highlight-punctuation">,</span> item<span class="lg-highlight-punctuation">:</span> 'abc123'<span class="lg-highlight-punctuation">,</span> qty<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> _id<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">3</span><span class="lg-highlight-punctuation">,</span> item<span class="lg-highlight-punctuation">:</span> 'ijk123'<span class="lg-highlight-punctuation">,</span> qty<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">12</span> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">]</span></td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> <div class="leafygreen-ui-vg7qwp" role="note"> <h2 class="leafygreen-ui-2xicti"> Example </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Input query: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.find( { qty: { $mod: [ 4.5, 0 ] } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">qty</span>: <!-- -->{ <span class="lg-highlight-attr">$mod</span>: <!-- -->[ <span class="lg-highlight-number">4.5</span>, <span class="lg-highlight-number">0</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> <p class="leafygreen-ui-1kp3ins"> Results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: 1, item: 'abc123', qty: 0 },\n { _id: 3, item: 'ijk123', qty: 12 }\n]","programmingLanguage":"JSON"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> _id<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1</span><span class="lg-highlight-punctuation">,</span> item<span class="lg-highlight-punctuation">:</span> 'abc123'<span class="lg-highlight-punctuation">,</span> qty<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> _id<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">3</span><span class="lg-highlight-punctuation">,</span> item<span class="lg-highlight-punctuation">:</span> 'ijk123'<span class="lg-highlight-punctuation">,</span> qty<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">12</span> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">]</span></td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> <div class="leafygreen-ui-vg7qwp" role="note"> <h2 class="leafygreen-ui-2xicti"> Example </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Input query: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.find( { qty: { $mod: [ 4.99, 0 ] } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">qty</span>: <!-- -->{ <span class="lg-highlight-attr">$mod</span>: <!-- -->[ <span class="lg-highlight-number">4.99</span>, <span class="lg-highlight-number">0</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> <p class="leafygreen-ui-1kp3ins"> Results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: 1, item: 'abc123', qty: 0 },\n { _id: 3, item: 'ijk123', qty: 12 }\n]","programmingLanguage":"JSON"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> _id<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1</span><span class="lg-highlight-punctuation">,</span> item<span class="lg-highlight-punctuation">:</span> 'abc123'<span class="lg-highlight-punctuation">,</span> qty<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> _id<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">3</span><span class="lg-highlight-punctuation">,</span> item<span class="lg-highlight-punctuation">:</span> 'ijk123'<span class="lg-highlight-punctuation">,</span> qty<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">12</span> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">]</span></td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Each query applies <code class="leafygreen-ui-1l06pbn"> 4 </code> to the <code class="leafygreen-ui-1l06pbn"> $mod </code> expression regardless of decimal points, resulting in the same result set. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-mod-qo-negative-dividend-example"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Negative Dividend <a class="headerlink leafygreen-ui-1kepx47" href="#negative-dividend-1" 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="negative-dividend-1"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $mod </code> expression produces a negative result when the dividend is negative. </p> <p class="leafygreen-ui-1kp3ins"> The following example demonstrates this behavior: </p> <div class="leafygreen-ui-vg7qwp" role="note"> <h2 class="leafygreen-ui-2xicti"> Example </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Input query: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.find( { qty: { $mod: [ -4, -0 ] } } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">qty</span>: <!-- -->{ <span class="lg-highlight-attr">$mod</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">4</span>, <!-- -->-<span class="lg-highlight-number">0</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> <p class="leafygreen-ui-1kp3ins"> This query returns two documents because the <code class="leafygreen-ui-1l06pbn"> qty </code> has a remainder of <code class="leafygreen-ui-1l06pbn"> -0 </code> when the dividend is negative and <code class="leafygreen-ui-1l06pbn"> -0 </code> equals <code class="leafygreen-ui-1l06pbn"> 0 </code> in JavaScript. For details on this equality, see the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type" rel="noopener noreferrer"> <span> official JavaScript documentation </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> . </p> <p class="leafygreen-ui-1kp3ins"> Results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: 1, item: 'abc123', qty: 0 },\n { _id: 3, item: 'ijk123', qty: 12 }\n]","programmingLanguage":"JSON"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> _id<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1</span><span class="lg-highlight-punctuation">,</span> item<span class="lg-highlight-punctuation">:</span> 'abc123'<span class="lg-highlight-punctuation">,</span> qty<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> _id<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">3</span><span class="lg-highlight-punctuation">,</span> item<span class="lg-highlight-punctuation">:</span> 'ijk123'<span class="lg-highlight-punctuation">,</span> qty<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">12</span> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">]</span></td></tr></tbody></table></code></pre> </div> </div> </div> </div> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/query-miscellaneous/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Miscellaneous Query Operators <a class="headerlink leafygreen-ui-1kepx47" href="#miscellaneous-query-operators" 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="miscellaneous-query-operators"> </div> </a> </h1> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> For details on a specific operator, including syntax and examples, click on the link to the operator's reference page. </p> </div> </div> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:25%"/> <col style="width:75%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/rand/#mongodb-query-op.-rand"> <code class="leafygreen-ui-1l06pbn"> $rand </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Generates a random float between 0 and 1. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/meta/natural/#mongodb-operator-metaOp.-natural"> <code class="leafygreen-ui-1l06pbn"> $natural </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> A special hint that can be provided via the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#mongodb-method-cursor.sort"> <code class="leafygreen-ui-1l06pbn"> sort() </code> </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.hint/#mongodb-method-cursor.hint"> <code class="leafygreen-ui-1l06pbn"> hint() </code> </a> methods that can be used to force either a forward or reverse collection scan. </div> </div> </td> </tr> </tbody> </table> </div> </section>
https://www.mongodb.com/docs/manual/reference/method/js-constructor/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Object Constructors and Methods <a class="headerlink leafygreen-ui-1kepx47" href="#object-constructors-and-methods" 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="object-constructors-and-methods"> </div> </a> </h1> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> For details on a specific method, including syntax and examples, click on the link to the method's reference page. </p> </div> </div> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Binary.createFromBase64/#mongodb-method-Binary.createFromBase64"> <code class="leafygreen-ui-1l06pbn"> Binary.createFromBase64() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Creates a binary object from a base64 value. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Binary.createFromHexString/#mongodb-method-Binary.createFromHexString"> <code class="leafygreen-ui-1l06pbn"> Binary.createFromHexString() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Creates a binary object from a hexadecimal value. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/BinData/#mongodb-method-BinData"> <code class="leafygreen-ui-1l06pbn"> BinData() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-binary-data"> binary data object <!-- --> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/BSONRegExp/#mongodb-method-BSONRegExp"> <code class="leafygreen-ui-1l06pbn"> BSONRegExp() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Creates a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/BSONRegExp/#mongodb-method-BSONRegExp"> <code class="leafygreen-ui-1l06pbn"> BSONRegExp() </code> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/BulkWriteResult/#mongodb-method-BulkWriteResult"> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Wrapper around the result set from <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.execute/#mongodb-method-Bulk.execute"> <code class="leafygreen-ui-1l06pbn"> Bulk.execute() </code> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Date/#mongodb-method-Date"> <code class="leafygreen-ui-1l06pbn"> Date() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Creates a date object. By default creates a date object including the current date. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/HexData/#mongodb-method-HexData"> <code class="leafygreen-ui-1l06pbn"> HexData() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-binary-data"> binary data object <!-- --> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId/#mongodb-method-ObjectId"> <code class="leafygreen-ui-1l06pbn"> ObjectId() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-ObjectId"> ObjectId <!-- --> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId.createFromBase64/#mongodb-method-ObjectId.createFromBase64"> <code class="leafygreen-ui-1l06pbn"> ObjectId.createFromBase64() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Creates an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-ObjectId"> ObjectId </a> from a base64 value. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId.createFromHexString/#mongodb-method-ObjectId.createFromHexString"> <code class="leafygreen-ui-1l06pbn"> ObjectId.createFromHexString() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Creates an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-ObjectId"> ObjectId </a> from a hexadecimal value. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId.getTimestamp/#mongodb-method-ObjectId.getTimestamp"> <code class="leafygreen-ui-1l06pbn"> ObjectId.getTimestamp() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns the timestamp portion of an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-ObjectId"> ObjectId <!-- --> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId.toString/#mongodb-method-ObjectId.toString"> <code class="leafygreen-ui-1l06pbn"> ObjectId.toString() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns the string representation of an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-ObjectId"> ObjectId <!-- --> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/UUID/"> UUID() </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Converts a 32-byte hexadecimal string to the UUID BSON subtype. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/WriteResult/#mongodb-method-WriteResult"> <code class="leafygreen-ui-1l06pbn"> WriteResult() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Wrapper around the result set from write methods. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/WriteResult.hasWriteError/#mongodb-method-WriteResult.hasWriteError"> <code class="leafygreen-ui-1l06pbn"> WriteResult.hasWriteError() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns a boolean specifying whether the results include <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/WriteResult/#mongodb-data-WriteResult.writeError"> <code class="leafygreen-ui-1l06pbn"> WriteResult.writeError </code> . </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/WriteResult.hasWriteConcernError/#mongodb-method-WriteResult.hasWriteConcernError"> <code class="leafygreen-ui-1l06pbn"> WriteResult.hasWriteConcernError() </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns a boolean specifying whether whether the results include <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/WriteResult/#mongodb-data-WriteResult.writeConcernError"> <code class="leafygreen-ui-1l06pbn"> WriteResult.writeConcernError </code> . </a> </div> </div> </td> </tr> </tbody> </table> </div> </section>
https://www.mongodb.com/docs/manual/reference/method/BulkWriteResult/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> BulkWriteResult() <a class="headerlink leafygreen-ui-1kepx47" href="#bulkwriteresult--" 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="bulkwriteresult--"> </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="#properties" target="_self"> <span> Properties </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#writeerrors-exception" target="_self"> <span> writeErrors Exception </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#writeconcernerror-exception" target="_self"> <span> writeConcernError Exception </span> </a> </li> </ul> </div> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult() </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-BulkWriteResult" title="Permalink to this definition"> <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="mongodb-method-BulkWriteResult"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A wrapper that contains the results of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.execute/#mongodb-method-Bulk.execute"> <code class="leafygreen-ui-1l06pbn"> Bulk.execute() </code> </a> method. </p> </dd> </dl> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Properties <a class="headerlink leafygreen-ui-1kepx47" href="#properties" 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="properties"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult </code> has the following properties: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult.acknowledged </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-BulkWriteResult.acknowledged" title="Permalink to this definition"> <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="mongodb-data-BulkWriteResult.acknowledged"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Boolean indicating whether or not the bulk write was acknowledged. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult.deletedCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-BulkWriteResult.deletedCount" title="Permalink to this definition"> <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="mongodb-data-BulkWriteResult.deletedCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Count of deleted documents. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult.insertedCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-BulkWriteResult.insertedCount" title="Permalink to this definition"> <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="mongodb-data-BulkWriteResult.insertedCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Count of inserted documents. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult.insertedIds </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-BulkWriteResult.insertedIds" title="Permalink to this definition"> <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="mongodb-data-BulkWriteResult.insertedIds"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:10%"/> <col style="width:45%"/> <col style="width:45%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <code class="leafygreen-ui-1l06pbn"> mongosh </code> Version </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Example </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> v1.x </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Array of inserted documents by <code class="leafygreen-ui-1l06pbn"> ObjectId </code> . </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> [ ObjectId(...), ObjectId(...), ObjectId(...) ] </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> v2.x </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Map from each inserted document index to its <code class="leafygreen-ui-1l06pbn"> ObjectId </code> . </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { 0: ObjectId(...), 1: ObjectId(...), 2: ObjectId(...) }` </code> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult.matchedCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-BulkWriteResult.matchedCount" title="Permalink to this definition"> <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="mongodb-data-BulkWriteResult.matchedCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Count of matched documents. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult.modifiedCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-BulkWriteResult.modifiedCount" title="Permalink to this definition"> <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="mongodb-data-BulkWriteResult.modifiedCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Count of modified documents. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult.upsertedCount </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-BulkWriteResult.upsertedCount" title="Permalink to this definition"> <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="mongodb-data-BulkWriteResult.upsertedCount"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Count of upserted documents. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult.upsertedIds </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-BulkWriteResult.upsertedIds" title="Permalink to this definition"> <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="mongodb-data-BulkWriteResult.upsertedIds"> </div> </a> </dt> <dd> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:10%"/> <col style="width:45%"/> <col style="width:45%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <code class="leafygreen-ui-1l06pbn"> mongosh </code> Version </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Example </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> v1.x </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Array of upserted documents by <code class="leafygreen-ui-1l06pbn"> ObjectId </code> . </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> [ ObjectId(...), ObjectId(...), ObjectId(...) ] </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> v2.x </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Map from each upserted document index to its <code class="leafygreen-ui-1l06pbn"> ObjectId </code> . </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { 0: ObjectId(...), 1: ObjectId(...), 2: ObjectId(...) }` </code> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> writeErrors Exception <a class="headerlink leafygreen-ui-1kepx47" href="#writeerrors-exception" 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="writeerrors-exception"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> If there is a write error while processing the bulk write, <code class="leafygreen-ui-1l06pbn"> mongosh </code> raises an exception that contains a <code class="leafygreen-ui-1l06pbn"> writeErrors </code> property with the following fields: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> writeErrors </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-writeErrors" title="Permalink to this definition"> <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="mongodb-data-writeErrors"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> An array of documents that contains information regarding any error, unrelated to write concerns, encountered during the update operation. <code class="leafygreen-ui-1l06pbn"> writeErrors </code> contains an error document for each write operation that errors. </p> <p class="leafygreen-ui-1kp3ins"> Each error document contains the following fields: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> writeErrors.index </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-writeErrors.index" title="Permalink to this definition"> <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="mongodb-data-writeErrors.index"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Integer that identifies the write operation in the bulk operations list, which uses a zero-based index. See also <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.getOperations/#mongodb-method-Bulk.getOperations"> <code class="leafygreen-ui-1l06pbn"> Bulk.getOperations() </code> . </a> </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> writeErrors.code </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-writeErrors.code" title="Permalink to this definition"> <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="mongodb-data-writeErrors.code"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Integer value identifying the error. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> writeErrors.errmsg </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-writeErrors.errmsg" title="Permalink to this definition"> <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="mongodb-data-writeErrors.errmsg"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Description of the error. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> writeErrors.op </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-writeErrors.op" title="Permalink to this definition"> <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="mongodb-data-writeErrors.op"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A document identifying the operation that failed. For instance, an update or replace operation error will return a document specifying the query, the update, the <code class="leafygreen-ui-1l06pbn"> multi </code> , and the <code class="leafygreen-ui-1l06pbn"> upsert </code> options. An insert opertation returns the document the operation tried to insert. </p> </dd> </dl> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> writeConcernError Exception <a class="headerlink leafygreen-ui-1kepx47" href="#writeconcernerror-exception" 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="writeconcernerror-exception"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> If there is a write concern error while processing the bulk write, <code class="leafygreen-ui-1l06pbn"> mongosh </code> raises an exception that contains a <code class="leafygreen-ui-1l06pbn"> writeConcernError </code> property with the following fields: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> writeConcernError </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-writeConcernError" title="Permalink to this definition"> <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="mongodb-data-writeConcernError"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Document describing errors that relate to the write concern. </p> <div> <p> <em> Changed <!-- --> in version <!-- --> 7.1 </em> : <!-- --> When <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/BulkWriteResult/#mongodb-method-BulkWriteResult"> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult() </code> </a> is received from <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-program-mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> , write concern errors are always reported, even when one or more write errors occur. </p> <p class="leafygreen-ui-1kp3ins"> In previous releases, the occurrence of write errors could cause the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-BulkWriteResult" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> BulkWriteResult() </code> </span> </a> to not report write concern errors. </p> </div> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> writeConcernError </code> documents contains the following fields: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> writeConcernError.code </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-writeConcernError.code" title="Permalink to this definition"> <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="mongodb-data-writeConcernError.code"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Integer value identifying the cause of the write concern error. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> writeConcernError.errmsg </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-writeConcernError.errmsg" title="Permalink to this definition"> <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="mongodb-data-writeConcernError.errmsg"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Description of the cause of the write concern error. </p> </dd> </dl> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> writeConcernError.errInfo.writeConcern </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-writeConcernError.errInfo.writeConcern" title="Permalink to this definition"> <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="mongodb-data-writeConcernError.errInfo.writeConcern"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> The write concern object used for the corresponding operation. For information on write concern object fields, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-specs"> Write Concern Specification <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> The write concern object may also contain the following field, indicating the source of the write concern: </p> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> writeConcernError.errInfo.writeConcern.provenance </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-writeConcernError.errInfo.writeConcern.provenance" title="Permalink to this definition"> <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="mongodb-data-writeConcernError.errInfo.writeConcern.provenance"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> A string value indicating where the write concern originated (known as write concern <code class="leafygreen-ui-1l06pbn"> provenance </code> ). The following table shows the possible values for this field and their significance: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:40%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Provenance </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> clientSupplied </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern was specified in the application. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> customDefault </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern originated from a custom defined default value. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#mongodb-dbcommand-dbcmd.setDefaultRWConcern"> <code class="leafygreen-ui-1l06pbn"> setDefaultRWConcern </code> . </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> getLastErrorDefaults </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern originated from the replica set's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.getLastErrorDefaults"> <code class="leafygreen-ui-1l06pbn"> settings.getLastErrorDefaults </code> </a> field. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> implicitDefault </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The write concern originated from the server in absence of all other write concern specifications. </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> </dd> </dl> </dd> </dl> </section> </section>
https://www.mongodb.com/docs/manual/core/hashed-sharding/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" 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> </h1> <p class="leafygreen-ui-1kp3ins"> Hashed sharding uses either a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/#std-label-index-hashed-index"> single field hashed index </a> or a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed"> compound hashed index </a> as the shard key to partition data across your sharded cluster. </p> <dl> <dt> Sharding on a Single Field Hashed Index </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> Hashed sharding provides a more even data distribution across the sharded cluster at the cost of reducing <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-sharding-query-isolation"> Targeted Operations vs. Broadcast Operations </a> . Post-hash, documents with "close" shard key values are unlikely to be on the same chunk or shard - the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> is more likely to perform <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-sharding-mongos-broadcast"> Broadcast Operations </a> to fulfill a given ranged query. <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 queries with equality matches to a single shard. </p> <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"> Hashed indexes compute the hash value of a single field as the index value; this value is used as your shard key. <a class="footnote-reference header-buffer" href="#footnote-hashvalue" id="ref-hashvalue-id1"> [ <!-- --> 1 <!-- --> ] </a> </p> </dd> <dt> Sharding on a Compound Hashed Index </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> MongoDB includes support for creating compound indexes with a single <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/#std-label-index-type-hashed"> hashed field </a> . To create a compound hashed index, specify <code class="leafygreen-ui-1l06pbn"> hashed </code> as the value of any single index key when creating the index. </p> <p class="leafygreen-ui-1kp3ins"> Compound hashed index compute the hash value of a single field in the compound index; this value is used along with the other fields in the index as your shard key. </p> <p class="leafygreen-ui-1kp3ins"> Compound hashed sharding supports features like <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding"> zone sharding </a> , where the prefix (i.e. first) non-hashed field or fields support zone ranges while the hashed field supports more even distribution of the sharded data. Compound hashed sharding also supports shard keys with a hashed prefix for resolving data distribution issues related to <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-monotonic"> monotonically increasing fields <!-- --> . </a> </p> </dd> </dl> <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="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> MongoDB <code class="leafygreen-ui-1l06pbn"> hashed </code> indexes truncate floating point numbers to 64-bit integers before hashing. For example, a <code class="leafygreen-ui-1l06pbn"> hashed </code> index would store the same value for a field that held a value of <code class="leafygreen-ui-1l06pbn"> 2.3 </code> , <code class="leafygreen-ui-1l06pbn"> 2.2 </code> , and <code class="leafygreen-ui-1l06pbn"> 2.9 </code> . To prevent collisions, do not use a <code class="leafygreen-ui-1l06pbn"> hashed </code> index for floating point numbers that cannot be reliably converted to 64-bit integers (and then back to floating point). MongoDB <code class="leafygreen-ui-1l06pbn"> hashed </code> indexes do not support floating point values larger than 2 <sup> 53 </sup> . </p> <p class="leafygreen-ui-1kp3ins"> To see what the hashed value would be for a key, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/convertShardKeyToHashed/#mongodb-method-convertShardKeyToHashed"> <code class="leafygreen-ui-1l06pbn"> convertShardKeyToHashed() </code> . </a> </p> </div> </div> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-hashvalue" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <a href="#ref-hashvalue-id1"> 1 </a> ] </td> <td class="leafygreen-ui-17r2xs0"> <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> provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/convertShardKeyToHashed/#mongodb-method-convertShardKeyToHashed"> <code class="leafygreen-ui-1l06pbn"> convertShardKeyToHashed() </code> </a> method. This method uses the same hashing function as the hashed index and can be used to see what the hashed value would be for a key. </td> </tr> </tbody> </table> <span class="leafygreen-ui-1qnjd6d" id="std-label-hashed-sharding-shard-key"> </span> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Hashed Sharding Shard Key <a class="headerlink leafygreen-ui-1kepx47" href="#hashed-sharding-shard-key" 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-shard-key"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The field you choose as your hashed shard key should have a good <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-range"> cardinality </a> , or large number of different values. Hashed keys are ideal for shard keys with fields that change <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-monotonic"> monotonically </a> like <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-ObjectId"> ObjectId </a> values or timestamps. A good example of this is the default <code class="leafygreen-ui-1l06pbn"> _id </code> field, assuming it only contains <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-ObjectId"> ObjectId </a> values. </p> <p class="leafygreen-ui-1kp3ins"> To shard a collection using a hashed shard key, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/deploy-shard-cluster/#std-label-deploy-hashed-sharded-cluster-shard-collection"> Shard a Collection <!-- --> . </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-hashed-versus-ranged-sharding"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Hashed vs Ranged Sharding <a class="headerlink leafygreen-ui-1kepx47" href="#hashed-vs-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="hashed-vs-ranged-sharding"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Given a collection using a monotonically increasing value <code class="leafygreen-ui-1l06pbn"> X </code> as the shard key, using ranged sharding results in a distribution of incoming inserts similar to the following: </p> <div class="css-y1v7l ej97su30"> <div role="button" tabindex="-1"> <img alt="Diagram of poor shard key distribution due to monotonically increasing or decreasing shard key" class="leafygreen-ui-1qnf57e" height="600" src="/docs/manual/images/sharded-cluster-monotonic-distribution.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"> Since the value of <code class="leafygreen-ui-1l06pbn"> X </code> is always increasing, the chunk with an upper bound of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MaxKey"> <code class="leafygreen-ui-1l06pbn"> MaxKey </code> </a> receives the majority incoming writes. This restricts insert operations to the single shard containing this chunk, which reduces or removes the advantage of distributed writes in a sharded cluster. </p> <p class="leafygreen-ui-1kp3ins"> By using a hashed index on <code class="leafygreen-ui-1l06pbn"> X </code> , the distribution of inserts is similar to the following: </p> <div class="css-y1v7l ej97su30"> <div role="button" tabindex="-1"> <img alt="Diagram of hashed shard key distribution" class="leafygreen-ui-1qnf57e" height="552" src="/docs/manual/images/sharded-cluster-hashed-distribution.bakedsvg.svg" style="--border-color:#C1C7C6" width="1162"/> <div class="css-19pi7x2 ej97su31" style="--color:#444"> click to enlarge </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Since the data is now distributed more evenly, inserts are efficiently distributed throughout the cluster. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Shard the Collection <a class="headerlink leafygreen-ui-1kepx47" href="#shard-the-collection" 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-the-collection"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection"> <code class="leafygreen-ui-1l06pbn"> sh.shardCollection() </code> </a> method, specifying the full namespace of the collection and the target <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/#std-label-index-type-hashed"> hashed index </a> to use as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key <!-- --> . </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.shardCollection( \"database.collection\", { &lt;field&gt; : \"hashed\" } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">shardCollection</span>( <span class="lg-highlight-string">"database.collection"</span>, <!-- -->{ &lt;<!-- -->field<!-- -->&gt; <!-- -->: <span class="lg-highlight-string">"hashed"</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> <p class="leafygreen-ui-1kp3ins"> To shard a collection on a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed"> compound hashed index </a> , specify the full namespace of the collection and the target compound hashed index to use as the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key <!-- --> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.shardCollection(\n \"database.collection\",\n { \"fieldA\" : 1, \"fieldB\" : 1, \"fieldC\" : \"hashed\" }\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">sh.<span class="lg-highlight-title lg-highlight-function">shardCollection</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"database.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"fieldA"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"fieldB"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"fieldC"</span> <!-- -->: <span class="lg-highlight-string">"hashed"</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 class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <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> </div> </div> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Shard a Populated Collection <a class="headerlink leafygreen-ui-1kepx47" href="#shard-a-populated-collection" 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-a-populated-collection"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> If you shard a populated collection using a hashed shard key: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The sharding operation creates an initial chunk to cover all of the shard key values. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> After the initial chunk creation, the balancer moves ranges of the initial chunk when it needs to balance data. </p> </li> </ul> <span class="leafygreen-ui-1qnjd6d" id="std-label-shard-empty-collection"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Shard an Empty Collection <a class="headerlink leafygreen-ui-1kepx47" href="#shard-an-empty-collection" 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-an-empty-collection"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The shard collection operation can perform an initial chunk creation and distribution for empty or non-existing collections if <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/"> zones and zone ranges </a> have been defined for the collection. Initial creation and distribution of chunk allows for faster setup of zoned sharding. After the initial distribution, the balancer manages the chunk distribution going forward per usual. </p> <dl> <dt> Sharding Empty Collection on Single Field Hashed Shard Key </dt> <dd class="css-1ufxuu7"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> With no <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zones-sharding"> zones and zone ranges </a> specified for the empty or non-existing collection: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The sharding operation creates an empty chunk to cover the entire range of the shard key values. Starting in version 7.2, the operation creates 1 chunk per shard by default and migrates across the cluster. You can use <code class="leafygreen-ui-1l06pbn"> numInitialChunks </code> option to specify a different number of initial chunks and cause an initial chunk distribution. This initial creation and distribution of chunks allows for faster setup of sharding. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> After the initial distribution, the balancer manages the chunk distribution going forward. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> With zones and zone ranges specified for the empty or a non-existing collection: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The sharding operation creates empty chunks for the defined zone ranges as well as any additional chunks to cover the entire range of the shard key values and performs an initial chunk distribution based on the zone ranges. This initial creation and distribution of chunks allows for faster setup of zoned sharding. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> After the initial distribution, the balancer manages the chunk distribution going forward. </p> </li> </ul> </li> </ul> </dd> <dt> Sharding Empty Collection on Compound Hashed Shard Key with Hashed Field Prefix </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> If the compound hashed shard key has the hashed field as the prefix (the hashed field is the first field in the shard key): </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> With no zones and zone ranges specified for the empty or non-existing collection: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The sharding operation creates empty chunks to cover the entire range of the shard key values and performs an initial chunk distribution. The value of all non-hashed fields is <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MinKey"> <code class="leafygreen-ui-1l06pbn"> MinKey </code> </a> at each split point. Starting in version 7.2, the operation creates 1 chunk per shard by default and migrates across the cluster. You can use <code class="leafygreen-ui-1l06pbn"> numInitialChunks </code> option to specify a different number of initial chunks and cause an initial chunk distribution. This initial creation and distribution of chunks allows for faster setup of sharding. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> After the initial distribution, the balancer manages the chunk distribution going forward. </p> </li> </ul> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> With a <em> single </em> zone with a range from <code class="leafygreen-ui-1l06pbn"> MinKey </code> to <code class="leafygreen-ui-1l06pbn"> MaxKey </code> specified for the empty or a non-existing collection <em> and </em> the <code class="leafygreen-ui-1l06pbn"> presplitHashedZones </code> option specified to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection"> <code class="leafygreen-ui-1l06pbn"> sh.shardCollection() </code> : </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The sharding operation creates empty chunks for the defined zone range as well as any additional chunks to cover the entire range of the shard key values and performs an initial chunk distribution based on the zone ranges. This initial creation and distribution of chunks allows for faster setup of zoned sharding. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> After the initial distribution, the balancer manages the chunk distribution going forward. </p> </li> </ul> </li> </ul> </dd> <dt> Sharding Empty Collection on Compound Hashed Shard Key with Non-Hashed Prefix </dt> <dd class="css-1ufxuu7"> <p class="leafygreen-ui-1kp3ins"> If the compound hashed shard key has one or more non-hashed fields as the prefix (i.e. the hashed field is <em> not </em> the first field in the shard key): </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> With no zones and zone ranges specified for the empty or non-existing collection <em> and </em> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones"> preSplitHashedZones </a> is <code class="leafygreen-ui-1l06pbn"> false </code> or omitted, MongoDB does not perform any initial chunk creation or distribution when sharding the collection. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> With no zones and zone ranges specified for the empty or non-existing collection <em> and </em> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones"> preSplitHashedZones </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection"> <code class="leafygreen-ui-1l06pbn"> sh.shardCollection() </code> </a> / <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/shardCollection/#mongodb-dbcommand-dbcmd.shardCollection"> <code class="leafygreen-ui-1l06pbn"> shardCollection </code> </a> returns an error. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> With zones and zone ranges specified for the empty or a non-existing collection <em> and </em> the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones"> preSplitHashedZones </a> option specified to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection"> <code class="leafygreen-ui-1l06pbn"> sh.shardCollection() </code> : </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The sharding operation creates empty chunks for the defined zone ranges as well as any additional chunks to cover the entire range of the shard key values. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The sharding operation further subdivides the initial chunk for each range, such that each shard in the zone is allocated an equal number of chunks. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> This initial creation and distribution of chunks allows for faster setup of zoned sharding. After the initial distribution, the balancer manages the chunk distribution going forward. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The defined ranges for each zone <em> must </em> meet certain requirements. For a description of the requirements and a complete example, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-hashed-example"> Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection <!-- --> . </a> </p> </li> </ul> </dd> </dl> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Drop a Hashed Shard Key Index <a class="headerlink leafygreen-ui-1kepx47" href="#drop-a-hashed-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="drop-a-hashed-shard-key-index"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 7.0.3 (and 6.0.12 and 5.0.22), you can drop the index for a hashed shard key. </p> <p class="leafygreen-ui-1kp3ins"> This can speed up data insertion for collections sharded with a hashed shard key. It can also speed up data ingestion when using <code class="leafygreen-ui-1l06pbn"> mongosync </code> . </p> <p class="leafygreen-ui-1kp3ins"> For details, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/drop-a-hashed-shard-key-index/#std-label-drop-a-hashed-shard-key-index"> Drop a Hashed Shard Key Index <!-- --> . </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"> To learn how to deploy a sharded cluster and implement hashed sharding, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/deploy-shard-cluster/#std-label-sharding-procedure-setup"> Deploy a Self-Managed Sharded Cluster <!-- --> . </a> </p> </div> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/cursor.addOption/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> cursor.addOption() <a class="headerlink leafygreen-ui-1kepx47" href="#cursor.addoption--" 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="cursor.addoption--"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#flags" target="_self"> <span> Flags </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> cursor.addOption(flag) </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-cursor.addOption" title="Permalink to this definition"> <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="mongodb-method-cursor.addOption"> </div> </a> </dt> <dd> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> mongosh Method </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This page documents a <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> method. This is <em> not </em> the documentation for a language-specific driver, such as Node.js. </p> <p class="leafygreen-ui-1kp3ins"> For MongoDB API drivers, refer to the language-specific <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> MongoDB driver documentation <!-- --> . </span> </a> </p> </div> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Deprecated since v3.2 </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Starting in v3.2, the <code class="leafygreen-ui-1l06pbn"> cursor.addOption() </code> operator is deprecated in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo"> <code class="leafygreen-ui-1l06pbn"> mongo </code> </a> . Use available <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/js-cursor/#std-label-doc-cursor-methods"> cursor methods </a> instead. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> Used to change query behavior by setting the flags listed below. </p> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> cursor.addOption() </code> method has the following parameter: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Parameter </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> flag </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> flag </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> For <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> , you can use the cursor flags listed below. For the driver-specific list, see your <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> driver documentation <!-- --> . </span> </a> </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> <span class="leafygreen-ui-1qnjd6d" id="std-label-cursor-flags"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Flags <a class="headerlink leafygreen-ui-1kepx47" href="#flags" 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="flags"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <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> provides several additional cursor flags to modify the behavior of the cursor. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Flag </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> DBQuery.Option.tailable </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-DBQuery.Option.tailable" title="Permalink to this definition"> <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="mongodb-data-DBQuery.Option.tailable"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Sets the cursor not to close once the last data is received, allowing the query to continue returning data added after the initial results were exhausted. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> DBQuery.Option.slaveOk </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-DBQuery.Option.slaveOk" title="Permalink to this definition"> <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="mongodb-data-DBQuery.Option.slaveOk"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Allows querying of a replica secondary. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> DBQuery.Option.noTimeout </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-DBQuery.Option.noTimeout" title="Permalink to this definition"> <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="mongodb-data-DBQuery.Option.noTimeout"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Prevents the server from timing out idle cursors. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> DBQuery.Option.awaitData </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-DBQuery.Option.awaitData" title="Permalink to this definition"> <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="mongodb-data-DBQuery.Option.awaitData"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> For use with <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-DBQuery.Option.tailable" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> DBQuery.Option.tailable </code> </span> </a> . Sets the cursor to block the query thread when no data is available and await data for a set time instead of immediately returning no data. The cursor returns no data only if the timeout expires. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> DBQuery.Option.exhaust </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-DBQuery.Option.exhaust" title="Permalink to this definition"> <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="mongodb-data-DBQuery.Option.exhaust"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Sets the cursor to return all data returned by the query at once rather than splitting the results into batches. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <dl class="data"> <dt> <code class="leafygreen-ui-1l06pbn"> DBQuery.Option.partial </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-DBQuery.Option.partial" title="Permalink to this definition"> <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="mongodb-data-DBQuery.Option.partial"> </div> </a> </dt> <dd> </dd> </dl> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Sets the cursor to return partial data from a query against a sharded cluster in which some shards do not respond rather than throwing an error. </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following example adds the <code class="leafygreen-ui-1l06pbn"> DBQuery.Option.tailable </code> flag and the <code class="leafygreen-ui-1l06pbn"> DBQuery.Option.awaitData </code> flag to ensure that the query returns a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/tailable-cursors/#std-label-tailable-cursors-landing-page"> tailable cursor </a> . The sequence creates a cursor. After returning the full result set, it waits for the default interval of 1000 milliseconds so that it can capture and return additional data added during the query: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var t = db.myCappedCollection;\nvar cursor = t.find().addOption(DBQuery.Option.tailable).\n addOption(DBQuery.Option.awaitData)","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"><span class="lg-highlight-keyword">var</span> t <!-- -->= <!-- -->db.<span class="lg-highlight-property">myCappedCollection</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> cursor <!-- -->= <!-- -->t.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">addOption</span>(<span class="lg-highlight-title lg-highlight-class">DBQuery</span>.<span class="lg-highlight-property">Option</span>.<span class="lg-highlight-property">tailable</span>).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">addOption</span>(<span class="lg-highlight-title lg-highlight-class">DBQuery</span>.<span class="lg-highlight-property">Option</span>.<span class="lg-highlight-property">awaitData</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 class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Adding incorrect wire protocol flags can cause problems and/or extra server load. </p> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $isNumber (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-isnumber--aggregation-" 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="-isnumber--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="expression"> <dt> <code class="leafygreen-ui-1l06pbn"> $isNumber </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-isNumber" title="Permalink to this definition"> <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="mongodb-expression-exp.-isNumber"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $isNumber </code> checks if the specified <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> expression </a> resolves to one of the following numeric <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-BSON-types"> BSON types <!-- --> : </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Int32"> <code class="leafygreen-ui-1l06pbn"> Integer </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Decimal128"> <code class="leafygreen-ui-1l06pbn"> Decimal </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Double"> <code class="leafygreen-ui-1l06pbn"> Double </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Int64"> <code class="leafygreen-ui-1l06pbn"> Long </code> </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $isNumber </code> returns: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> true </code> if the expression resolves to a number. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> false </code> if the expression resolves to any other <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types"> BSON type </a> , <code class="leafygreen-ui-1l06pbn"> null </code> , or a missing field. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $isNumber </code> has the following <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-agg-quick-ref-operator-expressions"> operator expression syntax <!-- --> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $isNumber: &lt;expression&gt; }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$isNumber</span>: &lt;<!-- -->expression<!-- -->&gt; <!-- -->}</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"> The argument can be any valid <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> expression <!-- --> . </a> </p> </dd> </dl> <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"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/type/#mongodb-expression-exp.-type"> <code class="leafygreen-ui-1l06pbn"> $type (Aggregation) </code> </a> - returns the BSON type of the argument. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/type/#mongodb-query-op.-type"> <code class="leafygreen-ui-1l06pbn"> $type (Query) </code> </a> - filters fields based on BSON type. </p> </li> </ul> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Use $isNumber to Check if a Field is Numeric <a class="headerlink leafygreen-ui-1kepx47" href="#use--isnumber-to-check-if-a-field-is-numeric" 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="use--isnumber-to-check-if-a-field-is-numeric"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Issue the following operation against the <code class="leafygreen-ui-1l06pbn"> examples.sensors </code> collection to populate test data: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"examples\").sensors.insertMany([\n { \"_id\" : 1, \"reading\" : NumberDecimal(26.0) },\n { \"_id\" : 2, \"reading\" : NumberLong(25.0) },\n { \"_id\" : 3, \"reading\" : NumberInt(24) },\n { \"_id\" : 4, \"reading\" : 24.0 },\n { \"_id\" : 5, \"reading\" : \"24\" },\n { \"_id\" : 6, \"reading\" : [ NumberDecimal(26) ]}\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">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"examples"</span>).<span class="lg-highlight-property">sensors</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">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-number">26.0</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">25.0</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberInt</span>(<span class="lg-highlight-number">24</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-number">24.0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-string">"24"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-number">26</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> aggregation stage to add the following fields to each document: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> isNumber </code> - Indicates whether the value of <code class="leafygreen-ui-1l06pbn"> reading </code> is an integer, decimal, double, or long. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> type </code> - Indicates the BSON type of <code class="leafygreen-ui-1l06pbn"> reading </code> . </p> </li> </ul> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sensors.aggregate([{\n $addFields : {\n \"isNumber\" : { $isNumber : \"$reading\" },\n \"hasType\" : {$type : \"$reading\"}\n }\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">db.<span class="lg-highlight-property">sensors</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->$addFields<!-- --> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"isNumber"</span> <!-- -->: <!-- -->{ <!-- -->$isNumber<!-- --> <!-- -->: <span class="lg-highlight-string">"$reading"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hasType"</span> <!-- -->: <!-- -->{<!-- -->$type<!-- --> <!-- -->: <span class="lg-highlight-string">"$reading"</span>}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The aggregation operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"reading\" : NumberDecimal(\"26.0000000000000\"), \"isNum \" : true, \"type\" : \"decimal\" }\n{ \"_id\" : 2, \"reading\" : NumberLong(25), \"isNum \" : true, \"type\" : \"long\" }\n{ \"_id\" : 3, \"reading\" : 24, \"isNum \" : true, \"type\" : \"int\" }\n{ \"_id\" : 4, \"reading\" : 24, \"isNum \" : true, \"type\" : \"double\" }\n{ \"_id\" : 5, \"reading\" : \"24\", \"isNum \" : false, \"type\" : \"string\" }\n{ \"_id\" : 6, \"reading\" : [ NumberDecimal(\"26.0000000000000\") ], \"isNum \" : false, \"type\" : \"array\" }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"26.0000000000000"</span>)<!-- -->, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"decimal"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">25</span>)<!-- -->, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"long"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-number">24</span>, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"int"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-number">24</span>, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"double"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-string">"24"</span>, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">false</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"string"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"26.0000000000000"</span>) ]<!-- -->, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">false</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"array"</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Conditionally Modify Fields using $isNumber <a class="headerlink leafygreen-ui-1kepx47" href="#conditionally-modify-fields-using--isnumber" 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="conditionally-modify-fields-using--isnumber"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> grades </code> collection contains data on student grades. The <code class="leafygreen-ui-1l06pbn"> grade </code> field may either store a string letter grade <em> or </em> a numeric point value. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"examples\").grades.insertMany([\n {\n \"student_id\" : 457864153,\n \"class_id\" : \"01\",\n \"class_desc\" : \"Algebra\",\n \"grade\" : \"A\"\n },\n {\n \"student_id\" : 457864153,\n \"class_id\" : \"02\",\n \"class_desc\" : \"Chemistry\",\n \"grade\" : 3.0\n },\n {\n \"student_id\" : 978451637,\n \"class_id\" : \"03\",\n \"class_desc\" : \"Physics\",\n \"grade\" : \"C\"\n },\n {\n \"student_id\" : 978451637,\n \"class_id\" : \"04\",\n \"class_desc\" : \"English\",\n \"grade\" : 4.0\n }\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">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"examples"</span>).<span class="lg-highlight-property">grades</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"student_id"</span> <!-- -->: <span class="lg-highlight-number">457864153</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"class_id"</span> <!-- -->: <span class="lg-highlight-string">"01"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"class_desc"</span> <!-- -->: <span class="lg-highlight-string">"Algebra"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-string">"A"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"student_id"</span> <!-- -->: <span class="lg-highlight-number">457864153</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"class_id"</span> <!-- -->: <span class="lg-highlight-string">"02"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"class_desc"</span> <!-- -->: <span class="lg-highlight-string">"Chemistry"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">3.0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"student_id"</span> <!-- -->: <span class="lg-highlight-number">978451637</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"class_id"</span> <!-- -->: <span class="lg-highlight-string">"03"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"class_desc"</span> <!-- -->: <span class="lg-highlight-string">"Physics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-string">"C"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"student_id"</span> <!-- -->: <span class="lg-highlight-number">978451637</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"class_id"</span> <!-- -->: <span class="lg-highlight-string">"04"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"class_desc"</span> <!-- -->: <span class="lg-highlight-string">"English"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">4.0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> stage to add a <code class="leafygreen-ui-1l06pbn"> points </code> field containing the numeric grade value for that course. The stage uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/cond/#mongodb-expression-exp.-cond"> <code class="leafygreen-ui-1l06pbn"> $cond </code> </a> operator to set the value of <code class="leafygreen-ui-1l06pbn"> points </code> based on the output of <code class="leafygreen-ui-1l06pbn"> $isNumber </code> : </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> true </code> , <code class="leafygreen-ui-1l06pbn"> grades </code> already contains the numeric point value. Set <code class="leafygreen-ui-1l06pbn"> points </code> equal to <code class="leafygreen-ui-1l06pbn"> grades </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> false </code> , <code class="leafygreen-ui-1l06pbn"> grades </code> contains a string letter value. Use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/switch/#mongodb-expression-exp.-switch"> <code class="leafygreen-ui-1l06pbn"> $switch </code> </a> to convert the letter grade to its equivalent point value and assign to <code class="leafygreen-ui-1l06pbn"> points </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The aggregation pipeline then uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> stage to group on the <code class="leafygreen-ui-1l06pbn"> student_id </code> and calculate the student's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/avg/#mongodb-group-grp.-avg"> <code class="leafygreen-ui-1l06pbn"> average </code> </a> GPA. </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":" db.getSiblingDB(\"examples\").grades.aggregate([\n {\n $addFields: {\n \"points\" : {\n $cond : {\n if : { $isNumber : \"$grade\" },\n then: \"$grade\" ,\n else: {\n $switch : {\n branches: [\n { case: {$eq : [\"$grade\" , \"A\"]}, then : 4.0 },\n { case: {$eq : [\"$grade\" , \"B\"]}, then : 3.0 },\n { case: {$eq : [\"$grade\" , \"C\"]}, then : 2.0 },\n { case: {$eq : [\"$grade\" , \"D\"]}, then : 1.0 },\n { case: {$eq : [\"$grade\" , \"F\"]}, then : 0.0 }\n ]\n }\n }\n }\n }\n }\n },\n {\n $group : {\n _id : \"$student_id\",\n GPA : {\n $avg : \"$points\"\n }\n }\n }\n])","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"> db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"examples"</span>).<span class="lg-highlight-property">grades</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$addFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"points"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->$cond<!-- --> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">if</span> <!-- -->: <!-- -->{ <!-- -->$isNumber<!-- --> <!-- -->: <span class="lg-highlight-string">"$grade"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-string">"$grade"</span> <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">else</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->$switch<!-- --> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">branches</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{<!-- -->$eq<!-- --> <!-- -->: <!-- -->[<span class="lg-highlight-string">"$grade"</span> <!-- -->, <span class="lg-highlight-string">"A"</span>]}<!-- -->, <!-- -->then <!-- -->: <span class="lg-highlight-number">4.0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{<!-- -->$eq<!-- --> <!-- -->: <!-- -->[<span class="lg-highlight-string">"$grade"</span> <!-- -->, <span class="lg-highlight-string">"B"</span>]}<!-- -->, <!-- -->then <!-- -->: <span class="lg-highlight-number">3.0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{<!-- -->$eq<!-- --> <!-- -->: <!-- -->[<span class="lg-highlight-string">"$grade"</span> <!-- -->, <span class="lg-highlight-string">"C"</span>]}<!-- -->, <!-- -->then <!-- -->: <span class="lg-highlight-number">2.0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{<!-- -->$eq<!-- --> <!-- -->: <!-- -->[<span class="lg-highlight-string">"$grade"</span> <!-- -->, <span class="lg-highlight-string">"D"</span>]}<!-- -->, <!-- -->then <!-- -->: <span class="lg-highlight-number">1.0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{<!-- -->$eq<!-- --> <!-- -->: <!-- -->[<span class="lg-highlight-string">"$grade"</span> <!-- -->, <span class="lg-highlight-string">"F"</span>]}<!-- -->, <!-- -->then <!-- -->: <span class="lg-highlight-number">0.0</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->$group<!-- --> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->_id <!-- -->: <span class="lg-highlight-string">"$student_id"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable lg-highlight-constant">GPA</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->$avg<!-- --> <!-- -->: <span class="lg-highlight-string">"$points"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The aggregation pipeline outputs one document per unique <code class="leafygreen-ui-1l06pbn"> student_id </code> with that student's <code class="leafygreen-ui-1l06pbn"> GPA </code> grade point average: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 457864153, \"GPA\" : 3.5 }\n{ \"_id\" : 978451637, \"GPA\" : 3 }","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">457864153</span>, <span class="lg-highlight-string">"GPA"</span> <!-- -->: <span class="lg-highlight-number">3.5</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">978451637</span>, <span class="lg-highlight-string">"GPA"</span> <!-- -->: <span class="lg-highlight-number">3</span> }</td></tr></tbody></table></code></pre> </div> </div> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/audit-message/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> System Event Audit Messages in Self-Managed Deployments <a class="headerlink leafygreen-ui-1kepx47" href="#system-event-audit-messages-in-self-managed-deployments" 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="system-event-audit-messages-in-self-managed-deployments"> </div> </a> </h1> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> System Event Audit Messages are available in <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise"> MongoDB Enterprise </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/" target="_self"> <span> MongoDB Atlas <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> To learn more about this feature in MongoDB Atlas, see the Atlas documentation for <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/database-auditing/#std-label-set-up-database-auditing" target="_self"> <span> Set Up Database Auditing </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/mongodb-logs/#std-label-mongodb-logs" target="_self"> <span> View and Download MongoDB Logs <!-- --> . </span> </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> When the MongoDB auditing facility captures events, you can specify the schema that MongoDB uses for log message output: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> mongo </code> schema writes logs in a format designed by MongoDB. This is the default log output schema. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> OCSF </code> schema writes logs in <span class="leafygreen-ui-vm4wms" tabindex="0"> OCSF </span> format. This option provides logs in a more widely-used standardized format compatible with log processors. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> To set the schema used for log messages, use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-auditLog.schema"> <code class="leafygreen-ui-1l06pbn"> auditLog.schema </code> </a> configuration file option. </p> <p class="leafygreen-ui-1kp3ins"> For examples and details on the messages returned in each schema, see these pages: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/mongo/#std-label-event-audit-messages-mongo"> mongo Schema Audit Messages </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/ocsf/#std-label-event-audit-messages-ocsf"> OCSF Schema Audit Messages </a> </p> </li> </ul> </section>
https://www.mongodb.com/docs/manual/reference/mongodb-wire-protocol/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> MongoDB Wire Protocol <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-wire-protocol" 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="mongodb-wire-protocol"> </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="#introduction" target="_self"> <span> Introduction </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#tcp-ip-socket" target="_self"> <span> TCP/IP Socket </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#messages-types-and-formats" target="_self"> <span> Messages Types and Formats </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#standard-message-header" target="_self"> <span> Standard Message Header </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#opcodes" target="_self"> <span> Opcodes </span> </a> </li> </ul> </div> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This MongoDB Wire Protocol Specification is licensed under a <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://creativecommons.org/licenses/by-nc-sa/3.0/us/" rel="noopener noreferrer"> <span> Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License </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> . You may not use or adapt this material for any commercial purpose, such as to create a commercial database or database-as-a-service offering. </p> </div> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Introduction <a class="headerlink leafygreen-ui-1kepx47" href="#introduction" 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="introduction"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The MongoDB Wire Protocol is a simple socket-based, request-response style protocol. Clients communicate with the database server through a regular TCP/IP socket. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> TCP/IP Socket <a class="headerlink leafygreen-ui-1kepx47" href="#tcp-ip-socket" 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="tcp-ip-socket"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Clients should connect to the database with a regular TCP/IP socket. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Port <a class="headerlink leafygreen-ui-1kepx47" href="#port" 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="port"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The default port number for <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instances is 27017. The port number for <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> is configurable and may vary. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Byte Ordering <a class="headerlink leafygreen-ui-1kepx47" href="#byte-ordering" 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="byte-ordering"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> All integers in the MongoDB wire protocol use little-endian byte order: that is, least-significant byte first. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Messages Types and Formats <a class="headerlink leafygreen-ui-1kepx47" href="#messages-types-and-formats" 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="messages-types-and-formats"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wire-op-msg" target="_self"> <span> OP_MSG </span> </a> opcode for both client requests and database replies. There are several message formats used in older versions of MongoDB which have been deprecated in favor of <code class="leafygreen-ui-1l06pbn"> OP_MSG </code> . </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"> This page uses a C-like <code class="leafygreen-ui-1l06pbn"> struct </code> to describe the message structure. </p> <p class="leafygreen-ui-1kp3ins"> The types used in this document, such as <code class="leafygreen-ui-1l06pbn"> int32 </code> and <code class="leafygreen-ui-1l06pbn"> cstring </code> , are the same as those defined in the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://bsonspec.org/#/specification" rel="noopener noreferrer"> <span> BSON specification </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> . </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-wp-message-header"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Standard Message Header <a class="headerlink leafygreen-ui-1kepx47" href="#standard-message-header" 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="standard-message-header"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> In general, each message consists of a standard message header followed by request-specific data. The standard message header is structured as follows: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"struct MsgHeader {\n int32 messageLength; // total message size, including this\n int32 requestID; // identifier for this message\n int32 responseTo; // requestID from the original request\n // (used in responses from the database)\n int32 opCode; // message type\n}","programmingLanguage":"C"} </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 c leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword lg-highlight-class">struct</span><span class="lg-highlight-class"> </span><span class="lg-highlight-title lg-highlight-class">MsgHeader</span><span class="lg-highlight-class"> {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> int32 messageLength; <span class="lg-highlight-comment">// total message size, including this</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> int32 requestID; <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> identifier for this </span><span class="lg-highlight-comment">message</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> int32 responseTo; <span class="lg-highlight-comment">// requestID</span><span class="lg-highlight-comment"> from the original </span><span class="lg-highlight-comment">request</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-comment">// (used</span><span class="lg-highlight-comment"> in responses from </span><span class="lg-highlight-comment">the database)</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> int32 opCode; <span class="lg-highlight-comment">// message type</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 class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> messageLength </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The total size of the message in bytes. This total includes the 4 bytes that holds the message length. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> requestID </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> A client or database-generated identifier that uniquely identifies the message. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> responseTo </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The <code class="leafygreen-ui-1l06pbn"> requestID </code> taken from the messages from the client. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> opCode </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Type of message. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wp-request-opcodes" target="_self"> <span> Opcodes </span> </a> for details. </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-wp-request-opcodes"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Opcodes <a class="headerlink leafygreen-ui-1kepx47" href="#opcodes" 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="opcodes"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB uses these <code class="leafygreen-ui-1l06pbn"> opCode </code> values: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:35%"/> <col style="width:10%"/> <col style="width:65%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Opcode Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Comment </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> OP_COMPRESSED </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2012 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Wraps other opcodes using compression </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> OP_MSG </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2013 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Send a message using the standard format. Used for both client requests and database replies. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <code class="leafygreen-ui-1l06pbn"> OP_REPLY </code> </div> </div> <div class="line-block"> <div class="line"> <em> Deprecated in MongoDB 5.0. Removed in MongoDB 5.1. </em> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 1 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Reply to a client request. <code class="leafygreen-ui-1l06pbn"> responseTo </code> is set. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <code class="leafygreen-ui-1l06pbn"> OP_UPDATE </code> </div> </div> <div class="line-block"> <div class="line"> <em> Deprecated in MongoDB 5.0. Removed in MongoDB 5.1. </em> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2001 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Update document. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <code class="leafygreen-ui-1l06pbn"> OP_INSERT </code> </div> </div> <div class="line-block"> <div class="line"> <em> Deprecated in MongoDB 5.0. Removed in MongoDB 5.1. </em> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2002 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Insert new document. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> RESERVED </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2003 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Formerly used for OP_GET_BY_OID. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <code class="leafygreen-ui-1l06pbn"> OP_QUERY </code> </div> </div> <div class="line-block"> <div class="line"> <em> Deprecated in MongoDB 5.0. Removed in MongoDB 5.1. </em> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2004 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Query a collection. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <code class="leafygreen-ui-1l06pbn"> OP_GET_MORE </code> </div> </div> <div class="line-block"> <div class="line"> <em> Deprecated in MongoDB 5.0. Removed in MongoDB 5.1. </em> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2005 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Get more data from a query. See Cursors. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <code class="leafygreen-ui-1l06pbn"> OP_DELETE </code> </div> </div> <div class="line-block"> <div class="line"> <em> Deprecated in MongoDB 5.0. Removed in MongoDB 5.1. </em> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2006 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Delete documents. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <code class="leafygreen-ui-1l06pbn"> OP_KILL_CURSORS </code> </div> </div> <div class="line-block"> <div class="line"> <em> Deprecated in MongoDB 5.0. Removed in MongoDB 5.1. </em> </div> </div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2007 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Notify database that the client has finished with the cursor. </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-wire-op-compressed"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> OP_COMPRESSED </code> <a class="headerlink leafygreen-ui-1kepx47" href="#op_compressed" 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="op_compressed"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Any opcode can be compressed and wrapped in an <code class="leafygreen-ui-1l06pbn"> OP_COMPRESSED </code> header. The <code class="leafygreen-ui-1l06pbn"> OP_COMPRESSED </code> message contains the original compressed opcode message alongside the metadata necessary to process and decompress it. </p> <p class="leafygreen-ui-1kp3ins"> The format of the <code class="leafygreen-ui-1l06pbn"> OP_COMPRESSED </code> message is: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"struct {\n MsgHeader header; // standard message header\n int32 originalOpcode; // value of wrapped opcode\n int32 uncompressedSize; // size of deflated compressedMessage, excluding MsgHeader\n uint8 compressorId; // ID of compressor that compressed message\n char *compressedMessage; // opcode itself, excluding MsgHeader\n}","programmingLanguage":"Bash"} </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 bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">struct {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> MsgHeader header; // standard message header</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> int32 originalOpcode; // value of wrapped opcode</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> int32 uncompressedSize; // size of deflated compressedMessage, excluding MsgHeader</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> uint8 compressorId; // ID of compressor that compressed message</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> char *compressedMessage; // opcode itself, excluding MsgHeader</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 class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:25%"/> <col style="width:75%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> MsgHeader </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Message header, as described in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wp-message-header" target="_self"> <span> Standard Message Header <!-- --> . </span> </a> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> originalOpcode </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Contains the value of the wrapped opcode. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> uncompressedSize </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The size of the deflated <code class="leafygreen-ui-1l06pbn"> compressedMessage </code> , which excludes the <code class="leafygreen-ui-1l06pbn"> MsgHeader </code> . </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> compressorId </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The ID of the compressor that compressed the message. A list of <code class="leafygreen-ui-1l06pbn"> compressorId </code> values is provided below. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> compressedMessage </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The opcode itself, excluding the <code class="leafygreen-ui-1l06pbn"> MsgHeader </code> . </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Each compressor is assigned a predefined compressor ID as follows: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:15%"/> <col style="width:25%"/> <col style="width:60%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> compressorId </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Handshake Value </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> 0 </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> noop </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The content of the message is uncompressed. This is used for testing. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> 1 </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> snappy </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The content of the message is compressed using snappy. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> 2 </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> zlib </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The content of the message is compressed using zlib. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> 3 </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> zstd </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The content of the message is compressed using zstd. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> 4-255 </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> reserved </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Reserved for future use. </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-wire-op-msg"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> <code class="leafygreen-ui-1l06pbn"> OP_MSG </code> <a class="headerlink leafygreen-ui-1kepx47" href="#op_msg" 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="op_msg"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> OP_MSG </code> is an extensible message format used to encode both client requests and server replies on the wire. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> OP_MSG </code> has the following format: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"OP_MSG {\n MsgHeader header; // standard message header\n uint32 flagBits; // message flags\n Sections[] sections; // data sections\n optional&lt;uint32&gt; checksum; // optional CRC-32C checksum\n}"} </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">OP_MSG {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> MsgHeader header; // standard message header</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> uint32 flagBits; // message flags</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> Sections[] sections; // data sections</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> optional&lt;uint32&gt; checksum; // optional CRC-32C checksum</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 class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> header </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Standard message header, as described in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wp-message-header" target="_self"> <span> Standard Message Header <!-- --> . </span> </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> flagBits </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An integer bitmask containing message flags, as described in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wire-msg-flags" target="_self"> <span> Flag Bits <!-- --> . </span> </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> sections </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Message body sections, as described in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wire-msg-sections" target="_self"> <span> Sections <!-- --> . </span> </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> checksum </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> An optional CRC-32C checksum, as described in <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wire-msg-checksum" target="_self"> <span> Checksum <!-- --> . </span> </a> </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-wire-msg-flags"> </span> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Flag Bits <a class="headerlink leafygreen-ui-1kepx47" href="#flag-bits" 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="flag-bits"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> flagBits </code> integer is a bitmask encoding flags that modify the format and behavior of <code class="leafygreen-ui-1l06pbn"> OP_MSG </code> . </p> <p class="leafygreen-ui-1kp3ins"> The first 16 bits (0-15) are <em> required </em> and parsers <strong> MUST </strong> error if an unknown bit is set. </p> <p class="leafygreen-ui-1kp3ins"> The last 16 bits (16-31) are <em> optional </em> , and parsers <strong> MUST </strong> ignore any unknown set bits. Proxies and other message forwarders <strong> MUST </strong> clear any unknown optional bits before forwarding messages. </p> <div class="header-buffer" id="ref-f1-id1"> </div> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:10%"/> <col style="width:20%"/> <col style="width:10%"/> <col style="width:10%"/> <col style="width:60%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Bit </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Name </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Request </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Response </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 0 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> checksumPresent </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The message ends with 4 bytes containing a CRC-32C <a class="footnote-reference header-buffer" href="#footnote-f1" id="ref-f1-id1"> [ <!-- --> 2 <!-- --> ] </a> checksum. See <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wire-msg-checksum" target="_self"> <span> Checksum </span> </a> for details. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 1 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> moreToCome </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Another message will follow this one without further action from the receiver. The receiver <strong> MUST NOT </strong> send another message until receiving one with <code class="leafygreen-ui-1l06pbn"> moreToCome </code> set to 0 as sends may block, causing deadlock. Requests with the <code class="leafygreen-ui-1l06pbn"> moreToCome </code> bit set will not receive a reply. Replies will only have this set in response to requests with the <code class="leafygreen-ui-1l06pbn"> exhaustAllowed </code> bit set. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 16 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> exhaustAllowed </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> ✓ </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> The client is prepared for multiple replies to this request using the <code class="leafygreen-ui-1l06pbn"> moreToCome </code> bit. The server will never produce replies with the <code class="leafygreen-ui-1l06pbn"> moreToCome </code> bit set unless the request has this bit set. </p> <p class="leafygreen-ui-1kp3ins"> This ensures that multiple replies are only sent when the network layer of the requester is prepared for them. </p> </div> </div> </td> </tr> </tbody> </table> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-wire-msg-sections"> </span> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Sections <a class="headerlink leafygreen-ui-1kepx47" href="#sections" 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="sections"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> An <code class="leafygreen-ui-1l06pbn"> OP_MSG </code> message contains one or more sections. Each section starts with a <code class="leafygreen-ui-1l06pbn"> kind </code> byte indicating its type. Everything after the <code class="leafygreen-ui-1l06pbn"> kind </code> byte constitutes the section's payload. </p> <p class="leafygreen-ui-1kp3ins"> The available kinds of sections follow. </p> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Kind 0: Body <a class="headerlink leafygreen-ui-1kepx47" href="#kind-0--body" 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="kind-0--body"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> A body section is encoded as a <strong> single </strong> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types"> BSON object </a> . The size in the BSON object also serves as the size of the section. This section kind is the standard command request and reply body. </p> <p class="leafygreen-ui-1kp3ins"> All top-level fields <strong> MUST </strong> have a unique name. </p> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Kind 1: Document Sequence <a class="headerlink leafygreen-ui-1kepx47" href="#kind-1--document-sequence" 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="kind-1--document-sequence"> </div> </a> </h4> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> int32 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Size of the section in bytes. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> C String </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Document sequence identifier. In all current commands this field is the (possibly nested) field that it is replacing from the body section. </p> <p class="leafygreen-ui-1kp3ins"> This field <strong> MUST NOT </strong> also exist in the body section. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Zero or more BSON objects </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Objects are sequenced back to back with no separators. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Each object is limited to the <code class="leafygreen-ui-1l06pbn"> maxBSONObjectSize </code> of the server. The combination of all objects is not limited to <code class="leafygreen-ui-1l06pbn"> maxBSONObjSize </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The document sequence ends once <code class="leafygreen-ui-1l06pbn"> size </code> bytes have been consumed. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Parsers <strong> MAY </strong> choose to merge these objects into the body as an array at the path specified by the sequence identifier when converting to language-level objects. </p> </li> </ul> </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Kind 2 <a class="headerlink leafygreen-ui-1kepx47" href="#kind-2" 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="kind-2"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> This section is used for internal purposes. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-wire-msg-checksum"> </span> </section> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Checksum <a class="headerlink leafygreen-ui-1kepx47" href="#checksum" 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="checksum"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Each message <strong> MAY </strong> end with a CRC-32C <a class="footnote-reference header-buffer" href="#footnote-f1" id="ref-f1-id2"> [ <!-- --> 2 <!-- --> ] </a> checksum that covers all bytes in the message except for the checksum itself. </p> <p class="leafygreen-ui-1kp3ins"> If you do not use TLS/SSL connections, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instances exchange messages with checksums. </p> <p class="leafygreen-ui-1kp3ins"> If you use TLS/SSL connections, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instances skip the checksum. </p> <p class="leafygreen-ui-1kp3ins"> Drivers and older binaries will ignore the checksum if presented with messages with checksum. </p> <p class="leafygreen-ui-1kp3ins"> The presence of a checksum is indicated by the <code class="leafygreen-ui-1l06pbn"> checksumPresent </code> flag bit. </p> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Legacy Opcodes <a class="headerlink leafygreen-ui-1kepx47" href="#legacy-opcodes" 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="legacy-opcodes"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.1, these opcodes are removed in favor of <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wire-op-msg" target="_self"> <span> OP_MSG <!-- --> : </span> </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> OP_DELETE </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> OP_GET_MORE </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> OP_INSERT </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> OP_KILL_CURSORS </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> OP_QUERY </code> <a class="footnote-reference header-buffer" href="#footnote-op-query-footnote" id="ref-op-query-footnote-id3"> [ <!-- --> 1 <!-- --> ] </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> OP_REPLY </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> OP_UPDATE </code> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> If you are running an older version of MongoDB and need detailed information on the previous opcodes, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-legacy-opcodes"> Legacy Opcodes <!-- --> . </a> </p> <p class="css-1j389vi"> Footnotes </p> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-op-query-footnote" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <a href="#ref-op-query-footnote-id3"> 1 </a> ] </td> <td class="leafygreen-ui-17r2xs0"> <!-- --> MongoDB 5.1 removes support for both <code class="leafygreen-ui-1l06pbn"> OP_QUERY </code> find operations and <code class="leafygreen-ui-1l06pbn"> OP_QUERY </code> commands. As an exception, <code class="leafygreen-ui-1l06pbn"> OP_QUERY </code> is still supported for running the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/hello/#mongodb-dbcommand-dbcmd.hello"> <code class="leafygreen-ui-1l06pbn"> hello </code> </a> and <code class="leafygreen-ui-1l06pbn"> isMaster </code> commands as part of the connection handshake. </td> </tr> </tbody> </table> <table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-f1" rules="none"> <colgroup> <col/> </colgroup> <tbody valign="top"> <tr> <td class="leafygreen-ui-17r2xs0"> [ <!-- --> 2 <!-- --> ] </td> <td class="leafygreen-ui-17r2xs0"> <em> ( <a href="#ref-f1-id1"> 1 </a> , <a href="#ref-f1-id2"> 2 </a> ) </em> <!-- --> 32-bit <span class="leafygreen-ui-vm4wms" tabindex="0"> CRC </span> computed with the Castagnoli polynomial as described by <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4960#page-140" rel="noopener noreferrer"> <span> https://tools.ietf.org/html/rfc4960#page-140 <!-- --> . </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> </td> </tr> </tbody> </table> </section> </section> </section>
https://www.mongodb.com/docs/manual/core/transactions-sharded-clusters/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Production Considerations (Sharded Clusters) <a class="headerlink leafygreen-ui-1kepx47" href="#production-considerations--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="production-considerations--sharded-clusters-"> </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="#performance" target="_self"> <span> Performance </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#read-concerns" target="_self"> <span> Read Concerns </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#write-concerns" target="_self"> <span> Write Concerns </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#arbiters" target="_self"> <span> Arbiters </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#backups-and-restores" target="_self"> <span> Backups and Restores </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#chunk-migrations" target="_self"> <span> Chunk Migrations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#outside-reads-during-commit" target="_self"> <span> Outside Reads During Commit </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-information" target="_self"> <span> Additional Information </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> You can perform multi-document transactions on sharded clusters. </p> <p class="leafygreen-ui-1kp3ins"> The following page lists concerns specific to running transactions on a sharded cluster. These concerns are in addition to those listed in <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-production-consideration/"> Production Considerations <!-- --> . </a> </p> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Performance <a class="headerlink leafygreen-ui-1kepx47" href="#performance" 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="performance"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Single Shard <a class="headerlink leafygreen-ui-1kepx47" href="#single-shard" 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="single-shard"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Transactions that target a single shard should have the same performance as replica-set transactions. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Multiple Shards <a class="headerlink leafygreen-ui-1kepx47" href="#multiple-shards" 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="multiple-shards"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Transactions that affect multiple shards incur a greater performance cost. </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"> On a sharded cluster, transactions that span multiple shards will error and abort if any involved shard contains an arbiter. </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-transactions-sharded-clusters-time-limit"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Time Limit <a class="headerlink leafygreen-ui-1kepx47" href="#time-limit" 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="time-limit"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To specify a time limit, specify a <code class="leafygreen-ui-1l06pbn"> maxTimeMS </code> limit on <code class="leafygreen-ui-1l06pbn"> commitTransaction </code> . </p> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> maxTimeMS </code> is unspecified, MongoDB will use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.transactionLifetimeLimitSeconds"> <code class="leafygreen-ui-1l06pbn"> transactionLifetimeLimitSeconds </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> If <code class="leafygreen-ui-1l06pbn"> maxTimeMS </code> is specified but would result in transaction that exceeds <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.transactionLifetimeLimitSeconds"> <code class="leafygreen-ui-1l06pbn"> transactionLifetimeLimitSeconds </code> </a> , MongoDB will use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.transactionLifetimeLimitSeconds"> <code class="leafygreen-ui-1l06pbn"> transactionLifetimeLimitSeconds </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> To modify <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.transactionLifetimeLimitSeconds"> <code class="leafygreen-ui-1l06pbn"> transactionLifetimeLimitSeconds </code> </a> for a sharded cluster, the parameter must be modified for all shard replica set members. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Read Concerns <a class="headerlink leafygreen-ui-1kepx47" href="#read-concerns" 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="read-concerns"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Multi-document transactions support <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-"> <code class="leafygreen-ui-1l06pbn"> "local" </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-"> <code class="leafygreen-ui-1l06pbn"> "majority" </code> </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-"> <code class="leafygreen-ui-1l06pbn"> "snapshot" </code> </a> read concern levels. </p> <p class="leafygreen-ui-1kp3ins"> For transactions on a sharded cluster, only the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-"> <code class="leafygreen-ui-1l06pbn"> "snapshot" </code> </a> read concern provides a consistent snapshot across multiple shards. </p> <p class="leafygreen-ui-1kp3ins"> For more information on read concern and transactions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-read-concern"> Transactions and Read Concern <!-- --> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Write Concerns <a class="headerlink leafygreen-ui-1kepx47" href="#write-concerns" 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="write-concerns"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> You cannot run transactions on a sharded cluster that has a shard with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault"> <code class="leafygreen-ui-1l06pbn"> writeConcernMajorityJournalDefault </code> </a> set to <code class="leafygreen-ui-1l06pbn"> false </code> (such as a shard with a voting member that uses the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory"> in-memory storage engine </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"> Regardless of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern"> write concern specified for the transaction </a> , the commit operation for a sharded cluster transaction includes some parts that use <code class="leafygreen-ui-1l06pbn"> {w: "majority", j: true} </code> write concern. </p> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Arbiters <a class="headerlink leafygreen-ui-1kepx47" href="#arbiters" 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="arbiters"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> You cannot change a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> using a transaction if the replica set has an arbiter. Arbiters cannot participate in the data operations required for multi-shard transactions. </p> <p class="leafygreen-ui-1kp3ins"> Transactions whose write operations span multiple shards will error and abort if any transaction operation reads from or writes to a shard that contains an arbiter. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Backups and Restores <a class="headerlink leafygreen-ui-1kepx47" href="#backups-and-restores" 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="backups-and-restores"> </div> </a> </h2> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> To use <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongodump/#std-program-mongodump" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongodump </code> </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#std-program-mongorestore" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> mongorestore </code> </span> </a> as a backup strategy for sharded clusters, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/backup-sharded-cluster-with-database-dumps/#std-label-backup-sharded-dumps"> Back Up a Self-Managed Sharded Cluster with a Database Dump <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> Sharded clusters can also use one of the following coordinated backup and restore processes, which maintain the atomicity guarantees of transactions across shards: </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/atlas/database?tck=docs_server" target="_self"> <span> MongoDB Atlas </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/cloud/cloud-manager?tck=docs_server" target="_self"> <span> MongoDB Cloud Manager </span> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/products/ops-manager?tck=docs_server" target="_self"> <span> MongoDB Ops Manager </span> </a> </p> </li> </ul> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Chunk Migrations <a class="headerlink leafygreen-ui-1kepx47" href="#chunk-migrations" 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="chunk-migrations"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-chunk-migration-procedure"> Chunk migration </a> acquires exclusive collection locks during certain stages. </p> <p class="leafygreen-ui-1kp3ins"> If an ongoing transaction has a lock on a collection and a chunk migration that involves that collection starts, these migration stages must wait for the transaction to release the locks on the collection, thereby impacting the performance of chunk migrations. </p> <p class="leafygreen-ui-1kp3ins"> If a chunk migration interleaves with a transaction (for instance, if a transaction starts while a chunk migration is already in progress and the migration completes before the transaction takes a lock on the collection), the transaction errors during the commit and aborts. </p> <p class="leafygreen-ui-1kp3ins"> Depending on how the two operations interleave, some sample errors include (the error messages have been abbreviated): </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> an error from cluster data placement change ... migration commit in progress for &lt;namespace&gt; </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> Cannot find shardId the chunk belonged to at cluster time ... </code> </p> </li> </ul> <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/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.shardingStatistics.countDonorMoveChunkLockTimeout"> <code class="leafygreen-ui-1l06pbn"> shardingStatistics.countDonorMoveChunkLockTimeout </code> </a> </p> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Outside Reads During Commit <a class="headerlink leafygreen-ui-1kepx47" href="#outside-reads-during-commit" 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="outside-reads-during-commit"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> During the commit for a transaction, outside read operations may try to read the same documents that will be modified by the transaction. If the transaction writes to multiple shards, then during the commit attempt across the shards: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Outside reads that use read concern <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-"> <code class="leafygreen-ui-1l06pbn"> "snapshot" </code> </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-"> <code class="leafygreen-ui-1l06pbn"> "linearizable" </code> </a> wait until all writes of a transaction are visible. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Outside reads that are part of causally consistent sessions (those that include <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/#std-label-afterClusterTime"> afterClusterTime </a> ) wait until all writes of a transaction are visible. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Outside reads using other read concerns do not wait until all writes of a transaction are visible, but instead read the before-transaction version of the documents. </p> </li> </ul> <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/transactions/#std-label-transactions-atomicity"> Transactions and Atomicity </a> </p> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" 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> </h2> <p class="leafygreen-ui-1kp3ins"> See also <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-production-consideration/"> Production Considerations <!-- --> . </a> </p> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Aggregation Stages <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-stages" 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="aggregation-stages"> </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="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#db.collection.aggregate---stages" target="_self"> <span> db.collection.aggregate() Stages </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#db.aggregate---stages" target="_self"> <span> db.aggregate() Stages </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#stages-available-for-updates" target="_self"> <span> Stages Available for Updates </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> In the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> method and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.aggregate/#mongodb-method-db.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.aggregate() </code> </a> method, <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> pipeline </a> stages appear in an array. In the Atlas UI, you can arrange pipeline stages using the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/agg-pipeline/#std-label-atlas-ui-agg-pipeline" target="_self"> <span> aggregation pipeline builder </span> </a> . Documents pass through the stages in sequence. </p> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> You can use <!-- --> pipeline stages <!-- --> for deployments hosted 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> </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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> db.collection.aggregate() Stages <a class="headerlink leafygreen-ui-1kepx47" href="#db.collection.aggregate---stages" 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="db.collection.aggregate---stages"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> All stages except the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out"> <code class="leafygreen-ui-1l06pbn"> $out </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear"> <code class="leafygreen-ui-1l06pbn"> $geoNear </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/changeStream/#mongodb-pipeline-pipe.-changeStream"> <code class="leafygreen-ui-1l06pbn"> $changeStream </code> </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/#mongodb-pipeline-pipe.-changeStreamSplitLargeEvent"> <code class="leafygreen-ui-1l06pbn"> $changeStreamSplitLargeEvent </code> </a> stages can appear multiple times in a pipeline. </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"> For details on a specific operator, including syntax and examples, click on the link to the operator's reference page. </p> </div> </div> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.aggregate( [ { &lt;stage&gt; }, ... ] )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ &lt;<!-- -->stage<!-- -->&gt; <!-- -->}<!-- -->, <!-- -->...<!-- --> ] )</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 class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Stage </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Adds new fields to documents. Similar to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> reshapes each document in the stream; specifically, by adding new fields to output documents that contain both the existing fields from the input documents and the newly added fields. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> is an alias for <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> . </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/bucket/#mongodb-pipeline-pipe.-bucket"> <code class="leafygreen-ui-1l06pbn"> $bucket </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/bucketAuto/#mongodb-pipeline-pipe.-bucketAuto"> <code class="leafygreen-ui-1l06pbn"> $bucketAuto </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically determined in an attempt to evenly distribute the documents into the specified number of buckets. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/changeStream/#mongodb-pipeline-pipe.-changeStream"> <code class="leafygreen-ui-1l06pbn"> $changeStream </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns a <a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams"> Change Stream </a> cursor for the collection. This stage can only occur once in an aggregation pipeline and it must occur as the first stage. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/#mongodb-pipeline-pipe.-changeStreamSplitLargeEvent"> <code class="leafygreen-ui-1l06pbn"> $changeStreamSplitLargeEvent </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Splits large <a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams"> change stream </a> events that exceed 16 MB into smaller fragments returned in a change stream cursor. </p> <p class="leafygreen-ui-1kp3ins"> You can only use <code class="leafygreen-ui-1l06pbn"> $changeStreamSplitLargeEvent </code> in a <code class="leafygreen-ui-1l06pbn"> $changeStream </code> pipeline and it must be the final stage in the pipeline. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/collStats/#mongodb-pipeline-pipe.-collStats"> <code class="leafygreen-ui-1l06pbn"> $collStats </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns statistics regarding a collection or view. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/count/#mongodb-pipeline-pipe.-count"> <code class="leafygreen-ui-1l06pbn"> $count </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns a count of the number of documents at this stage of the aggregation pipeline. </p> <p class="leafygreen-ui-1kp3ins"> Distinct from the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/count-accumulator/#mongodb-group-grp.-count"> <code class="leafygreen-ui-1l06pbn"> $count </code> </a> aggregation accumulator. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/densify/#mongodb-pipeline-pipe.-densify"> <code class="leafygreen-ui-1l06pbn"> $densify </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Creates new documents in a sequence of documents where certain values in a field are missing. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/documents/#mongodb-pipeline-pipe.-documents"> <code class="leafygreen-ui-1l06pbn"> $documents </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns literal documents from input expressions. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/facet/#mongodb-pipeline-pipe.-facet"> <code class="leafygreen-ui-1l06pbn"> $facet </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Processes multiple <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline"> aggregation pipelines </a> within a single stage on the same set of input documents. Enables the creation of multi-faceted aggregations capable of characterizing data across multiple dimensions, or facets, in a single stage. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/fill/#mongodb-pipeline-pipe.-fill"> <code class="leafygreen-ui-1l06pbn"> $fill </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Populates <code class="leafygreen-ui-1l06pbn"> null </code> and missing field values within documents. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear"> <code class="leafygreen-ui-1l06pbn"> $geoNear </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns an ordered stream of documents based on the proximity to a geospatial point. Incorporates the functionality of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/limit/#mongodb-pipeline-pipe.-limit"> <code class="leafygreen-ui-1l06pbn"> $limit </code> </a> for geospatial data. The output documents include an additional distance field and can include a location identifier field. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/graphLookup/#mongodb-pipeline-pipe.-graphLookup"> <code class="leafygreen-ui-1l06pbn"> $graphLookup </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Performs a recursive search on a collection. To each output document, adds a new array field that contains the traversal results of the recursive search for that document. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group"> <code class="leafygreen-ui-1l06pbn"> $group </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Groups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group. Consumes all input documents and outputs one document per each distinct group. The output documents only contain the identifier field and, if specified, accumulated fields. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/indexStats/#mongodb-pipeline-pipe.-indexStats"> <code class="leafygreen-ui-1l06pbn"> $indexStats </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns statistics regarding the use of each index for the collection. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/limit/#mongodb-pipeline-pipe.-limit"> <code class="leafygreen-ui-1l06pbn"> $limit </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Passes the first <em> n </em> documents unmodified to the pipeline where <em> n </em> is the specified limit. For each input document, outputs either one document (for the first <em> n </em> documents) or zero documents (after the first <em> n </em> documents). </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/listSampledQueries/#mongodb-pipeline-pipe.-listSampledQueries"> <code class="leafygreen-ui-1l06pbn"> $listSampledQueries </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Lists sampled queries for all collections or a specific collection. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/listSearchIndexes/#mongodb-pipeline-pipe.-listSearchIndexes"> <code class="leafygreen-ui-1l06pbn"> $listSearchIndexes </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns information about existing <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/atlas-search-overview/#fts-indexes" target="_self"> <span> Atlas Search indexes </span> </a> on a specified collection. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/listSessions/#mongodb-pipeline-pipe.-listSessions"> <code class="leafygreen-ui-1l06pbn"> $listSessions </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Lists all sessions that have been active long enough to propagate to the <code class="leafygreen-ui-1l06pbn"> system.sessions </code> collection. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup"> <code class="leafygreen-ui-1l06pbn"> $lookup </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Performs a left outer join to another collection in the <em> same </em> database to filter in documents from the "joined" collection for processing. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Filters the document stream to allow only matching documents to pass unmodified into the next pipeline stage. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> uses standard MongoDB queries. For each input document, outputs either one document (a match) or zero documents (no match). </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Writes the resulting documents of the aggregation pipeline to a collection. The stage can incorporate (insert new documents, merge documents, replace documents, keep existing documents, fail the operation, process documents with a custom update pipeline) the results into an output collection. To use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge"> <code class="leafygreen-ui-1l06pbn"> $merge </code> </a> stage, it must be the last stage in the pipeline. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out"> <code class="leafygreen-ui-1l06pbn"> $out </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Writes the resulting documents of the aggregation pipeline to a collection. To use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out"> <code class="leafygreen-ui-1l06pbn"> $out </code> </a> stage, it must be the last stage in the pipeline. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/planCacheStats/#mongodb-pipeline-pipe.-planCacheStats"> <code class="leafygreen-ui-1l06pbn"> $planCacheStats </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-query-plans-query-optimization"> plan cache </a> information for a collection. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. </p> <p class="leafygreen-ui-1kp3ins"> See also <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> for removing existing fields. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/querySettings/#mongodb-pipeline-pipe.-querySettings"> <code class="leafygreen-ui-1l06pbn"> $querySettings </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns query settings previously added with <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setQuerySettings/#mongodb-dbcommand-dbcmd.setQuerySettings"> <code class="leafygreen-ui-1l06pbn"> setQuerySettings </code> . </a> </p> <div> <p> <em> New <!-- --> in version <!-- --> 8.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/queryStats/#mongodb-pipeline-pipe.-queryStats"> <code class="leafygreen-ui-1l06pbn"> $queryStats </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns runtime statistics for recorded queries. </p> <p class="leafygreen-ui-1kp3ins"> <strong class="css-4dei7l"> WARNING: </strong> The <code class="leafygreen-ui-1l06pbn"> $queryStats </code> aggregation stage is unsupported and is not guaranteed to be stable in a future release. Don't build functionality that relies on a specific output format of this stage, since the output may change in a future release. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/redact/#mongodb-pipeline-pipe.-redact"> <code class="leafygreen-ui-1l06pbn"> $redact </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Reshapes each document in the stream by restricting the content for each document based on information stored in the documents themselves. Incorporates the functionality of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match"> <code class="leafygreen-ui-1l06pbn"> $match </code> </a> . Can be used to implement field level redaction. For each input document, outputs either one or zero documents. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceRoot/#mongodb-pipeline-pipe.-replaceRoot"> <code class="leafygreen-ui-1l06pbn"> $replaceRoot </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Replaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the <code class="leafygreen-ui-1l06pbn"> _id </code> field. Specify a document embedded in the input document to promote the embedded document to the top level. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith"> <code class="leafygreen-ui-1l06pbn"> $replaceWith </code> </a> is an alias for <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceRoot/#mongodb-pipeline-pipe.-replaceRoot"> <code class="leafygreen-ui-1l06pbn"> $replaceRoot </code> </a> stage. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith"> <code class="leafygreen-ui-1l06pbn"> $replaceWith </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Replaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the <code class="leafygreen-ui-1l06pbn"> _id </code> field. Specify a document embedded in the input document to promote the embedded document to the top level. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith"> <code class="leafygreen-ui-1l06pbn"> $replaceWith </code> </a> is an alias for <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceRoot/#mongodb-pipeline-pipe.-replaceRoot"> <code class="leafygreen-ui-1l06pbn"> $replaceRoot </code> </a> stage. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sample/#mongodb-pipeline-pipe.-sample"> <code class="leafygreen-ui-1l06pbn"> $sample </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Randomly selects the specified number of documents from its input. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/search/#mongodb-pipeline-pipe.-search" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $search </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Performs a full-text search of the field or fields in an <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/query-syntax/" target="_self"> <span> Atlas </span> </a> collection. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $search </code> is only available for MongoDB Atlas clusters, and is not available for self-managed deployments. To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/query-syntax/" target="_self"> <span> Atlas Search Aggregation Pipeline Stages <!-- --> . </span> </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/searchMeta/#mongodb-pipeline-pipe.-searchMeta" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $searchMeta </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Returns different types of metadata result documents for the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self"> <span> Atlas Search </span> </a> query against an <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/query-syntax/" target="_self"> <span> Atlas </span> </a> collection. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $searchMeta </code> is only available for MongoDB Atlas clusters, and is not available for self-managed deployments. To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/query-syntax/" target="_self"> <span> Atlas Search Aggregation Pipeline Stages <!-- --> . </span> </a> </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Adds new fields to documents. Similar to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> reshapes each document in the stream; specifically, by adding new fields to output documents that contain both the existing fields from the input documents and the newly added fields. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> is an alias for <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> stage. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields"> <code class="leafygreen-ui-1l06pbn"> $setWindowFields </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Groups documents into windows and applies one or more operators to the documents in each window. </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.0 </em> . </p> </div> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/skip/#mongodb-pipeline-pipe.-skip"> <code class="leafygreen-ui-1l06pbn"> $skip </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Skips the first <em> n </em> documents where <em> n </em> is the specified skip number and passes the remaining documents unmodified to the pipeline. For each input document, outputs either zero documents (for the first <em> n </em> documents) or one document (if after the first <em> n </em> documents). </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort"> <code class="leafygreen-ui-1l06pbn"> $sort </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sortByCount/#mongodb-pipeline-pipe.-sortByCount"> <code class="leafygreen-ui-1l06pbn"> $sortByCount </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unionWith/#mongodb-pipeline-pipe.-unionWith"> <code class="leafygreen-ui-1l06pbn"> $unionWith </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Removes/excludes fields from documents. </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> is an alias for <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> stage that removes fields. </p> </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unwind/#mongodb-pipeline-pipe.-unwind"> <code class="leafygreen-ui-1l06pbn"> $unwind </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Deconstructs an array field from the input documents to output a document for <em> each </em> element. Each output document replaces the array with an element value. For each input document, outputs <em> n </em> documents where <em> n </em> is the number of array elements and can be zero for an empty array. </div> </div> </td> </tr> <tr class="leafygreen-ui-15dvrnp"> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#mongodb-pipeline-pipe.-vectorSearch" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $vectorSearch </code> </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Performs an <span class="leafygreen-ui-vm4wms" tabindex="0"> ANN </span> or <span class="leafygreen-ui-vm4wms" tabindex="0"> ENN </span> search on a vector in the specified field of an <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/query-syntax/" target="_self"> <span> Atlas </span> </a> collection. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> $vectorSearch </code> is only available for MongoDB Atlas clusters running MongoDB v6.0.11 or higher, and is not available for self-managed deployments. </p> <div> <p> <em> New <!-- --> in version <!-- --> 7.0.2 </em> . </p> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> For aggregation expression operators to use in the pipeline stages, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-pipeline-operators"> Aggregation Operators <!-- --> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> db.aggregate() Stages <a class="headerlink leafygreen-ui-1kepx47" href="#db.aggregate---stages" 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="db.aggregate---stages"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB also provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.aggregate/#mongodb-method-db.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.aggregate() </code> </a> method: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.aggregate( [ { &lt;stage&gt; }, ... ] )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ &lt;<!-- -->stage<!-- -->&gt; <!-- -->}<!-- -->, <!-- -->...<!-- --> ] )</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"> The following stages use the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.aggregate/#mongodb-method-db.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.aggregate() </code> </a> method and not the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate"> <code class="leafygreen-ui-1l06pbn"> db.collection.aggregate() </code> </a> method. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Stage </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/changeStream/#mongodb-pipeline-pipe.-changeStream"> <code class="leafygreen-ui-1l06pbn"> $changeStream </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns a <a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams"> Change Stream </a> cursor for the collection. This stage can only occur once in an aggregation pipeline and it must occur as the first stage. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/currentOp/#mongodb-pipeline-pipe.-currentOp"> <code class="leafygreen-ui-1l06pbn"> $currentOp </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns information on active and/or dormant operations for the MongoDB deployment. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/documents/#mongodb-pipeline-pipe.-documents"> <code class="leafygreen-ui-1l06pbn"> $documents </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Returns literal documents from input values. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/listLocalSessions/#mongodb-pipeline-pipe.-listLocalSessions"> <code class="leafygreen-ui-1l06pbn"> $listLocalSessions </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Lists all active sessions recently in use on the currently connected <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instance. These sessions may have not yet propagated to the <code class="leafygreen-ui-1l06pbn"> system.sessions </code> collection. </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Stages Available for Updates <a class="headerlink leafygreen-ui-1kepx47" href="#stages-available-for-updates" 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="stages-available-for-updates"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> You can use the aggregation pipeline for updates in: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Command </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> <code class="leafygreen-ui-1l06pbn"> mongosh </code> Methods </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/findAndModify/#mongodb-dbcommand-dbcmd.findAndModify"> <code class="leafygreen-ui-1l06pbn"> findAndModify </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#std-label-findOneAndUpdate-agg-pipeline"> db.collection.findOneAndUpdate() </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#std-label-findAndModify-agg-pipeline"> db.collection.findAndModify() </a> </div> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/update/#mongodb-dbcommand-dbcmd.update"> <code class="leafygreen-ui-1l06pbn"> update </code> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#std-label-updateOne-example-agg"> db.collection.updateOne() </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#std-label-updateMany-example-agg"> db.collection.updateMany() </a> </div> </div> <div class="line-block"> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.update/#std-label-example-bulk-find-update-agg"> Bulk.find.update() </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.updateOne/#std-label-example-bulk-find-update-one-agg"> Bulk.find.updateOne() </a> </div> <div class="line"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.upsert/#std-label-bulk-find-upsert-update-agg-example"> Bulk.find.upsert() </a> </div> </div> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> For the updates, the pipeline can consist of the following stages: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields"> <code class="leafygreen-ui-1l06pbn"> $addFields </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set"> <code class="leafygreen-ui-1l06pbn"> $set </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset"> <code class="leafygreen-ui-1l06pbn"> $unset </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceRoot/#mongodb-pipeline-pipe.-replaceRoot"> <code class="leafygreen-ui-1l06pbn"> $replaceRoot </code> </a> and its alias <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith"> <code class="leafygreen-ui-1l06pbn"> $replaceWith </code> . </a> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/sh.splitAt/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> sh.splitAt() <a class="headerlink leafygreen-ui-1kepx47" href="#sh.splitat--" 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="sh.splitat--"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#consideration" target="_self"> <span> Consideration </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> sh.splitAt(namespace, query) </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-sh.splitAt" title="Permalink to this definition"> <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="mongodb-method-sh.splitAt"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Splits a chunk at the shard key value specified by the query. </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> mongosh Method </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This page documents a <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> method. This is <em> not </em> the documentation for database commands or language-specific drivers, such as Node.js. </p> <p class="leafygreen-ui-1kp3ins"> For the database command, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/split/#mongodb-dbcommand-dbcmd.split"> <code class="leafygreen-ui-1l06pbn"> split </code> </a> command <!-- --> . </p> <p class="leafygreen-ui-1kp3ins"> For MongoDB API drivers, refer to the language-specific <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> MongoDB driver documentation <!-- --> . </span> </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> The method takes the following arguments: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Parameter </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> namespace </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> The namespace (i.e. <code class="leafygreen-ui-1l06pbn"> &lt;database&gt;.&lt;collection&gt; </code> ) of the sharded collection that contains the chunk to split. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> query </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> document </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> A query document that specifies the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> value at which to split the chunk. </div> </div> </td> </tr> </tbody> </table> </div> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Consideration <a class="headerlink leafygreen-ui-1kepx47" href="#consideration" 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="consideration"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> In most circumstances, you should leave chunk splitting to the automated processes within MongoDB. However, when initially deploying a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster </a> , it may be beneficial to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-pre-splitting"> pre-split </a> manually an empty collection using methods such as <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.splitAt" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> sh.splitAt() </code> . </span> </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.splitAt" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> sh.splitAt() </code> </span> </a> splits the original chunk into two chunks. One chunk has a shard key range that starts with the original lower bound (inclusive) and ends at the specified shard key value (exclusive). The other chunk has a shard key range that starts with the specified shard key value (inclusive) as the lower bound and ends at the original upper bound (exclusive). </p> <p class="leafygreen-ui-1kp3ins"> To split a chunk at its median point instead, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.splitFind/#mongodb-method-sh.splitFind"> <code class="leafygreen-ui-1l06pbn"> sh.splitFind() </code> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> For the sharded collection <code class="leafygreen-ui-1l06pbn"> test.foo </code> , the following example splits a chunk at the shard key value <code class="leafygreen-ui-1l06pbn"> x: 70 </code> . </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.splitAt( \"test.foo\", { x: 70 } )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">sh.<span class="lg-highlight-title lg-highlight-function">splitAt</span>( <span class="lg-highlight-string">"test.foo"</span>, <!-- -->{ <span class="lg-highlight-attr">x</span>: <span class="lg-highlight-number">70</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> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/sh.removeShardFromZone/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> sh.removeShardFromZone() <a class="headerlink leafygreen-ui-1kepx47" href="#sh.removeshardfromzone--" 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="sh.removeshardfromzone--"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self"> <span> Compatibility </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> sh.removeShardFromZone(shard, zone) </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-sh.removeShardFromZone" title="Permalink to this definition"> <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="mongodb-method-sh.removeShardFromZone"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Removes the association between a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zone"> zone </a> and a shard. </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> mongosh Method </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This page documents a <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> method. This is <em> not </em> the documentation for database commands or language-specific drivers, such as Node.js. </p> <p class="leafygreen-ui-1kp3ins"> For the database command, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/removeShardFromZone/#mongodb-dbcommand-dbcmd.removeShardFromZone"> <code class="leafygreen-ui-1l06pbn"> removeShardFromZone </code> </a> command <!-- --> . </p> <p class="leafygreen-ui-1kp3ins"> For MongoDB API drivers, refer to the language-specific <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> MongoDB driver documentation <!-- --> . </span> </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> This method has the following parameters: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:80%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Parameter </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-method-removeShardFromZone-shard" target="_self"> <span> shard </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-method-removeShardFromZone-shard"> </span> <p class="leafygreen-ui-1kp3ins"> The name of the shard from which to remove the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-method-removeShardFromZone-zone" target="_self"> <span> zone </span> </a> association. </p> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-method-removeShardFromZone-zone" target="_self"> <span> zone </span> </a> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <span class="leafygreen-ui-1qnjd6d" id="std-label-method-removeShardFromZone-zone"> </span> <p class="leafygreen-ui-1kp3ins"> The name of the zone whose association with the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-method-removeShardFromZone-shard" target="_self"> <span> shard </span> </a> you want to remove. </p> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> Only issue <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.removeShardFromZone" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> sh.removeShardFromZone() </code> </span> </a> when connected 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> instance. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Compatibility <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This method is available in deployments hosted 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> </a> : The fully managed service for MongoDB deployments in the cloud </p> </li> </ul> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This command is not supported in serverless instances. For more information, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self"> <span> Unsupported Commands <!-- --> . </span> </a> </p> </div> </div> <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 </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 </a> : The source-available, free-to-use, and self-managed version of MongoDB </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.removeShardFromZone" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> sh.removeShardFromZone() </code> </span> </a> does not remove ranges associated with the zone. </p> <p class="leafygreen-ui-1kp3ins"> To completely remove a zone from the cluster, you must run <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.removeShardFromZone" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> sh.removeShardFromZone() </code> </span> </a> on each shard associated with the zone. </p> <p class="leafygreen-ui-1kp3ins"> If the shard specified is the last shard associated with the zone, you must ensure there are no remaining ranges associated with the zone. Use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange"> <code class="leafygreen-ui-1l06pbn"> updateZoneKeyRange </code> </a> to remove any existing ranges associated to the zone before running <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.removeShardFromZone" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> sh.removeShardFromZone() </code> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> See the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding"> zone </a> manual page for more information on zones in sharded clusters. </p> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Balancer <a class="headerlink leafygreen-ui-1kepx47" href="#balancer" 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"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Removing the association between a zone and a shard removes the constraints keeping chunks covered by the zone on the shard. During the next balancer round, the balancer may migrate chunks that previously covered by the zone. </p> <p class="leafygreen-ui-1kp3ins"> See the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing"> sharded cluster balancer </a> manual page for more information on how migrations work in a sharded cluster. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Security <a class="headerlink leafygreen-ui-1kepx47" href="#security" 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="security"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> For sharded clusters that enforce <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/enable-authentication/"> access control </a> , you must authenticate either as: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> a user whose privileges include: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-update"> <code class="leafygreen-ui-1l06pbn"> update </code> </a> on the <code class="leafygreen-ui-1l06pbn"> shards </code> collection in the <code class="leafygreen-ui-1l06pbn"> config </code> database, and </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find"> <code class="leafygreen-ui-1l06pbn"> find </code> </a> on the <code class="leafygreen-ui-1l06pbn"> tags </code> collection in the <code class="leafygreen-ui-1l06pbn"> config </code> database; </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> or, alternatively, </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> a user whose privileges include <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-enableSharding"> <code class="leafygreen-ui-1l06pbn"> enableSharding </code> </a> on the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-specific-collection"> cluster </a> resource. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterAdmin"> <code class="leafygreen-ui-1l06pbn"> clusterAdmin </code> </a> or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterManager"> <code class="leafygreen-ui-1l06pbn"> clusterManager </code> </a> built-in roles have the appropriate permissions for issuing <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.removeShardFromZone" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> sh.removeShardFromZone() </code> </span> </a> . See the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization"> Role-Based Access Control </a> manual page for more information. </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following example removes the association between <code class="leafygreen-ui-1l06pbn"> shard0000 </code> and the <code class="leafygreen-ui-1l06pbn"> NYC </code> zone: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.removeShardFromZone(\"shard0000\", \"NYC\")","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">sh.<span class="lg-highlight-title lg-highlight-function">removeShardFromZone</span>(<span class="lg-highlight-string">"shard0000"</span>, <span class="lg-highlight-string">"NYC"</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 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/reference/method/sh.addShardToZone/#mongodb-method-sh.addShardToZone"> <code class="leafygreen-ui-1l06pbn"> sh.addShardToZone() </code> </a> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange"> <code class="leafygreen-ui-1l06pbn"> sh.updateZoneKeyRange() </code> </a> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.removeRangeFromZone/#mongodb-method-sh.removeRangeFromZone"> <code class="leafygreen-ui-1l06pbn"> sh.removeRangeFromZone() </code> </a> </p> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/sh.enableAutoMerger/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> sh.enableAutoMerger() <a class="headerlink leafygreen-ui-1kepx47" href="#sh.enableautomerger--" 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="sh.enableautomerger--"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#method-field" target="_self"> <span> Method Field </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> sh.enableAutoMerger(namespace) </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-sh.enableAutoMerger" title="Permalink to this definition"> <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="mongodb-method-sh.enableAutoMerger"> </div> </a> </dt> <dd> </dd> </dl> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Enables automatic <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk"> chunk </a> merges for a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace"> namespace <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> sh.enableAutoMerger() </code> is a <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> helper method. It is effectively the same as running the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/configureCollectionBalancing/#mongodb-dbcommand-dbcmd.configureCollectionBalancing"> <code class="leafygreen-ui-1l06pbn"> configureCollectionBalancing </code> </a> command with the <code class="leafygreen-ui-1l06pbn"> enableAutoMerger </code> field set to <code class="leafygreen-ui-1l06pbn"> true </code> . </p> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> mongosh Method </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> This page documents a <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> method. This is <em> not </em> the documentation for database commands or language-specific drivers, such as Node.js. </p> <p class="leafygreen-ui-1kp3ins"> For the database command, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/configureCollectionBalancing/#mongodb-dbcommand-dbcmd.configureCollectionBalancing"> <code class="leafygreen-ui-1l06pbn"> configureCollectionBalancing </code> </a> command <!-- --> . </p> <p class="leafygreen-ui-1kp3ins"> For MongoDB API drivers, refer to the language-specific <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> MongoDB driver documentation <!-- --> . </span> </a> </p> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.enableAutoMerger( &lt;namespace&gt; )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">sh.<span class="lg-highlight-title lg-highlight-function">enableAutoMerger</span>( &lt;<!-- -->namespace<!-- -->&gt; <!-- -->)</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Method Field <a class="headerlink leafygreen-ui-1kepx47" href="#method-field" 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="method-field"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The method takes the following field: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:10%"/> <col style="width:10%"/> <col style="width:60%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Necessity </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> namespace </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> String </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Required </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Namespace in the format <code class="leafygreen-ui-1l06pbn"> "&lt;database&gt;.&lt;collection&gt;" </code> . Method enables automatic chunk merges for the supplied namespace. </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To set the time intervals for automatic chunk merges, use these parameters: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.autoMergerIntervalSecs"> <code class="leafygreen-ui-1l06pbn"> autoMergerIntervalSecs </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.autoMergerThrottlingMS"> <code class="leafygreen-ui-1l06pbn"> autoMergerThrottlingMS </code> </a> </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following example enables automatic chunk merges for <code class="leafygreen-ui-1l06pbn"> "testDatabase.myCollection" </code> . Run the example from <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.enableAutoMerger( \"testDatabase.myCollection\" )","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">sh.<span class="lg-highlight-title lg-highlight-function">enableAutoMerger</span>( <span class="lg-highlight-string">"testDatabase.myCollection"</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> </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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/automerger-concept/#std-label-automerger-concept"> The AutoMerger </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.disableAutoMerger/#mongodb-method-sh.disableAutoMerger"> <code class="leafygreen-ui-1l06pbn"> sh.disableAutoMerger() </code> </a> method </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.startAutoMerger/#mongodb-method-sh.startAutoMerger"> <code class="leafygreen-ui-1l06pbn"> sh.startAutoMerger() </code> </a> method </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.stopAutoMerger/#mongodb-method-sh.stopAutoMerger"> <code class="leafygreen-ui-1l06pbn"> sh.stopAutoMerger() </code> </a> method </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/reference/command/configureCollectionBalancing/#mongodb-dbcommand-dbcmd.configureCollectionBalancing"> <code class="leafygreen-ui-1l06pbn"> configureCollectionBalancing </code> </a> command </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mergeAllChunksOnShard/#mongodb-dbcommand-dbcmd.mergeAllChunksOnShard"> <code class="leafygreen-ui-1l06pbn"> mergeAllChunksOnShard </code> </a> command </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.autoMergerIntervalSecs"> <code class="leafygreen-ui-1l06pbn"> autoMergerIntervalSecs </code> </a> parameter </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.autoMergerThrottlingMS"> <code class="leafygreen-ui-1l06pbn"> autoMergerThrottlingMS </code> </a> parameter </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/sh.stopAutoMerger/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> sh.stopAutoMerger() <a class="headerlink leafygreen-ui-1kepx47" href="#sh.stopautomerger--" 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="sh.stopautomerger--"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> sh.stopAutoMerger() </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-sh.stopAutoMerger" title="Permalink to this definition"> <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="mongodb-method-sh.stopAutoMerger"> </div> </a> </dt> <dd> </dd> </dl> <div> <p> <em> New <!-- --> in version <!-- --> 7.0 </em> . </p> </div> <p class="leafygreen-ui-1kp3ins"> Disables the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/automerger-concept/#std-label-automerger-concept"> AutoMerger <!-- --> . </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.stopAutoMerger()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">sh.<span class="lg-highlight-title lg-highlight-function">stopAutoMerger</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> When the method runs, it stops the AutoMerger. Any in progress operations issued by the AutoMerger are completed. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The following example disables the AutoMerger. Run the example from <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.stopAutoMerger()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">sh.<span class="lg-highlight-title lg-highlight-function">stopAutoMerger</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> </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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/automerger-concept/#std-label-automerger-concept"> The AutoMerger </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.startAutoMerger/#mongodb-method-sh.startAutoMerger"> <code class="leafygreen-ui-1l06pbn"> sh.startAutoMerger() </code> </a> method </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.enableAutoMerger/#mongodb-method-sh.enableAutoMerger"> <code class="leafygreen-ui-1l06pbn"> sh.enableAutoMerger() </code> </a> method </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.disableAutoMerger/#mongodb-method-sh.disableAutoMerger"> <code class="leafygreen-ui-1l06pbn"> sh.disableAutoMerger() </code> </a> method </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/reference/command/configureCollectionBalancing/#mongodb-dbcommand-dbcmd.configureCollectionBalancing"> <code class="leafygreen-ui-1l06pbn"> configureCollectionBalancing </code> </a> command </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mergeAllChunksOnShard/#mongodb-dbcommand-dbcmd.mergeAllChunksOnShard"> <code class="leafygreen-ui-1l06pbn"> mergeAllChunksOnShard </code> </a> command </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.autoMergerIntervalSecs"> <code class="leafygreen-ui-1l06pbn"> autoMergerIntervalSecs </code> </a> parameter </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.autoMergerThrottlingMS"> <code class="leafygreen-ui-1l06pbn"> autoMergerThrottlingMS </code> </a> parameter </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/core/security-hardening/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Network and Configuration Hardening for Self-Managed Deployments <a class="headerlink leafygreen-ui-1kepx47" href="#network-and-configuration-hardening-for-self-managed-deployments" 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="network-and-configuration-hardening-for-self-managed-deployments"> </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="#mongodb-configuration-hardening" target="_self"> <span> MongoDB Configuration Hardening </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#network-hardening" target="_self"> <span> Network Hardening </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> To reduce the risk exposure of the entire MongoDB system, ensure that only trusted hosts have access to MongoDB. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-http-interface-security"> </span> <span class="leafygreen-ui-1qnjd6d" id="std-label-rest-api"> </span> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> MongoDB Configuration Hardening <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-configuration-hardening" 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="mongodb-configuration-hardening"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> IP Binding <a class="headerlink leafygreen-ui-1kepx47" href="#ip-binding" 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="ip-binding"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> MongoDB binaries, <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> , bind to <code class="leafygreen-ui-1l06pbn"> localhost </code> by default. </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist"> Security Checklist for Self-Managed Deployments </a> . At minimum, consider <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-checklist-auth"> enabling authentication </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-network-config-hardening" target="_self"> <span> hardening network infrastructure <!-- --> . </span> </a> </p> </div> </div> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Make sure that your <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instances are only accessible on trusted networks. If your system has more than one network interface, bind MongoDB programs to the private or internal network interface. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> For more information, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-mongodb-configuration/"> IP Binding in Self-Managed Deployments <!-- --> . </a> </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Network Hardening <a class="headerlink leafygreen-ui-1kepx47" href="#network-hardening" 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="network-hardening"> </div> </a> </h2> <span class="leafygreen-ui-1qnjd6d" id="std-label-security-firewalls"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Firewalls <a class="headerlink leafygreen-ui-1kepx47" href="#firewalls" 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="firewalls"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Firewalls allow administrators to filter and control access to a system by providing granular control over network communications. For administrators of MongoDB, the following capabilities are important: limiting incoming traffic on a specific port to specific systems and limiting incoming traffic from untrusted hosts. </p> <p class="leafygreen-ui-1kp3ins"> On Linux systems, the <code class="leafygreen-ui-1l06pbn"> iptables </code> interface provides access to the underlying <code class="leafygreen-ui-1l06pbn"> netfilter </code> firewall. On Windows systems, <code class="leafygreen-ui-1l06pbn"> netsh </code> command line interface provides access to the underlying Windows Firewall. For additional information about firewall configuration, see: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-linux-iptables-firewall/"> Configure Linux <code class="leafygreen-ui-1l06pbn"> iptables </code> Firewall for Self-Managed Deployments </a> and </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-windows-netsh-firewall/"> Configure Windows <code class="leafygreen-ui-1l06pbn"> netsh </code> Firewall for Self-Managed Deployments <!-- --> . </a> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For best results and to minimize overall exposure, ensure that <em> only </em> traffic from trusted sources can reach <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instances and that the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instances can only connect to trusted outputs. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Virtual Private Networks <a class="headerlink leafygreen-ui-1kepx47" href="#virtual-private-networks" 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="virtual-private-networks"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Virtual private networks, or VPNs, make it possible to link two networks over an encrypted and limited-access trusted network. Typically, MongoDB users who use VPNs use TLS/SSL rather than IPSEC VPNs for performance issues. </p> <p class="leafygreen-ui-1kp3ins"> Depending on configuration and implementation, VPNs provide for certificate validation and a choice of encryption protocols, which requires a rigorous level of authentication and identification of all clients. Furthermore, because VPNs provide a secure tunnel, by using a VPN connection to control access to your MongoDB instance, you can prevent tampering and "man-in-the-middle" attacks. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Disable IP Forwarding <a class="headerlink leafygreen-ui-1kepx47" href="#disable-ip-forwarding" 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="disable-ip-forwarding"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> IP forwarding allows servers to forward packets to other systems. Disable this feature on servers that host <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-program-mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> . </a> </p> <div aria-hidden="true"> </div> <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs"> <div class="leafygreen-ui-jp7pox" id="tabs-10"> <div aria-label="Tabs to describe usage of linux/windows" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist"> <button aria-controls="_rvgbnj8br" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_8w540mbum" name="" role="tab" tabindex="0"> <div class="leafygreen-ui-1nxuzmg"> Linux </div> </button> <button aria-controls="_yb2b110jo" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_zrmert7dw" name="" role="tab" tabindex="-1"> <div class="leafygreen-ui-1nxuzmg"> Windows </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="_2bopnfavi" class="" id="_6ufkltv27" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> To disable IP forwarding on Linux, use the <code class="leafygreen-ui-1l06pbn"> sysctl </code> command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo sysctl -w net.ipv4.ip_forward=0","programmingLanguage":"Bash"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo sysctl -w net.ipv4.ip_forward=0</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 make the change persistent, edit the <code class="leafygreen-ui-1l06pbn"> /etc/sysctl.conf </code> file to add this line: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"net.ipv4.ip_forward = 0"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">net.ipv4.ip_forward = 0</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="_pjtx58wji" class="leafygreen-ui-38lglc" id="_udhym8xlk" role="tabpanel"> <div class="leafygreen-ui-1kdmo88"> <p class="leafygreen-ui-1kp3ins"> IP forwarding is disabled by default on Windows. </p> </div> </div> </div> </div> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/manage-keys/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Rotate and Rewrap Encryption Keys <a class="headerlink leafygreen-ui-1kepx47" href="#rotate-and-rewrap-encryption-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="rotate-and-rewrap-encryption-keys"> </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="#overview" target="_self"> <span> Overview </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#related-information" target="_self"> <span> Related Information </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#procedure" target="_self"> <span> Procedure </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#rotate-your-customer-master-key-on-your-key-management-system" target="_self"> <span> Rotate your Customer Master Key on your Key Management System </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#rotate-your-data-encryption-keys-using-keyvault.rewrapmanydatakey--" target="_self"> <span> Rotate your Data Encryption Keys using <code class="css-1kekw28 e1wawog0"> KeyVault.rewrapManyDataKey() </code> </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> In this guide, you can learn how to manage your encryption keys with a Key Management System ( <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> ) in your application. </p> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Overview <a class="headerlink leafygreen-ui-1kepx47" href="#overview" 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="overview"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> This procedure shows you how to rotate encryption keys for Queryable Encryption using <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> . Rotating DEKs consists of rewrapping them with a new Customer Master Key, so the terms "rotate" and "rewrap" are sometimes used interchangeably. </p> <p class="leafygreen-ui-1kp3ins"> After completing this guide, you should be able to rotate your Customer Master Key ( <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> ) on your Key Management System, and then rewrap existing DEKs in your Key Vault collection with your new <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> . </p> <div class="leafygreen-ui-1sjx7ru" role="note"> <h2 class="leafygreen-ui-29m78u"> Warning </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> As you rotate keys, confirm that they aren't used to encrypt any keys or data before deleting them. If you delete a <span class="leafygreen-ui-vm4wms" tabindex="0"> DEK </span> , all fields encrypted with that <span class="leafygreen-ui-vm4wms" tabindex="0"> DEK </span> become permanently unreadable. If you delete a <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> , all fields encrypted with a <span class="leafygreen-ui-vm4wms" tabindex="0"> DEK </span> using that <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> become permanently unreadable. </p> </div> </div> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Related Information <a class="headerlink leafygreen-ui-1kepx47" href="#related-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="related-information"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> For a detailed explanation of the concepts included in this procedure, refer to the topics below. </p> <p class="leafygreen-ui-1kp3ins"> To learn more about keys and key vaults, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/keys-key-vaults/#std-label-qe-reference-keys-key-vaults"> Encryption Keys and Key Vaults </a> . To view a list of supported <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> providers, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers"> KMS Providers </a> page. </p> <p class="leafygreen-ui-1kp3ins"> For tutorials detailing how to set up a Queryable Encryption enabled application with each of the supported <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> providers, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/overview-enable-qe/#std-label-qe-overview-enable-qe"> Overview: Enable Queryable Encryption <!-- --> . </a> </p> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Procedure <a class="headerlink leafygreen-ui-1kepx47" href="#procedure" 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="procedure"> </div> </a> </h2> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"The process for rotating your CMK (Customer Master Key) depends on your\nKMS (Key Management System) provider. For details, refer to your key provider's\ndocumentation:AWS: Rotating AWS KMS KeysAzure: Configure cryptographic key auto-rotation in Azure Key\nVaultGCP: Rotate a keyOnce you rotate the CMK (Customer Master Key), MongoDB uses it to wrap all new\nDEKs. To re-wrap existing DEKs, continue to the following steps.","name":"Rotate your Customer Master Key on your Key Management System"},{"@type":"HowToStep","text":"The KeyVault.rewrapManyDataKey() method automatically\ndecrypts multiple Data Encryption Keys and re-encrypts them using the\nspecified CMK (Customer Master Key). It then updates the keys in the\nKey Vault collection.The method has the following syntax:Specify a query filter document to select the keys to rotate, or omit the argument to rotate all keys in the Key Vault collectionIf you specify a query filter document, but no keys match, then no keys rotate.Specify the KMS (Key Management System) providerSpecify the masterKey using the new CMK (Customer Master Key),\nor omit the argument to rotate keys using their existing CMK (Customer Master Key)","name":"Rotate your Data Encryption Keys using KeyVault.rewrapManyDataKey()"}],"name":"Procedure","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Rotate your Customer Master Key on your Key Management System <a class="headerlink leafygreen-ui-1kepx47" href="#rotate-your-customer-master-key-on-your-key-management-system" 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="rotate-your-customer-master-key-on-your-key-management-system"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The process for rotating your <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> depends on your <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> provider. For details, refer to your key provider's documentation: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> AWS: <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.aws.amazon.com/kms/latest/developerguide/rotate-keys.html" rel="noopener noreferrer"> <span> Rotating AWS KMS Keys </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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Azure: <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://learn.microsoft.com/en-us/azure/key-vault/keys/how-to-configure-key-rotation" rel="noopener noreferrer"> <span> Configure cryptographic key auto-rotation in Azure Key Vault </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> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> GCP: <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://cloud.google.com/kms/docs/rotate-key" rel="noopener noreferrer"> <span> Rotate a key </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> </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> Once you rotate the <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> , MongoDB uses it to wrap all new DEKs. To re-wrap existing DEKs, continue to the following steps. </p> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Rotate your Data Encryption Keys using <code class="leafygreen-ui-1l06pbn"> KeyVault.rewrapManyDataKey() </code> <a class="headerlink leafygreen-ui-1kepx47" href="#rotate-your-data-encryption-keys-using-keyvault.rewrapmanydatakey--" 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="rotate-your-data-encryption-keys-using-keyvault.rewrapmanydatakey--"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/KeyVault.rewrapManyDataKey/#mongodb-method-KeyVault.rewrapManyDataKey"> <code class="leafygreen-ui-1l06pbn"> KeyVault.rewrapManyDataKey() </code> </a> method automatically decrypts multiple Data Encryption Keys and re-encrypts them using the specified <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> . It then updates the keys in the Key Vault collection. </p> <p class="leafygreen-ui-1kp3ins"> The method has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"let keyVault = db.getMongo().getKeyVault()\n\nkeyVault.rewrapManyDataKey(\n {\n \"&lt;query&gt;\"\n },\n {\n provider: \"&lt;kms&gt;\",\n masterKey: {\n \"&lt;datakeyopts&gt;\" : \"&lt;datakeyopts&gt;\"\n }\n }\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"><span class="lg-highlight-keyword">let</span> keyVault <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">getMongo</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">getKeyVault</span>(<!-- -->)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVault.<span class="lg-highlight-title lg-highlight-function">rewrapManyDataKey</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"&lt;Query filter document&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">provider</span>: <span class="lg-highlight-string">"&lt;KMS provider&gt;"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">masterKey</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"&lt;dataKeyOpts Key&gt;"</span> <!-- -->: <span class="lg-highlight-string">"&lt;dataKeyOpts Value&gt;"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <ol class="leafygreen-ui-rioki0" type="1"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specify a query filter document to select the keys to rotate, or omit the argument to rotate all keys in the Key Vault collection </p> <p class="leafygreen-ui-1kp3ins"> If you specify a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/document/#std-label-document-query-filter"> query filter document </a> , but no keys match, then no keys rotate. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specify the <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> provider </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specify the <code class="leafygreen-ui-1l06pbn"> masterKey </code> using the new <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> , or omit the argument to rotate keys using their existing <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> </p> </li> </ol> </section> </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Your DEKs themselves are left unchanged after re-wrapping them with the new <span class="leafygreen-ui-vm4wms" tabindex="0"> CMK </span> . The key rotation process is seamless, and does not interrupt your application. </p> </section> </section>
https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/manual-encryption/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Explicit Encryption <a class="headerlink leafygreen-ui-1kepx47" href="#explicit-encryption" 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="explicit-encryption"> </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="#overview" target="_self"> <span> Overview </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#use-explicit-encryption" target="_self"> <span> Use Explicit Encryption </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-a-clientencryption-instance" target="_self"> <span> Create a ClientEncryption Instance </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#encrypt-fields-in-read-and-write-operations" target="_self"> <span> Encrypt Fields in Read and Write Operations </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#automatic-decryption" target="_self"> <span> Automatic Decryption </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#server-side-field-level-encryption-enforcement" target="_self"> <span> Server-Side Field Level Encryption Enforcement </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Overview <a class="headerlink leafygreen-ui-1kepx47" href="#overview" 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="overview"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Explicit encryption provides fine-grained control over security, at the cost of increased complexity when configuring collections and writing code for MongoDB Drivers. With explicit encryption, you specify how to encrypt fields in your document for each operation you perform on the database, and you include this logic throughout your application. </p> <p class="leafygreen-ui-1kp3ins"> Explicit encryption is available in the following MongoDB products: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> MongoDB Community Server </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> MongoDB Enterprise Advanced </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> MongoDB Atlas </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Use Explicit Encryption <a class="headerlink leafygreen-ui-1kepx47" href="#use-explicit-encryption" 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="use-explicit-encryption"> </div> </a> </h2> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-fundamentals-manual-encryption-client-enc"> </span> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create a ClientEncryption Instance <a class="headerlink leafygreen-ui-1kepx47" href="#create-a-clientencryption-instance" 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-clientencryption-instance"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> is an abstraction used across drivers and <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> that encapsulates the Key Vault collection and <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> operations involved in explicit encryption. </p> <p class="leafygreen-ui-1kp3ins"> To create a <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> instance, specify: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> kmsProviders </code> object configured with access to the <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> provider hosting your Customer Master Key </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The namespace of your Key Vault collection </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If you use MongoDB Community Server, set the <code class="leafygreen-ui-1l06pbn"> bypassQueryAnalysis </code> option to <code class="leafygreen-ui-1l06pbn"> True </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A <code class="leafygreen-ui-1l06pbn"> MongoClient </code> instance with access to your Key Vault collection </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For more <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> options, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/reference/qe-options-clients/#std-label-qe-reference-mongo-client"> MongoClient Options for Queryable Encryption <!-- --> . </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-fundamentals-manual-encryption-update-operations"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Encrypt Fields in Read and Write Operations <a class="headerlink leafygreen-ui-1kepx47" href="#encrypt-fields-in-read-and-write-operations" 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-fields-in-read-and-write-operations"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> You must update read and write operations throughout your application such that your application encrypts fields before performing read and write operations. </p> <p class="leafygreen-ui-1kp3ins"> To encrypt fields, use the <code class="leafygreen-ui-1l06pbn"> encrypt </code> method of your <code class="leafygreen-ui-1l06pbn"> ClientEncryption </code> instance. Specify the following: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The value to be encrypted </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The algorithm used: <code class="leafygreen-ui-1l06pbn"> Indexed </code> , <code class="leafygreen-ui-1l06pbn"> Unindexed </code> , or <code class="leafygreen-ui-1l06pbn"> Range </code> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The ID of the Data Encryption Key </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query/#std-label-qe-contention"> contention factor </a> (if you are using the <code class="leafygreen-ui-1l06pbn"> Indexed </code> or <code class="leafygreen-ui-1l06pbn"> Range </code> algorithm) </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If you are performing a read operation using the <code class="leafygreen-ui-1l06pbn"> Indexed </code> or <code class="leafygreen-ui-1l06pbn"> Range </code> algorithm, set the query type defined for your field. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> range </code> options <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query/#std-label-qe-field-min-max"> min, max </a> (if you are using the <code class="leafygreen-ui-1l06pbn"> Range </code> algorithm) </p> </li> </ul> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Query Types </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> The query type only applies to read operations. </p> <p class="leafygreen-ui-1kp3ins"> To learn more about query types, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query/#std-label-qe-query-types"> Supported Query Types and Behavior <!-- --> . </a> </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-fundamentals-man-enc-algorithm-choice"> </span> <section> <h4 class="contains-headerlink leafygreen-ui-1vzlt5f"> Algorithm Choice <a class="headerlink leafygreen-ui-1kepx47" href="#algorithm-choice" 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="algorithm-choice"> </div> </a> </h4> <p class="leafygreen-ui-1kp3ins"> Use the <code class="leafygreen-ui-1l06pbn"> Indexed </code> or <code class="leafygreen-ui-1l06pbn"> Range </code> algorithm if you specify a <code class="leafygreen-ui-1l06pbn"> queryType </code> on the field. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> Indexed </code> supports equality queries. <code class="leafygreen-ui-1l06pbn"> Range </code> supports range queries. <code class="leafygreen-ui-1l06pbn"> Indexed </code> and <code class="leafygreen-ui-1l06pbn"> Range </code> fields require an index on the server. The index is created by specifying the <code class="leafygreen-ui-1l06pbn"> encryptedFields </code> option in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.createCollection/#mongodb-method-db.createCollection"> <code class="leafygreen-ui-1l06pbn"> db.createCollection() </code> . </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, the <code class="leafygreen-ui-1l06pbn"> rangePreview </code> Queryable Encryption algorithm is deprecated and removed. Use the <code class="leafygreen-ui-1l06pbn"> Range </code> algorithm instead. </p> <p class="leafygreen-ui-1kp3ins"> If your Queryable Encryption collection uses <code class="leafygreen-ui-1l06pbn"> rangePreview </code> , you must drop the collection before you can upgrade to MongoDB 8.0. </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-fundamentals-manual-encryption-automatic-decryption"> </span> </section> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Automatic Decryption <a class="headerlink leafygreen-ui-1kepx47" href="#automatic-decryption" 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="automatic-decryption"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To decrypt fields automatically, configure your <code class="leafygreen-ui-1l06pbn"> MongoClient </code> instance as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specify a <code class="leafygreen-ui-1l06pbn"> kmsProviders </code> object </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Specify your Key Vault collection </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If you use MongoDB Community Server, set the <code class="leafygreen-ui-1l06pbn"> bypassQueryAnalysis </code> option to <code class="leafygreen-ui-1l06pbn"> True </code> </p> </li> </ul> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <h3 class="leafygreen-ui-144d5kf"> <strong> Automatic Decryption in MongoDB Community Server </strong> </h3> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Automatic decryption is available in MongoDB Community Server. Automatic encryption requires MongoDB Enterprise or MongoDB Atlas. </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-qe-fundamentals-manual-encryption-server-side-schema"> </span> </section> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Server-Side Field Level Encryption Enforcement <a class="headerlink leafygreen-ui-1kepx47" href="#server-side-field-level-encryption-enforcement" 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="server-side-field-level-encryption-enforcement"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/qe-create-encryption-schema/#std-label-qe-specify-fields-for-encryption"> Steps </a> to enforce encryption of specific fields in a collection. </p> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> Indexed </code> and <code class="leafygreen-ui-1l06pbn"> Range </code> fields require an index on the server. The index is created by specifying the <code class="leafygreen-ui-1l06pbn"> encryptedFields </code> option in <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.createCollection/#mongodb-method-db.createCollection"> <code class="leafygreen-ui-1l06pbn"> db.createCollection() </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> If your MongoDB instance enforces the encryption of specific fields, any client performing Queryable Encryption with explicit encryption must encrypt those fields as specified. To learn how to set up server-side Queryable Encryption enforcement, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query/#std-label-qe-fundamentals-encrypt-query"> Encrypted Fields and Enabled Queries <!-- --> . </a> </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> <p class="leafygreen-ui-1kp3ins"> To learn more about Key Vault collections, Data Encryption Keys, and Customer Master Keys, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/keys-key-vaults/#std-label-qe-reference-keys-key-vaults"> Encryption Keys and Key Vaults <!-- --> . </a> </p> <p class="leafygreen-ui-1kp3ins"> To learn more about <span class="leafygreen-ui-vm4wms" tabindex="0"> KMS </span> providers and <code class="leafygreen-ui-1l06pbn"> kmsProviders </code> objects, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers"> KMS Providers <!-- --> . </a> </p> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $or (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-or--aggregation-" 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="-or--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#error-handling" target="_self"> <span> Error Handling </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <dl class="expression"> <dt> <code class="leafygreen-ui-1l06pbn"> $or </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-or" title="Permalink to this definition"> <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="mongodb-expression-exp.-or"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Evaluates one or more expressions and returns <code class="leafygreen-ui-1l06pbn"> true </code> if <em> any </em> of the expressions are <code class="leafygreen-ui-1l06pbn"> true </code> . Otherwise, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-or" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $or </code> </span> </a> returns <code class="leafygreen-ui-1l06pbn"> false </code> . </p> <p class="leafygreen-ui-1kp3ins"> <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-or" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $or </code> </span> </a> has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $or: [ &lt;expression1&gt;, &lt;expression2&gt;, ... ] }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$or</span>: <!-- -->[ &lt;<!-- -->expression1<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->expression2<!-- -->&gt;<!-- -->,<!-- --> <!-- -->...<!-- --> ] }</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"> For more information on expressions, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions"> Expression Operators <!-- --> . </a> </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> In addition to the <code class="leafygreen-ui-1l06pbn"> false </code> boolean value, <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-or" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $or </code> </span> </a> evaluates as <code class="leafygreen-ui-1l06pbn"> false </code> the following: <code class="leafygreen-ui-1l06pbn"> null </code> , <code class="leafygreen-ui-1l06pbn"> 0 </code> , and <code class="leafygreen-ui-1l06pbn"> undefined </code> values. The <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-or" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $or </code> </span> </a> evaluates all other values as <code class="leafygreen-ui-1l06pbn"> true </code> , including non-zero numeric values and arrays. </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:70%"/> <col style="width:30%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Example </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Result </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { $or: [ true, false ] } </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> true </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { $or: [ [ false ], false ] } </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> true </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { $or: [ null, 0, undefined ] } </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> false </code> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> { $or: [ ] } </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> false </code> </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Error Handling <a class="headerlink leafygreen-ui-1kepx47" href="#error-handling" 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="error-handling"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> To allow the query engine to optimize queries, <code class="leafygreen-ui-1l06pbn"> $or </code> handles errors as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> If any expression supplied to <code class="leafygreen-ui-1l06pbn"> $or </code> would cause an error when evaluated alone, the <code class="leafygreen-ui-1l06pbn"> $or </code> containing the expression may cause an error but an error is not guaranteed. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> An expression supplied after the first expression supplied to <code class="leafygreen-ui-1l06pbn"> $or </code> may cause an error even if the first expression evaluates to <code class="leafygreen-ui-1l06pbn"> true </code> . </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For example, the following query <em> always </em> produces an error if <code class="leafygreen-ui-1l06pbn"> $x </code> is <code class="leafygreen-ui-1l06pbn"> 0 </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.example.find( {\n $expr: { $eq: [ { $divide: [ 1, \"$x\" ] }, 3 ] }\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">db.<span class="lg-highlight-property">example</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$expr</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$divide</span>: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"$x"</span> ] }<!-- -->, <span class="lg-highlight-number">3</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> <p class="leafygreen-ui-1kp3ins"> The following query, which contains multiple expressions supplied to <code class="leafygreen-ui-1l06pbn"> $or </code> , <em> may </em> produce an error if there is any document where <code class="leafygreen-ui-1l06pbn"> $x </code> is <code class="leafygreen-ui-1l06pbn"> 0 </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.example.find( {\n $or: [\n { x: { $eq: 0 } },\n { $expr: { $eq: [ { $divide: [ 1, \"$x\" ] }, 3 ] } }\n ]\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">db.<span class="lg-highlight-property">example</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$or</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">x</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <span class="lg-highlight-number">0</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$expr</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$divide</span>: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"$x"</span> ] }<!-- -->, <span class="lg-highlight-number">3</span> ] } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Consider an <code class="leafygreen-ui-1l06pbn"> inventory </code> collection with the following documents: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"abc1\", description: \"product 1\", qty: 300 }\n{ \"_id\" : 2, \"item\" : \"abc2\", description: \"product 2\", qty: 200 }\n{ \"_id\" : 3, \"item\" : \"xyz1\", description: \"product 3\", qty: 250 }\n{ \"_id\" : 4, \"item\" : \"VWZ1\", description: \"product 4\", qty: 300 }\n{ \"_id\" : 5, \"item\" : \"VWZ2\", description: \"product 5\", qty: 180 }","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc1"</span>, <span class="lg-highlight-attr">description</span>: <span class="lg-highlight-string">"product 1"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">300</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc2"</span>, <span class="lg-highlight-attr">description</span>: <span class="lg-highlight-string">"product 2"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">200</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"xyz1"</span>, <span class="lg-highlight-attr">description</span>: <span class="lg-highlight-string">"product 3"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">250</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"VWZ1"</span>, <span class="lg-highlight-attr">description</span>: <span class="lg-highlight-string">"product 4"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">300</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"VWZ2"</span>, <span class="lg-highlight-attr">description</span>: <span class="lg-highlight-string">"product 5"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">180</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> <p class="leafygreen-ui-1kp3ins"> The following operation uses the <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-or" target="_self"> <span> <code class="leafygreen-ui-1l06pbn"> $or </code> </span> </a> operator to determine if <code class="leafygreen-ui-1l06pbn"> qty </code> is greater than 250 <em> or </em> less than <code class="leafygreen-ui-1l06pbn"> 200 </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.aggregate(\n [\n {\n $project:\n {\n item: 1,\n result: { $or: [ { $gt: [ \"$qty\", 250 ] }, { $lt: [ \"$qty\", 200 ] } ] }\n }\n }\n ]\n)","programmingLanguage":"JavaScript"} </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 javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">result</span>: <!-- -->{ <span class="lg-highlight-attr">$or</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <!-- -->[ <span class="lg-highlight-string">"$qty"</span>, <span class="lg-highlight-number">250</span> ] }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">$lt</span>: <!-- -->[ <span class="lg-highlight-string">"$qty"</span>, <span class="lg-highlight-number">200</span> ] } ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"abc1\", \"result\" : true }\n{ \"_id\" : 2, \"item\" : \"abc2\", \"result\" : false }\n{ \"_id\" : 3, \"item\" : \"xyz1\", \"result\" : false }\n{ \"_id\" : 4, \"item\" : \"VWZ1\", \"result\" : true }\n{ \"_id\" : 5, \"item\" : \"VWZ2\", \"result\" : true }","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">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc1"</span>, <span class="lg-highlight-string">"result"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc2"</span>, <span class="lg-highlight-string">"result"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"xyz1"</span>, <span class="lg-highlight-string">"result"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"VWZ1"</span>, <span class="lg-highlight-string">"result"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"VWZ2"</span>, <span class="lg-highlight-string">"result"</span> <!-- -->: <span class="lg-highlight-literal">true</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> </section> </section>
https://www.mongodb.com/docs/manual/reference/method/HexData/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> HexData() <a class="headerlink leafygreen-ui-1kepx47" href="#hexdata--" 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="hexdata--"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self"> <span> Command Fields </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self"> <span> Examples </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Creates a binary data object from hexadecimal data. </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <code class="leafygreen-ui-1l06pbn"> HexData() </code> has the following syntax: </p> <dl class="method"> <dt> <code class="leafygreen-ui-1l06pbn"> HexData( &lt;subType&gt;, &lt;buffer&gt; ) </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-HexData" title="Permalink to this definition"> <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="mongodb-method-HexData"> </div> </a> </dt> <dd> <table class="css-11h39yh e1nex8bq0"> <colgroup> <col class="field-name"/> <col class="field-body"/> </colgroup> <tbody> <tr class="css-x8snli"> <th> Returns <!-- --> : </th> <td> Binary data object. </td> </tr> </tbody> </table> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Command Fields <a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" 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="command-fields"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The command takes these fields: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:20%"/> <col style="width:40%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Field </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Type </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Necessity </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> subType </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> integer </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Required </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Specify a data subtype: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:10%"/> <col style="width:30%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Number </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 0 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Generic binary subtype </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 1 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Function data </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 2 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Binary (old) </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 3 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> UUID (old) </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 4 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> UUID </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 5 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> MD5 </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 6 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Encrypted BSON value </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 7 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> Compressed time series data </p> <div> <p> <em> New <!-- --> in version <!-- --> 5.2 </em> . </p> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 8 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Sensitive data, such as a key or secret. MongoDB does not log literal values for binary data with subtype 8. Instead, MongoDB logs a placeholder value of <code class="leafygreen-ui-1l06pbn"> ### </code> . </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 9 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Vector data, which is densely packed arrays of numbers of the same type. </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> 128 </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Custom data </div> </div> </td> </tr> </tbody> </table> </div> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <code class="leafygreen-ui-1l06pbn"> buffer </code> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> string </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Required </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Hexadecimal data. The string is decoded up to the first character that is not a valid hexadecimal digit. You can use upper or lower case letters in the hexadecimal string. </div> </div> </td> </tr> </tbody> </table> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Examples <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples"> </div> </a> </h2> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Use HexData() to insert a document with binary data created\nfrom a hexadecimal string into a test collection:","name":"Create the example collection"},{"@type":"HowToStep","text":"To return the document, run the following find command:Output shows the hexField value as a base 64 number using\nBinary.createFromBase64():","name":"Retrieve the document"}],"name":"Examples","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"} </script> <div class="css-4nyere eccljxs0"> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 1 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Create the example collection <a class="headerlink leafygreen-ui-1kepx47" href="#create-the-example-collection" 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-the-example-collection"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Use <code class="leafygreen-ui-1l06pbn"> HexData() </code> to insert a document with binary data created from a hexadecimal string into a test collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.hexCollection.insertOne( {\n _id: 0, hexField: HexData( 0, \"123456abcdef\" )\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">db.<span class="lg-highlight-property">hexCollection</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">hexField</span>: <span class="lg-highlight-title lg-highlight-class">HexData</span>( <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"123456abcdef"</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> </section> </div> </div> <div class="css-1nuklj8 e1ckbxcu1"> <div class="css-18fui5z e1ckbxcu0"> <div class="css-19lsqsq e1ckbxcu2"> 2 </div> </div> <div class="css-1ed38mk"> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Retrieve the document <a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-the-document" 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="retrieve-the-document"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> To return the document, run the following <code class="leafygreen-ui-1l06pbn"> find </code> command: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.hexCollection.find()","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">db.<span class="lg-highlight-property">hexCollection</span>.<span class="lg-highlight-title lg-highlight-function">find</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> <p class="leafygreen-ui-1kp3ins"> Output shows the <code class="leafygreen-ui-1l06pbn"> hexField </code> value as a base 64 number using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Binary.createFromBase64/#mongodb-method-Binary.createFromBase64"> <code class="leafygreen-ui-1l06pbn"> Binary.createFromBase64() </code> : </a> </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ { _id: 0, hexField: Binary.createFromBase64('EjRWq83v', 0) } ]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-tyg50d"> <pre class="leafygreen-ui-1agdxuk" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[ <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">hexField</span>: <span class="lg-highlight-title lg-highlight-class">Binary</span>.<span class="lg-highlight-title lg-highlight-function">createFromBase64</span>(<span class="lg-highlight-string">'EjRWq83v'</span>, <span class="lg-highlight-number">0</span>) } ]</td></tr></tbody></table></code></pre> </div> </div> </div> </section> </div> </div> </div> </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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/BinData/#mongodb-method-BinData"> <code class="leafygreen-ui-1l06pbn"> BinData() </code> </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Binary.createFromBase64/#mongodb-method-Binary.createFromBase64"> <code class="leafygreen-ui-1l06pbn"> Binary.createFromBase64() </code> </a> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/core/distributed-queries/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Distributed Queries <a class="headerlink leafygreen-ui-1kepx47" href="#distributed-queries" 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="distributed-queries"> </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="#read-operations-to-replica-sets" target="_self"> <span> Read Operations to Replica Sets </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#write-operations-on-replica-sets" target="_self"> <span> Write Operations on Replica Sets </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#read-operations-to-sharded-clusters" target="_self"> <span> Read Operations to Sharded Clusters </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#write-operations-on-sharded-clusters" target="_self"> <span> Write Operations on Sharded Clusters </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#change-streams-and-orphan-documents" target="_self"> <span> Change Streams and Orphan Documents </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Read Operations to Replica Sets <a class="headerlink leafygreen-ui-1kepx47" href="#read-operations-to-replica-sets" 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="read-operations-to-replica-sets"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> By default, clients reads from a replica set's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary"> primary </a> ; however, clients can specify a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/"> read preference </a> to direct read operations to other members. For example, clients can configure read preferences to read from secondaries or from nearest member to: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> reduce latency in multi-data-center deployments, </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> improve read throughput by distributing high read-volumes (relative to write volume), </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> perform backup operations, and/or </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> allow reads until a <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-high-availability/#std-label-replica-set-failover"> new primary is elected <!-- --> . </a> </p> </li> </ul> <div class="css-q7r6u4 ej97su30"> <div role="button" tabindex="-1"> <img alt="Read operations to a replica set. Default read preference routes the read to the primary. Read preference of ``nearest`` routes the read to the nearest member." class="leafygreen-ui-1qnf57e" height="480" src="/docs/manual/images/replica-set-read-preference.bakedsvg.svg" style="--border-color:#C1C7C6" width="800"/> <div class="css-19pi7x2 ej97su31" style="--color:#444"> click to enlarge </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Read operations from secondary members of replica sets may not reflect the current state of the primary. Read preferences that direct read operations to different servers may result in non-monotonic reads. </p> <p class="leafygreen-ui-1kp3ins"> Clients can use <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-causal-consistency"> causally consistent </a> sessions, which provides various guarantees including monotonic reads. </p> <p class="leafygreen-ui-1kp3ins"> You can configure the read preference on a per-connection or per-operation basis. For more information on read preference or on the read preference modes, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/"> Read Preference </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#std-label-replica-set-read-preference-modes"> Read Preference Modes <!-- --> . </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-write-operations-replica-sets"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Write Operations on Replica Sets <a class="headerlink leafygreen-ui-1kepx47" href="#write-operations-on-replica-sets" 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="write-operations-on-replica-sets"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> In <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set"> replica sets </a> , all write operations go to the set's <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary"> primary </a> . The primary applies the write operation and records the operations on the primary's operation log or <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog"> oplog </a> . The oplog is a reproducible sequence of operations to the data set. <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary"> secondary </a> members of the set continuously replicate the oplog and apply the operations to themselves in an asynchronous process. </p> <div class="css-18h91be ej97su30"> <div role="button" tabindex="-1"> <img alt="Diagram of default routing of reads and writes to the primary." class="leafygreen-ui-1qnf57e" height="507" src="/docs/manual/images/replica-set-read-write-operations-primary.bakedsvg.svg" style="--border-color:#C1C7C6" width="620"/> <div class="css-19pi7x2 ej97su31" style="--color:#444"> click to enlarge </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> For more information on replica sets and write operations, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/"> Replication </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/"> Write Concern <!-- --> . </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-read-operations-sharded-clusters"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Read Operations to Sharded Clusters <a class="headerlink leafygreen-ui-1kepx47" href="#read-operations-to-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="read-operations-to-sharded-clusters"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> Sharded clusters </a> allow you to partition a data set among a cluster of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances in a way that is nearly transparent to the application. For an overview of sharded clusters, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/"> Sharding </a> section of this manual. </p> <p class="leafygreen-ui-1kp3ins"> For a sharded cluster, applications issue operations to one of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> instances associated with the cluster. </p> <div class="css-18h91be ej97su30"> <div role="button" tabindex="-1"> <img alt="Diagram of a sharded cluster." class="leafygreen-ui-1qnf57e" height="560" src="/docs/manual/images/sharded-cluster.bakedsvg.svg" style="--border-color:#C1C7C6" width="700"/> <div class="css-19pi7x2 ej97su31" style="--color:#444"> click to enlarge </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> Read operations on sharded clusters are most efficient when directed to a specific shard. Queries to sharded collections should include the collection's <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key"> shard key </a> . When a query includes a shard key, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> can use cluster metadata from the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-config-servers/#std-label-sharding-config-server"> config database </a> to route the queries to shards. </p> <div class="figure css-5vkxs0" style="width:400px"> <img alt="Read operations to a sharded cluster. Query criteria includes the shard key. The query router ``mongos`` can target the query to the appropriate shard or shards." class="leafygreen-ui-1qnf57e" height="460" src="/docs/manual/images/sharded-cluster-targeted-query.bakedsvg.svg" style="--border-color:#C1C7C6" width="360"/> </div> <p class="leafygreen-ui-1kp3ins"> If a query does not include the shard key, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> must direct the query to <em> all </em> shards in the cluster. These <em> scatter gather </em> queries can be inefficient. On larger clusters, scatter gather queries are unfeasible for routine operations. </p> <div class="figure css-5vkxs0" style="width:400px"> <img alt="Read operations to a sharded cluster. Query criteria does not include the shard key. The query router ``mongos`` must broadcast query to all shards for the collection." class="leafygreen-ui-1qnf57e" height="460" src="/docs/manual/images/sharded-cluster-scatter-gather-query.bakedsvg.svg" style="--border-color:#C1C7C6" width="360"/> </div> <p class="leafygreen-ui-1kp3ins"> For replica set shards, read operations from secondary members of replica sets may not reflect the current state of the primary. Read preferences that direct read operations to different servers may result in non-monotonic reads. </p> <div class="leafygreen-ui-15mdk4" role="note"> <h2 class="leafygreen-ui-6n7b7d"> Note </h2> <div class="leafygreen-ui-9mycqc"> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Clients can use <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-causal-consistency"> causally consistent </a> sessions, which provides various guarantees, including monotonic reads. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> All members of a shard replica set, not just the primary, maintain the metadata regarding chunk metadata. This prevents reads from the secondaries from returning <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-orphaned-document"> orphaned data </a> if not using read concern <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-"> <code class="leafygreen-ui-1l06pbn"> "available" </code> </a> . In earlier versions, reads from secondaries, regardless of the read concern, could return orphaned documents. </p> </li> </ul> </div> </div> <p class="leafygreen-ui-1kp3ins"> For more information on read operations in sharded clusters, see the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/"> mongos </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key"> Shard Keys </a> sections. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-write-operations-sharded-clusters"> </span> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Write Operations on Sharded Clusters <a class="headerlink leafygreen-ui-1kepx47" href="#write-operations-on-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="write-operations-on-sharded-clusters"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> For sharded collections in a <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded cluster </a> , the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> directs write operations from applications to the shards that are responsible for the specific <em> portion </em> of the data set. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos"> <code class="leafygreen-ui-1l06pbn"> mongos </code> </a> uses the cluster metadata from the <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-config-servers/#std-label-sharding-config-server"> config database </a> to route the write operation to the appropriate shards. </p> <div class="css-18h91be ej97su30"> <div role="button" tabindex="-1"> <img alt="Diagram of a sharded cluster." class="leafygreen-ui-1qnf57e" height="560" src="/docs/manual/images/sharded-cluster.bakedsvg.svg" style="--border-color:#C1C7C6" width="700"/> <div class="css-19pi7x2 ej97su31" style="--color:#444"> click to enlarge </div> </div> </div> <p class="leafygreen-ui-1kp3ins"> MongoDB partitions data in a sharded collection into <em> ranges </em> based on the values of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> . Then, MongoDB distributes these chunks to shards. The shard key determines the distribution of chunks to shards. This can affect the performance of write operations in the cluster. </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> <div class="leafygreen-ui-85da11" role="note"> <h2 class="leafygreen-ui-1ac4g5h"> Important </h2> <div class="leafygreen-ui-9mycqc"> <p class="leafygreen-ui-1kp3ins"> Update operations that affect a <em> single </em> document <strong> must </strong> include the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> or the <code class="leafygreen-ui-1l06pbn"> _id </code> field. Updates that affect multiple documents are more efficient in some situations if they have the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> , but can be broadcast to all shards. </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> If the value of the shard key increases or decreases with every insert, all insert operations target a single shard. As a result, the capacity of a single shard becomes the limit for the insert capacity of the sharded cluster. </p> <p class="leafygreen-ui-1kp3ins"> For more information, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/"> Sharding </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/bulk-write-operations/"> Bulk Write Operations <!-- --> . </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/retryable-writes/#std-label-retryable-writes"> Retryable Writes </a> </p> </div> </div> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Change Streams and Orphan Documents <a class="headerlink leafygreen-ui-1kepx47" href="#change-streams-and-orphan-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="change-streams-and-orphan-documents"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Starting in MongoDB 5.3, during <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-range-migration-procedure"> range migration </a> , <a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams"> change stream </a> events are not generated for updates to <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-orphaned-document"> orphaned documents <!-- --> . </a> </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-read-operations-connection-pooling"> </span> </section> </section>
https://www.mongodb.com/docs/manual/core/zone-sharding/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Zones <a class="headerlink leafygreen-ui-1kepx47" href="#zones" 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"> </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="#behavior-and-operations" target="_self"> <span> Behavior and Operations </span> </a> </li> </ul> </div> <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"> Some common deployment patterns where zones can be applied are as follows: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Isolate a specific subset of data on a specific set of shards. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ensure that the most relevant data reside on shards that are geographically closest to the application servers. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Route data to shards based on the hardware / performance of the shard hardware. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> The following image illustrates a sharded cluster with three shards and two zones. The <code class="leafygreen-ui-1l06pbn"> A </code> zone represents a range with a lower boundary of <code class="leafygreen-ui-1l06pbn"> 1 </code> and an upper bound of <code class="leafygreen-ui-1l06pbn"> 10 </code> . The <code class="leafygreen-ui-1l06pbn"> B </code> zone represents a range with a lower boundary of <code class="leafygreen-ui-1l06pbn"> 10 </code> and an upper boundary of <code class="leafygreen-ui-1l06pbn"> 20 </code> . Shards <code class="leafygreen-ui-1l06pbn"> Alpha </code> and <code class="leafygreen-ui-1l06pbn"> Beta </code> have the <code class="leafygreen-ui-1l06pbn"> A </code> zone. Shard <code class="leafygreen-ui-1l06pbn"> Beta </code> also has the <code class="leafygreen-ui-1l06pbn"> B </code> zone. Shard <code class="leafygreen-ui-1l06pbn"> Charlie </code> has no zones associated with it. The cluster is in a steady state and no chunks violate any of the zones. </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior and Operations <a class="headerlink leafygreen-ui-1kepx47" href="#behavior-and-operations" 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="behavior-and-operations"> </div> </a> </h2> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Ranges <a class="headerlink leafygreen-ui-1kepx47" href="#ranges" 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="ranges"> </div> </a> </h3> <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 for a collection. Each range a zone covers is always inclusive of its lower boundary and exclusive of its upper boundary. Zones cannot share ranges, nor can they have overlapping ranges. </p> <p class="leafygreen-ui-1kp3ins"> For example, consider a shard key on <code class="leafygreen-ui-1l06pbn"> {"x": 1} </code> . The cluster has the following zone ranges: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"x\" : 5 } --&gt; { \"x\" : 10 } // Zone A\n{ \"x\" : 10} --&gt; { \"x\" : 20 } // Zone B","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">{ <span class="lg-highlight-string">"x"</span> <!-- -->: <span class="lg-highlight-number">5</span> } <!-- -->-<!-- -->-<!-- -->&gt; <!-- -->{ <span class="lg-highlight-string">"x"</span> <!-- -->: <span class="lg-highlight-number">10</span> } <span class="lg-highlight-comment">// Zone A</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"x"</span> <!-- -->: <span class="lg-highlight-number">10</span>} <!-- -->-<!-- -->-<!-- -->&gt; <!-- -->{ <span class="lg-highlight-string">"x"</span> <!-- -->: <span class="lg-highlight-number">20</span> } <span class="lg-highlight-comment">// Zone B</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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A document with a shard key value of <code class="leafygreen-ui-1l06pbn"> 7 </code> is routed to zone A. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A document with shard key value of <code class="leafygreen-ui-1l06pbn"> 10 </code> is routed to zone B. </p> </li> </ul> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Hashed Shard Keys and Zone Ranges <a class="headerlink leafygreen-ui-1kepx47" href="#hashed-shard-keys-and-zone-ranges" 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-shard-keys-and-zone-ranges"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> For collections whose shard key includes a hashed field, zone ranges and data distribution on that field are on hashed values. The zone contains documents whose <em> hashed </em> shard key value falls into the defined range. A zone range on a hashed field does not have the same predictable document routing behavior as a zone range on an unhashed field. </p> <p class="leafygreen-ui-1kp3ins"> For example, consider a shard key on <code class="leafygreen-ui-1l06pbn"> {"x" : "hashed"} </code> . The following range represents the <em> hashed </em> range between <code class="leafygreen-ui-1l06pbn"> 5 </code> and <code class="leafygreen-ui-1l06pbn"> 10 </code> : </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"x\": NumberLong(\"4470791281878691347\") } --&gt; { \"x\": NumberLong(\"7766103514953448109\") } // Zone A","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1b1bvay"> <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"x"</span>: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"4470791281878691347"</span>) } <!-- -->-<!-- -->-<!-- -->&gt; <!-- -->{ <span class="lg-highlight-string">"x"</span>: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"7766103514953448109"</span>) } <span class="lg-highlight-comment">// Zone A</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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A document with a shard key value of <code class="leafygreen-ui-1l06pbn"> 1 </code> is routed to Zone A since the <em> hashed </em> value of <code class="leafygreen-ui-1l06pbn"> 1 </code> falls into the defined range. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A document with a shard key value of <code class="leafygreen-ui-1l06pbn"> 15 </code> is routed to Zone A since the <em> hashed </em> value of <code class="leafygreen-ui-1l06pbn"> 15 </code> falls into the defined range. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> A document with a shard key value of <code class="leafygreen-ui-1l06pbn"> 8 </code> is not routed to Zone A since the <em> hashed </em> value of <code class="leafygreen-ui-1l06pbn"> 8 </code> does not fall into the defined range. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> <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> provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/convertShardKeyToHashed/#mongodb-method-convertShardKeyToHashed"> <code class="leafygreen-ui-1l06pbn"> convertShardKeyToHashed() </code> </a> for computing the post-hash value of the specified parameter. </p> <p class="leafygreen-ui-1kp3ins"> One valid use of zone ranges on a hashed field is to restrict the data for a collection to the shard or shards in a single zone. Create a zone range that covers the entire range of possible hashed shard key values using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MinKey"> <code class="leafygreen-ui-1l06pbn"> MinKey </code> </a> as the lower bound and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MaxKey"> <code class="leafygreen-ui-1l06pbn"> MaxKey </code> </a> as the upper bound. </p> <p class="leafygreen-ui-1kp3ins"> To define ranges, MongoDB provides the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange"> <code class="leafygreen-ui-1l06pbn"> updateZoneKeyRange </code> </a> command and the associated helper methods <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange"> <code class="leafygreen-ui-1l06pbn"> sh.updateZoneKeyRange() </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardTag/#mongodb-method-sh.addShardTag"> <code class="leafygreen-ui-1l06pbn"> sh.addShardTag() </code> . </a> </p> <p class="leafygreen-ui-1kp3ins"> You can run <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange"> <code class="leafygreen-ui-1l06pbn"> updateZoneKeyRange </code> </a> database command and its helpers <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange"> <code class="leafygreen-ui-1l06pbn"> sh.updateZoneKeyRange() </code> </a> and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addTagRange/#mongodb-method-sh.addTagRange"> <code class="leafygreen-ui-1l06pbn"> sh.addTagRange() </code> </a> on an unsharded collection or a non-existing collection. </p> <p class="leafygreen-ui-1kp3ins"> Dropping a collection deletes its associated zone/tag ranges. </p> <span class="leafygreen-ui-1qnjd6d" id="std-label-zone-sharding-initial-chunk-distribution"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Initial Chunk Distribution <a class="headerlink leafygreen-ui-1kepx47" href="#initial-chunk-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="initial-chunk-distribution"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> By defining the zones and the zone ranges <em> before </em> sharding an empty or a non-existing collection, the shard collection operation creates chunks for the defined zone ranges as well as any additional chunks to cover the entire range of the shard key values and performs an initial chunk distribution based on the zone ranges. This initial creation and distribution of chunks allows for faster setup of zoned sharding. After the initial distribution, the balancer manages the chunk distribution going forward. </p> <p class="leafygreen-ui-1kp3ins"> MongoDB supports sharding collections on <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed"> compound hashed indexes </a> . When sharding an empty or non-existing collection using a compound hashed shard key, additional requirements apply in order for MongoDB to perform initial chunk creation and distribution. </p> <p class="leafygreen-ui-1kp3ins"> See <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-hashed-example"> Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection </a> for for an example. </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/reference/method/sh.balancerCollectionStatus/#mongodb-method-sh.balancerCollectionStatus"> <code class="leafygreen-ui-1l06pbn"> sh.balancerCollectionStatus() </code> </a> </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-zone-sharding-balancer"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Balancer <a class="headerlink leafygreen-ui-1kepx47" href="#balancer" 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"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-balancer"> balancer </a> attempts to evenly distribute a sharded collection's chunks across all shards in the cluster. </p> <p class="leafygreen-ui-1kp3ins"> For each <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk"> chunk </a> marked for migration, the balancer checks each possible destination shard for any configured zones. If the chunk range falls into a zone, the balancer migrates the chunk into a shard inside that zone. Chunks that do not fall into a zone can exist on <em> any </em> shard in the cluster and are migrated normally. </p> <p class="leafygreen-ui-1kp3ins"> During balancing rounds, if the balancer detects that any chunks violate the configured zones for a given shard, the balancer migrates those chunks to a shard where no conflict exists. </p> <p class="leafygreen-ui-1kp3ins"> After associating a zone with a shard or shards and configuring the zone with a shard key range for a sharded collection, the cluster may take some time to migrate the affected data for the sharded collection. This depends on the division of chunks and the current distribution of data in the cluster. When balancing is complete, reads and writes for documents in a given zone are routed only to the shard or shards inside that zone. </p> <p class="leafygreen-ui-1kp3ins"> Once configured, the balancer respects zones during future <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-internals-balancing"> balancing rounds <!-- --> . </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/reference/method/sh.balancerCollectionStatus/#mongodb-method-sh.balancerCollectionStatus"> <code class="leafygreen-ui-1l06pbn"> sh.balancerCollectionStatus() </code> </a> </p> </div> </div> <span class="leafygreen-ui-1qnjd6d" id="std-label-zone-sharding-shard-key"> </span> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Shard Key <a class="headerlink leafygreen-ui-1kepx47" href="#shard-key" 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"> </div> </a> </h3> <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. </p> <p class="leafygreen-ui-1kp3ins"> For example, given a shard key <code class="leafygreen-ui-1l06pbn"> { a : 1, b : 1, c : 1 } </code> , creating or updating a range to cover values of <code class="leafygreen-ui-1l06pbn"> b </code> requires including <code class="leafygreen-ui-1l06pbn"> a </code> as the prefix. Creating or updating a range to covers values of <code class="leafygreen-ui-1l06pbn"> c </code> requires including <code class="leafygreen-ui-1l06pbn"> a </code> and <code class="leafygreen-ui-1l06pbn"> b </code> as the prefix. </p> <p class="leafygreen-ui-1kp3ins"> You cannot create ranges using fields not included in the shard key. For example, if you wanted to use zones to partition data based on geographic location, the shard key would need the first field to contain geographic data. </p> <p class="leafygreen-ui-1kp3ins"> When choosing a shard key for a collection, consider what fields you might want to use for configuring zones. See <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-internals-choose-shard-key"> Choose a Shard Key </a> for considerations in choosing a shard key. </p> </section> <section> <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium"> Shard Zone Boundaries <a class="headerlink leafygreen-ui-1kepx47" href="#shard-zone-boundaries" 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-zone-boundaries"> </div> </a> </h3> <p class="leafygreen-ui-1kp3ins"> Zone ranges are always inclusive of the lower boundary and exclusive of the upper boundary. </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/tutorial/manage-shard-zone/"> Manage Shard Zones </a> </p> </div> </div> </section> </section> </section>
https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> $bitXor (aggregation) <a class="headerlink leafygreen-ui-1kepx47" href="#-bitxor--aggregation-" 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="-bitxor--aggregation-"> </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="#definition" target="_self"> <span> Definition </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self"> <span> Syntax </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self"> <span> Behavior </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self"> <span> Example </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> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Definition <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition"> </div> </a> </h2> <div> <p> <em> New <!-- --> in version <!-- --> 6.3 </em> . </p> </div> <dl class="expression"> <dt> <code class="leafygreen-ui-1l06pbn"> $bitXor </code> <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-bitXor" title="Permalink to this definition"> <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="mongodb-expression-exp.-bitXor"> </div> </a> </dt> <dd> <p class="leafygreen-ui-1kp3ins"> Returns the result of a bitwise <code class="leafygreen-ui-1l06pbn"> xor </code> (exclusive or) operation on an array of <code class="leafygreen-ui-1l06pbn"> int </code> and <code class="leafygreen-ui-1l06pbn"> long </code> values. </p> </dd> </dl> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Syntax <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The <code class="leafygreen-ui-1l06pbn"> $bitXor </code> operator has the following syntax: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $bitXor: [ &lt;expression1&gt;, &lt;expression2&gt;, ... ] }","programmingLanguage":"JavaScript"} </script> <div class="css-16lmvu9"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-yzcs8i"> <pre class="leafygreen-ui-1q4bxgx" 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">{ <span class="lg-highlight-attr">$bitXor</span>: <!-- -->[ &lt;<!-- -->expression1<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->expression2<!-- -->&gt;<!-- -->,<!-- --> <!-- -->...<!-- --> ] }</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> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Behavior <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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="behavior"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> If the operands include both integers and long values, MongoDB sign-extends the calculated integer result and returns a long value. Otherwise, if the operands include only integers or only longs, MongoDB returns results with the corresponding value type. </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"> All numbers in <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> are doubles, not integers. To specify integers in <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> , use the <code class="leafygreen-ui-1l06pbn"> NumberInt() </code> or the <code class="leafygreen-ui-1l06pbn"> NumberLong() </code> constructor. To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-int" target="_self"> <span> Int32 </span> </a> or <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-long" target="_self"> <span> Long <!-- --> . </span> </a> </p> <p class="leafygreen-ui-1kp3ins"> To learn how your MongoDB driver handles numeric values, refer to your <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self"> <span> driver's documentation <!-- --> . </span> </a> </p> </div> </div> <p class="leafygreen-ui-1kp3ins"> If any arguments in the array are of a different data type such as a string, double, or decimal, MongoDB returns an error. </p> <p class="leafygreen-ui-1kp3ins"> If the argument is an empty array, the operation returns <code class="leafygreen-ui-1l06pbn"> NumberInt(0) </code> . </p> <p class="leafygreen-ui-1kp3ins"> If any of the arguments in the array equate to <code class="leafygreen-ui-1l06pbn"> null </code> , the operation returns <code class="leafygreen-ui-1l06pbn"> null </code> . </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Example <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> The example on this page uses the <code class="leafygreen-ui-1l06pbn"> switches </code> collection: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.switches.insertMany( [\n { _id: 0, a: NumberInt(0), b: NumberInt(127) },\n { _id: 1, a: NumberInt(2), b: NumberInt(3) },\n { _id: 2, a: NumberInt(3), b: NumberInt(5) }\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">db.<span class="lg-highlight-property">switches</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">a</span>: <span class="lg-highlight-title lg-highlight-class">NumberInt</span>(<span class="lg-highlight-number">0</span>)<!-- -->, <span class="lg-highlight-attr">b</span>: <span class="lg-highlight-title lg-highlight-class">NumberInt</span>(<span class="lg-highlight-number">127</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">a</span>: <span class="lg-highlight-title lg-highlight-class">NumberInt</span>(<span class="lg-highlight-number">2</span>)<!-- -->, <span class="lg-highlight-attr">b</span>: <span class="lg-highlight-title lg-highlight-class">NumberInt</span>(<span class="lg-highlight-number">3</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">a</span>: <span class="lg-highlight-title lg-highlight-class">NumberInt</span>(<span class="lg-highlight-number">3</span>)<!-- -->, <span class="lg-highlight-attr">b</span>: <span class="lg-highlight-title lg-highlight-class">NumberInt</span>(<span class="lg-highlight-number">5</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> <p class="leafygreen-ui-1kp3ins"> The following aggregation uses the <code class="leafygreen-ui-1l06pbn"> $bitXor </code> operator in the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project"> <code class="leafygreen-ui-1l06pbn"> $project </code> </a> stage: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.switches.aggregate( [\n {\n $project: {\n result: {\n $bitXor: [\"$a\", \"$b\"]\n }\n }\n }\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">db.<span class="lg-highlight-property">switches</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">result</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$bitXor</span>: <!-- -->[<span class="lg-highlight-string">"$a"</span>, <span class="lg-highlight-string">"$b"</span>]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</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> <p class="leafygreen-ui-1kp3ins"> The operation returns the following results: </p> <script class="structured_data" type="application/ld+json"> {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":" [\n { _id: 0, result: 127 },\n { _id: 1, result: 1 },\n { _id: 2, result: 6 }\n ]","programmingLanguage":"JavaScript"} </script> <div class="css-1lju8ps"> <div class="leafygreen-ui-196mwvg"> <div class="leafygreen-ui-1jheeh3"> <pre class="leafygreen-ui-1453az5" 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"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">result</span>: <span class="lg-highlight-number">127</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">result</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">result</span>: <span class="lg-highlight-number">6</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr></tbody></table></code></pre> </div> </div> </div> </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> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-pipeline-operators"> Aggregation Operators </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/bit/#std-label-update-bit"> $bit </a> </p> </li> </ul> </section> </section>
https://www.mongodb.com/docs/manual/security/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Security <a class="headerlink leafygreen-ui-1kepx47" href="#security" 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="security"> </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="#secure-your-mongodb-atlas-deployments" target="_self"> <span> Secure Your MongoDB Atlas Deployments </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#report-suspected-security-bugs" target="_self"> <span> Report Suspected Security Bugs </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> MongoDB provides various features, such as authentication, access control, encryption, to secure your MongoDB deployments. Some key security features include: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:20%"/> <col style="width:20%"/> <col style="width:20%"/> <col style="width:20%"/> <col style="width:20%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Authentication </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Authorization </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> TLS/SSL </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Enterprise Only </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Encryption </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/"> Authentication on Self-Managed Deployments </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-scram/"> SCRAM </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-x.509/"> x.509 </a> </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/"> Role-Based Access Control in Self-Managed Deployments </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/enable-authentication/"> Enable Access Control on Self-Managed Deployments </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-users-and-roles/"> Manage Users and Roles on Self-Managed Deployments </a> </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-transport-encryption/"> TLS/SSL (Transport Encryption) </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/"> Configure <code class="leafygreen-ui-1l06pbn"> mongod </code> and <code class="leafygreen-ui-1l06pbn"> mongos </code> for TLS/SSL </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/"> TLS/SSL Configuration for Clients </a> </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/"> Kerberos Authentication on Self-Managed Deployments </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-ldap/"> Self-Managed LDAP Proxy Authentication </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-oidc/"> Self-Managed OpenID Connect Authentication </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/"> Auditing Self-Managed Deployments </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-log-redaction"> Log Redaction </a> </p> </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/#std-label-qe-manual-feature-qe"> Queryable Encryption </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/#std-label-manual-csfle-feature"> Client-Side Field Level Encryption </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/#std-label-security-encryption-at-rest"> Encryption at Rest </a> </p> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-transport-encryption/#std-label-transport-encryption"> TLS/SSL (Transport Encryption) </a> </p> </div> </div> </td> </tr> </tbody> </table> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Secure Your MongoDB Atlas Deployments <a class="headerlink leafygreen-ui-1kepx47" href="#secure-your-mongodb-atlas-deployments" 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="secure-your-mongodb-atlas-deployments"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB Atlas, the fully managed service for MongoDB deployments in the cloud, comes preconfigured with secure default settings. Atlas also provides the following key security features: </p> <div class="leafygreen-ui-skkc39" tabindex="0"> <table class="leafygreen-ui-hr8lsv"> <colgroup> <col style="width:30%"/> <col style="width:70%"/> </colgroup> <thead class="leafygreen-ui-a9ho40"> <tr data-testid="leafygreen-ui-header-row"> <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Security Feature </div> </div> </th> <th class="leafygreen-ui-13uteka" role="columnheader" scope="col"> <div class="leafygreen-ui-ui0te9"> <div> Description </div> </div> </th> </tr> </thead> <tbody> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Authentication and Authorization </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> In Atlas, you configure database users to access your deployments. Atlas provides various ways to perform user authentication and authorization, including LDAP, OIDC, and X.509. To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/security/config-db-auth/" target="_self"> <span> Configure Authentication and Authorization <!-- --> . </span> </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Encryption </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> By default, Atlas encrypts all data stored in your deployments and uses TLS/SSL to encrypt the connections to your databases. To add another layer of security, you can configure <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/security-kms-encryption/" target="_self"> <span> Encryption at Rest using Customer Key Management <!-- --> . </span> </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> IP Access List </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Atlas allows connections only from addresses specified in the IP access list. To learn how to manage client connections in Atlas, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/security/ip-access-list/" target="_self"> <span> Configure IP Access List Entries <!-- --> . </span> </a> </div> </div> </td> </tr> <tr class=""> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Cloud Provider Support </div> </div> </td> <td class="leafygreen-ui-1drjk7h"> <div class="leafygreen-ui-1n4j8xf"> <div> Atlas supports network peering connections and private endpoints to secure your deployments hosted on AWS, Azure, and Google Cloud. To learn more, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/security-vpc-peering/" target="_self"> <span> Set Up a Network Peering Connection </span> </a> and <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/security-configure-private-endpoints/" target="_self"> <span> Configure Private Endpoints <!-- --> . </span> </a> </div> </div> </td> </tr> </tbody> </table> </div> <p class="leafygreen-ui-1kp3ins"> For a full list of security features in Atlas, see <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/setup-cluster-security/" target="_self"> <span> Security Features for Clusters <!-- --> . </span> </a> </p> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Report Suspected Security Bugs <a class="headerlink leafygreen-ui-1kepx47" href="#report-suspected-security-bugs" 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="report-suspected-security-bugs"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> If you suspect you have <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/company/contact/mongodb-vulnerability-disclosure-policy" target="_self"> <span> identified a security bug </span> </a> on any MongoDB products, please submit the issue using our <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/bug-submission-form" target="_self"> <span> Security Bug Submission Form </span> </a> . </p> </section> </section>
https://www.mongodb.com/docs/manual/core/workload-isolation/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Workload Isolation in MongoDB Deployments <a class="headerlink leafygreen-ui-1kepx47" href="#workload-isolation-in-mongodb-deployments" 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="workload-isolation-in-mongodb-deployments"> </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="#operational-overview" target="_self"> <span> Operational Overview </span> </a> </li> </ul> </div> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Operational Overview <a class="headerlink leafygreen-ui-1kepx47" href="#operational-overview" 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="operational-overview"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> MongoDB includes a number of features that allow database administrators and developers to isolate workload by functional or geographical groupings. </p> <p class="leafygreen-ui-1kp3ins"> This capability provides "data center awareness," which allows applications to target MongoDB deployments with consideration of the physical location of the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances. MongoDB supports segmentation of operations across different dimensions, which may include multiple data centers and geographical regions in multi-data center deployments, racks, networks, or power circuits in single data center deployments. </p> <p class="leafygreen-ui-1kp3ins"> MongoDB also supports workload isolation based on functional or operational parameters, to ensure that certain <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod"> <code class="leafygreen-ui-1l06pbn"> mongod </code> </a> instances are only used for reporting workloads or that certain high-frequency portions of a sharded collection only exist on specific shards. </p> <p class="leafygreen-ui-1kp3ins"> Specifically, with MongoDB, you can: </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> ensure write operations propagate to specific members of a replica set, or to specific members of replica sets. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> ensure that specific members of a replica set respond to queries. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> ensure that specific ranges of your <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> balance onto and reside on specific <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard"> shards <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> combine the above features in a single distributed deployment, on a per-operation (for read and write operations) and collection (for chunk distribution in sharded clusters distribution) basis. </p> </li> </ul> <p class="leafygreen-ui-1kp3ins"> For full documentation of these features, see the following documentation in the MongoDB Manual: </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/read-preference/#std-label-read-preference"> Read Preferences </a> , which controls how drivers help applications target read operations to members of a replica set. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern"> Write Concerns </a> , which controls how MongoDB ensures that write operations propagate to members of a replica set. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-replica-set-tag-sets/#std-label-replica-set-configuration-tag-sets"> Replica Set Tags </a> , which control how applications create and interact with custom groupings of replica set members to create custom application-specific read preferences and write concerns. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding"> Zones </a> in sharded clusters, which allows MongoDB administrators to create <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zone"> zones </a> that represent a group of shards and associate one or more ranges of <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key"> shard key </a> values to these zones. 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 directs reads and writes covered by a zone only to the shards inside the zone. </p> </li> </ul> <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"> Before adding workload isolation features to your application and MongoDB deployment, become familiar with all documentation of <a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/#std-label-replication"> replication </a> , and <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/#std-label-sharding-background"> sharding <!-- --> . </a> </p> </div> </div> </section> </section>
https://www.mongodb.com/docs/manual/administration/production-checklist-development/
<section> <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium"> Development Checklist <a class="headerlink leafygreen-ui-1kepx47" href="#development-checklist" 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="development-checklist"> </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="#data-durability" target="_self"> <span> Data Durability </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#schema-design" target="_self"> <span> Schema Design </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#replication" target="_self"> <span> Replication </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#sharding" target="_self"> <span> Sharding </span> </a> </li> <li class="leafygreen-ui-1jqtqlb"> <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#drivers" target="_self"> <span> Drivers </span> </a> </li> </ul> </div> <p class="leafygreen-ui-1kp3ins"> The following checklist, along with the <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-checklist-operations/"> Operations Checklist for Self-Managed Deployments </a> , provides recommendations to help you avoid issues in your production MongoDB deployment. </p> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Data Durability <a class="headerlink leafygreen-ui-1kepx47" href="#data-durability" 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="data-durability"> </div> </a> </h2> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ensure that your replica set includes at least three data-bearing voting members and that your write operations use <code class="leafygreen-ui-1l06pbn"> w: majority </code> <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/"> write concern </a> . Three data-bearing voting members are required for replica-set wide data durability. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ensure that all instances use <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journaling-internals"> journaling <!-- --> . </a> </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Schema Design <a class="headerlink leafygreen-ui-1kepx47" href="#schema-design" 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="schema-design"> </div> </a> </h2> <p class="leafygreen-ui-1kp3ins"> Data in MongoDB has a <em> dynamic schema </em> . <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-collection"> Collections </a> do not enforce <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-document"> document </a> structure. This facilitates iterative development and polymorphism. Nevertheless, collections often hold documents with highly homogeneous structures. For more information, see <a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/#std-label-manual-data-modeling-intro"> Data Modeling <!-- --> . </a> </p> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Determine the set of collections that you will need and the indexes required to support your queries. With the exception of the <code class="leafygreen-ui-1l06pbn"> _id </code> index, you must create all indexes explicitly: MongoDB does not automatically create any indexes other than <code class="leafygreen-ui-1l06pbn"> _id </code> . </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ensure that your schema design supports your deployment type: if you are planning to use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster"> sharded clusters </a> for horizontal scaling, design your schema to include a strong shard key. While you can <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-change-a-shard-key/#std-label-change-a-shard-key"> change your shard key </a> later, it is important to carefully consider your <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-shard-key-requirements"> shard key choice </a> to avoid scalability and perfomance issues. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ensure that your schema design does not rely on indexed arrays that grow in length without bound. Typically, best performance can be achieved when such indexed arrays have fewer than 1000 elements. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Consider the document size limits when designing your schema. The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#mongodb-limit-BSON-Document-Size"> BSON Document Size </a> limit is 16MB per document. If you require larger documents, use <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/gridfs/#std-label-gridfs"> GridFS <!-- --> . </a> </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Replication <a class="headerlink leafygreen-ui-1kepx47" href="#replication" 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="replication"> </div> </a> </h2> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Use an odd number of voting members to ensure that elections proceed successfully. You can have up to 7 voting members. If you have an <em> even </em> number of voting members, and constraints, such as cost, prohibit adding another secondary to be a voting member, you can add an <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-arbiter"> arbiter </a> to ensure an odd number of votes. For additional considerations when using an arbiter for a 3-member replica set (P-S-A), see <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-arbiter/"> Replica Set Arbiter <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ensure that your secondaries remain up-to-date by using <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/monitoring/#std-label-monitoring-for-mdb"> monitoring tools </a> and by specifying appropriate <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/"> write concern <!-- --> . </a> </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Do not use secondary reads to scale overall read throughput. See: <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://askasya.com/post/canreplicashelpscaling" rel="noopener noreferrer"> <span> Can I use more replica nodes to scale </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> for an overview of read scaling. For information about secondary reads, see: <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/"> Read Preference <!-- --> . </a> </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" 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> </h2> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ensure that your shard key distributes the load evenly on your shards. See: <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/"> Shard Keys </a> for more information. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Use <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-sharding-mongos-targeted"> targeted operations </a> for workloads that need to scale with the number of shards. </p> </li> <li class="leafygreen-ui-d7p7b6"> <div class="line-block"> <div class="line"> Secondaries no longer return orphaned data unless using read concern <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-"> <code class="leafygreen-ui-1l06pbn"> "available" </code> </a> (which is the default read concern for reads against secondaries when not associated with <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions"> causally consistent sessions </a> ). </div> </div> <div class="line-block"> <div class="line"> All members of the shard replica set maintain chunk metadata, allowing them to filter out orphans when not using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-"> <code class="leafygreen-ui-1l06pbn"> "available" </code> </a> . As such, <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-sharding-mongos-broadcast"> non-targeted or broadcast </a> queries that are not using <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-"> <code class="leafygreen-ui-1l06pbn"> "available" </code> </a> can be safely run on any member and will not return orphaned data. </div> </div> <div class="line-block"> <div class="line"> The <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-"> <code class="leafygreen-ui-1l06pbn"> "available" </code> </a> read concern can return <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-orphaned-document"> orphaned documents </a> from secondary members since it does not check for updated chunk metadata. However, if the return of orphaned documents is immaterial to an application, the <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-"> <code class="leafygreen-ui-1l06pbn"> "available" </code> </a> read concern provides the lowest latency reads possible among the various read concerns. </div> </div> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/create-chunks-in-sharded-cluster/"> Pre-split and manually balance chunks </a> when inserting large data sets into a new non-hashed sharded collection. Pre-splitting and manually balancing enables the insert load to be distributed among the shards, increasing performance for the initial load. </p> </li> </ul> </section> <section> <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium"> Drivers <a class="headerlink leafygreen-ui-1kepx47" href="#drivers" 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="drivers"> </div> </a> </h2> <ul class="leafygreen-ui-rioki0"> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Make use of connection pooling. Most MongoDB drivers support connection pooling. Adjust the connection pool size to suit your use case, beginning at 110-115% of the typical number of concurrent database requests. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ensure that your applications handle transient write and read errors during replica set elections. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Ensure that your applications handle failed requests and retry them if applicable. Drivers <strong> do not </strong> automatically retry failed requests. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Use exponential backoff logic for database request retries. </p> </li> <li class="leafygreen-ui-d7p7b6"> <p class="leafygreen-ui-1kp3ins"> Use <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.maxTimeMS/#mongodb-method-cursor.maxTimeMS"> <code class="leafygreen-ui-1l06pbn"> cursor.maxTimeMS() </code> </a> for reads and <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-wtimeout"> <code class="leafygreen-ui-1l06pbn"> wtimeout </code> </a> for writes if you need to cap execution time for database operations. </p> </li> </ul> </section> </section>