{"componentChunkName":"component---src-templates-blog-list-template-js","path":"/engineering/16","result":{"data":{"allMarkdownRemark":{"edges":[{"node":{"excerpt":"E-commerce business is growing day by day as it saves time and cost for people traveling to meet or perform businesses in person. More…","fields":{"slug":"/engineering/electronic-identity-integration/"},"html":"<p>E-commerce business is growing day by day as it saves time and cost for people traveling to meet or perform businesses in person. More people are conducting business online by creating accounts using email or phone verification. This has posed a challenge for everyone to identify the persons who we are claiming online. Online hackers have used false Identity to deceive or defraud someone else. Hence, Electronic Identity ( eID) provides a way for businesses to verify a person's identity online and reduce the chances of Identity Fraud.</p>\n<h2 id=\"what-is-an-electronic-identity\" style=\"position:relative;\"><a href=\"#what-is-an-electronic-identity\" aria-label=\"what is an electronic identity permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is an electronic identity?</h2>\n<p>Electronic identity is an electronic card or device with a unique identity number issued by either a government agency or some banks. A consumer needs to go to the government agency or some banks and show valid identity documents. After the document verification, an Electronic Identity is issued to the consumer. Examples of e-IDs are Danish NemID, Swedish BankID, and Dutch DigiD.</p>\n<p>Most service providers such as financial institutions and insurance firms provide services online and are recognizing an opportunity in implementing eID due to strict Know Your Customer (KYC) and Anti-Money Laundering (AML) requirements.</p>\n<p>eIDs are used to authenticate consumers online across multiple platforms and services. eIDs also allow the consumers to sign documents online, and the companies can trust the signature as the electronic identity is issued by the government or banks based on physical identity documents. This is fast, convenient, and secure for the consumers as they are saved from completing registration forms for multiple services. Hence, this increases the conversion for the businesses. </p>\n<h2 id=\"integrating-eid-authentication-with-loginradius\" style=\"position:relative;\"><a href=\"#integrating-eid-authentication-with-loginradius\" aria-label=\"integrating eid authentication with loginradius permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Integrating eID authentication with LoginRadius</h2>\n<p>LoginRadius supports all the major industry federated SSO methods. Hence, you can integrate eID authentication with LoginRadius using some third application like Criipto, which supports the industry-standard SSO methods. Criipto allows the integration of an eID with the LoginRadius application using JWT SSO Login flow.  Jason Web Token ( JWT) is a signed token that transfers the information from one service to another securely. </p>\n<h3 id=\"prerequisite\" style=\"position:relative;\"><a href=\"#prerequisite\" aria-label=\"prerequisite permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Prerequisite</h3>\n<ul>\n<li>A Criipto account ( you can create a free trial account )</li>\n<li>A LoginRadius application </li>\n<li>One of the desired electronic ID</li>\n</ul>\n<h3 id=\"register-your-loginradius-app-in-your-criipto-account\" style=\"position:relative;\"><a href=\"#register-your-loginradius-app-in-your-criipto-account\" aria-label=\"register your loginradius app in your criipto account permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Register your LoginRadius app in your Criipto account</h3>\n<hr>\n<p>Please see the following steps to register your LoginRadius app in your Criipto account.</p>\n<ol>\n<li>Login in to your <a href=\"https://manage.criipto.id/login\">Criipto account</a>.</li>\n<li>Click + sign to add an application under the Applications tab.</li>\n<li>\n<p>Add the following information:\n<span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 62.46153846153847%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAMABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAIBBf/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/9oADAMBAAIQAxAAAAHt7SJUX//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAQUCX//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8BP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8BP//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEABj8CX//EABkQAAIDAQAAAAAAAAAAAAAAABFhAAEQof/aAAgBAQABPyGrfYX2F4c//9oADAMBAAIAAwAAABDcL//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8QP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8QP//EABkQAQEAAwEAAAAAAAAAAAAAAAEAEWHxcf/aAAgBAQABPxAeth0kdNnReCXRf//Z'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"criipto config\"\n        title=\"criipto config\"\n        src=\"/static/54a2d284bfc4aaada0415d0e698660ef/212bf/criipto-config1.jpg\"\n        srcset=\"/static/54a2d284bfc4aaada0415d0e698660ef/6aca1/criipto-config1.jpg 650w,\n/static/54a2d284bfc4aaada0415d0e698660ef/212bf/criipto-config1.jpg 768w,\n/static/54a2d284bfc4aaada0415d0e698660ef/72e01/criipto-config1.jpg 1024w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<ul>\n<li>Name: Enter a name to identify your app in the Criipto.</li>\n<li>Domain: choose an available domain</li>\n<li>Callback URLs: Enter https://<LR appname>.hub.loginradius.com/access/jwt\n<span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 120.15384615384615%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAYABQDASIAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAAAAECAwX/xAAWAQEBAQAAAAAAAAAAAAAAAAAAAQL/2gAMAwEAAhADEAAAAezNbTRArqXOYP/EABkQAAIDAQAAAAAAAAAAAAAAAAECAAMgIf/aAAgBAQABBQLQTsNasf/EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQMBAT8BH//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EABoQAAICAwAAAAAAAAAAAAAAAAECABEQEiD/2gAIAQEABj8C6vdsWVBn/8QAHBAAAgICAwAAAAAAAAAAAAAAAAEhURARMUFh/9oACAEBAAE/Ie8842rGKZ8bgm2boi2j/9oADAMBAAIAAwAAABAoJ0H/xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAEDAQE/EB//xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAECAQE/EB//xAAaEAEBAAMBAQAAAAAAAAAAAAABEQAQIVFh/9oACAEBAAE/EEB8DYqvW+kdIMQP1w9wmwqyYeebka5//9k='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"criipto config\"\n        title=\"criipto config\"\n        src=\"/static/67d7009ed230b473075629b92f993a4d/212bf/criipto-config2.jpg\"\n        srcset=\"/static/67d7009ed230b473075629b92f993a4d/6aca1/criipto-config2.jpg 650w,\n/static/67d7009ed230b473075629b92f993a4d/212bf/criipto-config2.jpg 768w,\n/static/67d7009ed230b473075629b92f993a4d/dfe5d/criipto-config2.jpg 821w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></li>\n<li>Enable the desired eIDs</li>\n<li>Enable the <strong>Enable OAuth2 Code Flow</strong> under <strong>OpenID Connect</strong></li>\n<li>Click the Re-generate client secret button to generate a client secret. </li>\n<li>Select <strong>SignedJwt</strong> under <strong>User info response strategy</strong> </li>\n<li>Select <strong>compact</strong> under <strong>JWT property format</strong></li>\n<li>Enter the desired token time in <strong>Token lifetime</strong> under <strong>Advanced Options</strong>.</li>\n</ul>\n</li>\n<li>Click the <strong>save</strong> button.</li>\n</ol>\n<h3 id=\"configure-the-criipto-settings-in-the-loginradius\" style=\"position:relative;\"><a href=\"#configure-the-criipto-settings-in-the-loginradius\" aria-label=\"configure the criipto settings in the loginradius permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Configure the Criipto settings in the LoginRadius</h3>\n<ol>\n<li>Login into the <a href=\"https://adminconsole.loginradius.com/\">Admin Console</a></li>\n<li>Navigate to Platform Configuration>Authentication Configuration>Custom IDPs>JWT Provider\n<span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 36.30769230769231%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAHABQDASIAAhEBAxEB/8QAFwABAAMAAAAAAAAAAAAAAAAAAAEDBf/EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhADEAAAAdm0JB//xAAYEAACAwAAAAAAAAAAAAAAAAAAAQIQEf/aAAgBAQABBQLJCr//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/AT//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/AT//xAAWEAADAAAAAAAAAAAAAAAAAAABEEH/2gAIAQEABj8Chf8A/8QAGhABAAEFAAAAAAAAAAAAAAAAAREAECExQf/aAAgBAQABPyEBZQ4BFaZIt//aAAwDAQACAAMAAAAQg8//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/ED//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/ED//xAAaEAEAAgMBAAAAAAAAAAAAAAABACERQVGR/9oACAEBAAE/EGjtjerApUWyqmCf/9k='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"JWT config\"\n        title=\"JWT config\"\n        src=\"/static/651ade97fce5160ea1a000fea842ab05/212bf/LR-JWT-Config1.jpg\"\n        srcset=\"/static/651ade97fce5160ea1a000fea842ab05/6aca1/LR-JWT-Config1.jpg 650w,\n/static/651ade97fce5160ea1a000fea842ab05/212bf/LR-JWT-Config1.jpg 768w,\n/static/651ade97fce5160ea1a000fea842ab05/ba7ed/LR-JWT-Config1.jpg 1311w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></li>\n<li>Click <strong>+ Add A New Provider</strong> button highlighted on the above screen, and the following JWT configuration form fields will appear:\n<span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 158.92307692307693%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAgABQDASIAAhEBAxEB/8QAGAAAAwEBAAAAAAAAAAAAAAAAAAECAwX/xAAVAQEBAAAAAAAAAAAAAAAAAAAAAf/aAAwDAQACEAMQAAAB7ViSiQWd5Ggg/8QAGxABAAICAwAAAAAAAAAAAAAAAQACERIgIjH/2gAIAQEAAQUCB5Lg3IWJbztDM//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQMBAT8BH//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EABkQAAIDAQAAAAAAAAAAAAAAAAABITAyof/aAAgBAQAGPwKXyrCMn//EAB4QAQACAgEFAAAAAAAAAAAAAAEAERAhMUFhgdHh/9oACAEBAAE/IQLQnQ0lksjxghWONRL8S+0r4D3BXZPE/9oADAMBAAIAAwAAABDP7rL/xAAXEQEBAQEAAAAAAAAAAAAAAAABABAR/9oACAEDAQE/EFuzn//EABcRAQEBAQAAAAAAAAAAAAAAAAEAEBH/2gAIAQIBAT8QC5Gf/8QAIBABAAICAQQDAAAAAAAAAAAAAQARITFBEFFhgZGx0f/aAAgBAQABPxBCVaMHu8wA5g0VbVFvmaTiDc8r8RMi77TErdmQP306XVlegfs//9k='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"JWT config\"\n        title=\"JWT config\"\n        src=\"/static/af806f05678e429e41766c806defa146/212bf/LR-JWT-Config2.jpg\"\n        srcset=\"/static/af806f05678e429e41766c806defa146/6aca1/LR-JWT-Config2.jpg 650w,\n/static/af806f05678e429e41766c806defa146/212bf/LR-JWT-Config2.jpg 768w,\n/static/af806f05678e429e41766c806defa146/c293a/LR-JWT-Config2.jpg 1232w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></li>\n<li>\n<p>Complete the following details in the JWT provider</p>\n<ul>\n<li>Enter a unique name under the <strong>Provider Name</strong>. This name will be displayed under the social login forms in the LoginRadius IDX page and on the social login form rendered by LoginRadius V2.js library on your application if the Include In Social Schema is selected while configuring the JWT app.</li>\n<li>Select RS256 under the JWT signing <strong>Algorithm</strong> used by your application ( the selected algorithm is used in encrypting your consumers' information in the JWT).</li>\n<li>Enter the JWT secret or certificate (depending on the chosen algorithm) in the <strong>Key</strong> text box.</li>\n<li>Clock Skew(Optional): Enter 0</li>\n<li>Expiration Time Difference (Optional): Enter 0</li>\n<li>Token Query Parameter Name (Optional): Enter id_token</li>\n<li>\n<p>Data Mapping:</p>\n<ul>\n<li>Select Field(Dropdown): Select the LoginRadius field ID field</li>\n<li>Profile Key: Enter the user identifier field name from the JWT ( please see <a href=\"https://docs.criipto.com/getting-started/token-contents/\">Token contents</a> for the JWT payload returned by an eID)</li>\n</ul>\n</li>\n<li>Enable Include In Social Schema</li>\n</ul>\n</li>\n<li>Click the <strong>Add</strong> button </li>\n</ol>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","frontmatter":{"date":"January 29, 2021","updated_date":null,"description":"An electronic identity is an electronic card or device with a unique identity number issued by either a government agency or some banks.LoginRadius supports all the major industry federated SSO methods. Hence, you can integrate eID authentication with LoginRadius using some third application like Criipto, which supports the industry-standard SSO methods.","title":"Integration with electronic identity (eID) ","tags":["Electronic Identity","Bank ID","Criipto","LoginRadius"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/850aa1fb0d4aa358f92b28928f83052b/1d671/Integration_with_eID.jpg","srcSet":"/static/850aa1fb0d4aa358f92b28928f83052b/f836f/Integration_with_eID.jpg 200w,\n/static/850aa1fb0d4aa358f92b28928f83052b/2244e/Integration_with_eID.jpg 400w,\n/static/850aa1fb0d4aa358f92b28928f83052b/1d671/Integration_with_eID.jpg 680w","sizes":"(max-width: 680px) 100vw, 680px"}}},"author":{"id":"Jitender Agarwal","github":null,"avatar":null}}}},{"node":{"excerpt":"In C#, We have majorly two types of data types Value and Reference type. We can not assign a null value directly to the Value data type. In…","fields":{"slug":"/engineering/nullable-csharp/"},"html":"<p>\nIn C#, We have majorly two types of data types <em>Value</em> and <em>Reference</em> type. We can not assign a null value directly to the Value data type. In this case, C# 2.0 provides us the Nullable types to assign a value data type to null. </p>\n<h2 id=\"what-is-nullable-types\" style=\"position:relative;\"><a href=\"#what-is-nullable-types\" aria-label=\"what is nullable types permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is Nullable types?</h2>\n<p>As described above, The Nullable types used to assign the null value to the value data type. That means we can assign a null value directly to a variable of the value data type. We can declare null value using <code>Nullable&#x3C;T></code> where <code>T</code> is a type like an int, float, bool, etc.</p>\n<p>Nullable types represent the Null value as well the actual range of that data type. Like the <strong>int</strong> data type can hold the value from <code>-2147483648</code> to <code>2147483647</code> but a <strong>Nullable int</strong> can hold the value <code>null</code> and range from <code>-2147483648</code> to <code>2147483647</code></p>\n<h2 id=\"how-to-declare-nullable-types\" style=\"position:relative;\"><a href=\"#how-to-declare-nullable-types\" aria-label=\"how to declare nullable types permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How to declare Nullable types</h2>\n<p>There are two ways to declare Nullable types.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk10\">Nullable</span><span class=\"mtk1\">&lt;</span><span class=\"mtk4\">int</span><span class=\"mtk1\">&gt; </span><span class=\"mtk12\">example</span><span class=\"mtk1\">;</span></span></code></pre>\n<p>OR</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">int</span><span class=\"mtk1\">? </span><span class=\"mtk12\">Example</span><span class=\"mtk1\">;</span></span></code></pre>\n<h2 id=\"properties-of-nullable-types\" style=\"position:relative;\"><a href=\"#properties-of-nullable-types\" aria-label=\"properties of nullable types permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Properties of Nullable types</h2>\n<p>Nullable types have two properties.</p>\n<ol>\n<li>HasValue</li>\n<li>Value</li>\n</ol>\n<p><strong>HasValue</strong>: This property returns a bool value based on that if the Nullable variable has some value or not. If the variable has some value, then it will return true; otherwise, it will return false if it doesn’t have value or it’s null.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk10\">Nullable</span><span class=\"mtk1\">&lt;</span><span class=\"mtk4\">int</span><span class=\"mtk1\">&gt; </span><span class=\"mtk12\">a</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">null</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">Console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">WriteLine</span><span class=\"mtk1\">(</span><span class=\"mtk12\">a</span><span class=\"mtk1\">.</span><span class=\"mtk12\">HasValue</span><span class=\"mtk1\">); </span><span class=\"mtk3\">// Print False</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">Nullable</span><span class=\"mtk1\">&lt;</span><span class=\"mtk4\">int</span><span class=\"mtk1\">&gt; </span><span class=\"mtk12\">b</span><span class=\"mtk1\"> = </span><span class=\"mtk7\">9</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">Console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">WriteLine</span><span class=\"mtk1\">(</span><span class=\"mtk12\">b</span><span class=\"mtk1\">.</span><span class=\"mtk12\">HasValue</span><span class=\"mtk1\">); </span><span class=\"mtk3\">// Print True</span></span></code></pre>\n<p><strong>Value</strong>: This property gives the value of the Nullable type variable. If the variable has some value, it will return the value; else, it will give the runtime <code>InvalidOperationException</code> <a href=\"https://www.loginradius.com/blog/engineering/exception-handling-in-csharp/\">exception when the variable</a> value is null.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk10\">Nullable</span><span class=\"mtk1\">&lt;</span><span class=\"mtk4\">int</span><span class=\"mtk1\">&gt; </span><span class=\"mtk12\">a</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">null</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">Console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">WriteLine</span><span class=\"mtk1\">(</span><span class=\"mtk12\">a</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Value</span><span class=\"mtk1\">); </span><span class=\"mtk3\">// Gives run time exception of type &#39;InvalidOperationException&#39;</span></span></code></pre>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk10\">Nullable</span><span class=\"mtk1\">&lt;</span><span class=\"mtk4\">int</span><span class=\"mtk1\">&gt; </span><span class=\"mtk12\">b</span><span class=\"mtk1\"> = </span><span class=\"mtk7\">9</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">Console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">WriteLine</span><span class=\"mtk1\">(</span><span class=\"mtk12\">b</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Value</span><span class=\"mtk1\">); </span><span class=\"mtk3\">// Print 9</span></span></code></pre>\n<h2 id=\"method-of-nullable-types\" style=\"position:relative;\"><a href=\"#method-of-nullable-types\" aria-label=\"method of nullable types permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Method of Nullable types</h2>\n<p><strong>GetValueOrDefault()</strong>: This method returns the actually assigned value of the Nullable type variable if the value is not null, and if the variable value is null, then it will give the default value of that data type. Here is the example code</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk10\">Nullable</span><span class=\"mtk1\">&lt;</span><span class=\"mtk4\">int</span><span class=\"mtk1\">&gt; </span><span class=\"mtk12\">a</span><span class=\"mtk1\"> = </span><span class=\"mtk7\">9</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">Console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">WriteLine</span><span class=\"mtk1\">(</span><span class=\"mtk12\">a</span><span class=\"mtk1\">.</span><span class=\"mtk11\">GetValueOrDefault</span><span class=\"mtk1\">()); </span><span class=\"mtk3\">// Returns 9</span></span></code></pre>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk10\">Nullable</span><span class=\"mtk1\">&lt;</span><span class=\"mtk4\">int</span><span class=\"mtk1\">&gt; </span><span class=\"mtk12\">a</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">null</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">Console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">WriteLine</span><span class=\"mtk1\">(</span><span class=\"mtk12\">a</span><span class=\"mtk1\">.</span><span class=\"mtk11\">GetValueOrDefault</span><span class=\"mtk1\">()); </span><span class=\"mtk3\">// Returns 0</span></span></code></pre>\n<h2 id=\"rules-of-using-nullable-types\" style=\"position:relative;\"><a href=\"#rules-of-using-nullable-types\" aria-label=\"rules of using nullable types permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Rules of using Nullable types:</h2>\n<p>To use the Nullable type as a local variable, it should be declared first; it will give a compile-time error. This rule is similar to the value data type.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">int</span><span class=\"mtk1\">? </span><span class=\"mtk12\">b</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">Console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">WriteLine</span><span class=\"mtk1\">(</span><span class=\"mtk12\">b</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Value</span><span class=\"mtk1\">); </span><span class=\"mtk3\">//Compile time error &#39;use of unassigned local variable b&#39;</span></span></code></pre>\n<p>If the Nullable variable is a property in a class and after that, if we are accessing that Nullable variable, then it will not give any error because, in the class variable, it is declared as <code>null</code> automatically.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">class</span><span class=\"mtk1\"> </span><span class=\"mtk10\">Test</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">     </span><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk4\">int</span><span class=\"mtk1\">? </span><span class=\"mtk12\">B</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">class</span><span class=\"mtk1\"> </span><span class=\"mtk10\">Program</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">static</span><span class=\"mtk1\"> </span><span class=\"mtk4\">void</span><span class=\"mtk1\"> </span><span class=\"mtk11\">Main</span><span class=\"mtk1\">(</span><span class=\"mtk4\">string</span><span class=\"mtk1\">[] </span><span class=\"mtk12\">args</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">Console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">WriteLine</span><span class=\"mtk1\">(</span><span class=\"mtk4\">new</span><span class=\"mtk1\"> </span><span class=\"mtk10\">Test</span><span class=\"mtk1\">().</span><span class=\"mtk12\">B</span><span class=\"mtk1\">); </span><span class=\"mtk3\">// No compile time error</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<h2 id=\"null-coalescing-operator-\" style=\"position:relative;\"><a href=\"#null-coalescing-operator-\" aria-label=\"null coalescing operator  permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>null coalescing operator (??)</h2>\n<p>We can not assign the Nullable type variable value to the non-nullable type variable directly. As in the example below, if we try to assign the value, it will give the compile-time error.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">int</span><span class=\"mtk1\">? </span><span class=\"mtk12\">a</span><span class=\"mtk1\"> = </span><span class=\"mtk7\">10</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">int</span><span class=\"mtk1\"> </span><span class=\"mtk12\">b</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">a</span><span class=\"mtk1\">;</span><span class=\"mtk3\">//Compile time error `Cannot implicitly convert type &#39;int?&#39; to &#39;int&#39;. An explicit conversion exists (are you missing a cast?)`</span></span></code></pre>\n<p><strong>Note</strong>: We can use compare operators <code>==</code> and <code>!=</code> operator with Nullable type variables and non Nullable type variables.</p>\n<p>For the Nullable variable, we can use the null coalescing operator (??) to check if the variable value is <code>null</code> or not. Then we can assign the non-nullable type variable value according to that. This operator can be used when we are unsure that at run time if that Nullable variable's value is changed according to our logic or not. Here is an example of that</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"10\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">int</span><span class=\"mtk1\">? </span><span class=\"mtk12\">a</span><span class=\"mtk1\">=</span><span class=\"mtk4\">null</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">int</span><span class=\"mtk1\"> </span><span class=\"mtk12\">b</span><span class=\"mtk1\">=</span><span class=\"mtk12\">a</span><span class=\"mtk1\">?? </span><span class=\"mtk7\">10</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">Console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">WriteLine</span><span class=\"mtk1\">(</span><span class=\"mtk12\">b</span><span class=\"mtk1\">);  </span><span class=\"mtk3\">// Prints 10</span></span></code></pre>\n<p>In the above example, if the variable a value is null,, it will assign the value 10 to b variable. In that case, b is assigned with value 10, and the printed value will be 10.</p>\n<h2 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h2>\n<p>In this article, We have discussed the Nullable types, and it's properties and methods. The main advantage of using the Nullable types is that we can store the Null value in a column of a database using this type. If you want to learn more about C# here is an article written by me on <a href=\"https://www.loginradius.com/blog/engineering/enum-csharp/\">How to Use Enum in C#</a></p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk10 { color: #4EC9B0; }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk3 { color: #6A9955; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n</style>","frontmatter":{"date":"January 29, 2021","updated_date":null,"description":"Nullable is a term in C# that allows an extra value null to be owned by a form. We will learn in this article how to work with Nullable types in C#.","title":"How to Work with Nullable Types in C#","tags":["C#","Nullable"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/683771faa7dbd78039f0a89ea94ad469/14b42/coverimage.jpg","srcSet":"/static/683771faa7dbd78039f0a89ea94ad469/f836f/coverimage.jpg 200w,\n/static/683771faa7dbd78039f0a89ea94ad469/2244e/coverimage.jpg 400w,\n/static/683771faa7dbd78039f0a89ea94ad469/14b42/coverimage.jpg 800w,\n/static/683771faa7dbd78039f0a89ea94ad469/9842e/coverimage.jpg 900w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Hemant Manwani","github":"hemant404","avatar":null}}}},{"node":{"excerpt":"Many of us have to choose between Merge and Rebase as a Developer. Here I'll explain what merge and rebase are, why you should use them, and…","fields":{"slug":"/engineering/git-rebase-vs-git-merge/"},"html":"<p>Many of us have to choose between Merge and Rebase as a Developer. Here I'll explain what merge and rebase are, why you should use them, and how to do so.</p>\n<p>The same function is fulfilled by Git Merge and Git Rebase. They are built to incorporate adjustments into one from different divisions. Although the end objective is the same, it is done in various ways by those two approaches, and it is useful to know the difference as you become a better developer of software.</p>\n<h2 id=\"what-are-git-merge-and-git-rebase\" style=\"position:relative;\"><a href=\"#what-are-git-merge-and-git-rebase\" aria-label=\"what are git merge and git rebase permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What are Git Merge and Git Rebase?</h2>\n<p><em>Git Merge and Git Rebase are both used to combine the changes of branches but in a distinct way.</em></p>\n<p><strong>Git Merge</strong> - For developers using version control systems, merging is a prevalent method. Merging takes the contents of a source branch and combines them with a target branch, to be more precise. Only the <a href=\"https://medium.com/@loginradius/how-to-fetch-a-remote-branch-using-git-5c0f6d28264d\">target branch is updated</a> in this process. The history of the source branch remains similar.</p>\n<p><strong>Git Rebase</strong> - Another way to integrate modifications from one branch to another is by Rebase. Rebase compresses all the modifications into a single patch. The patch is then inserted into the target branch.</p>\n<h3 id=\"git-merge\" style=\"position:relative;\"><a href=\"#git-merge\" aria-label=\"git merge permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Git Merge</h3>\n<p>Combine multiple branch histories together.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">  A---B---C feature</span>\n<span class=\"grvsc-line\"> /</span>\n<span class=\"grvsc-line\">D---E---F---G master </span></code></pre>\n<p>if we are merging feature and master branch, then it would be</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">  A---B---C feature</span>\n<span class=\"grvsc-line\"> /               \\</span>\n<span class=\"grvsc-line\">D---E---F---G---H master</span></code></pre>\n<p><strong>Commands</strong> for merging feature and master branch</p>\n<p><code>git checkout feature</code>\n<code>git merge master</code></p>\n<p><strong>Note:</strong></p>\n<ul>\n<li>merge executes only one new commit</li>\n<li>if the feature branch has a completely different development </li>\n<li>If you get conflict while merging\n<code>resolve conflicts</code>\n<code>git add (changes)</code>\n<code>git merge --continue</code></li>\n</ul>\n<h3 id=\"git-rebase\" style=\"position:relative;\"><a href=\"#git-rebase\" aria-label=\"git rebase permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Git Rebase</h3>\n<p>Reapply commits on top of the base branch</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">   A---B---C feature</span>\n<span class=\"grvsc-line\"> /</span>\n<span class=\"grvsc-line\">D---E---F---G master</span></code></pre>\n<p>if we are rebasing the feature branch onto the master branch, then it would be</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">\t   A&#39;--B&#39;--C&#39; feature</span>\n<span class=\"grvsc-line\">\t /</span>\n<span class=\"grvsc-line\">\tD---E---F---G master</span></code></pre>\n<p><strong>Commands</strong> for merging feature and master branch</p>\n<p><code>git checkout feature</code>\n<code>git rebase master</code></p>\n<p><strong>Note:</strong> </p>\n<ul>\n<li>rebase typically executes multiple (number of commits in current branch).</li>\n<li>If you get conflict while rebasing\n<code>resolve conflicts</code>\n<code>git add (changes)</code>\n<code>git rebase --continue</code></li>\n</ul>\n<h2 id=\"when-to-use-git-rebase-or-git-merge\" style=\"position:relative;\"><a href=\"#when-to-use-git-rebase-or-git-merge\" aria-label=\"when to use git rebase or git merge permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>When to use Git Rebase or Git Merge</h2>\n<h3 id=\"choose-merge\" style=\"position:relative;\"><a href=\"#choose-merge\" aria-label=\"choose merge permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Choose Merge</h3>\n<ul>\n<li>whenever we want to add changes of a feature branch back into the base branch.</li>\n<li>if you want to keep the same history rather than rewrite it.</li>\n<li>if you want to revert the changes quickly</li>\n</ul>\n<h3 id=\"choose-rebase\" style=\"position:relative;\"><a href=\"#choose-rebase\" aria-label=\"choose rebase permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Choose Rebase</h3>\n<ul>\n<li>whenever we want to add changes of a base branch back to a feature branch.</li>\n<li>squash multiple commits</li>\n<li>reiterate each commit and update the changes</li>\n<li>reverting rebase would be very difficult</li>\n</ul>\n<h3 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h3>\n<p>I hope some perspectives on Git merge and Git rebase have been provided by this description. The strategy of merge vs rebase is still debatable. But maybe this article will help to dispel your doubts and encourage you to take an approach that works for your team. Here are few articles posted by me that will help you in learning few more things in Git:</p>\n<ol>\n<li><a href=\"https://www.loginradius.com/blog/engineering/git-cherry-pick/\">How to use Git Cherry Pick</a></li>\n<li><a href=\"https://www.loginradius.com/blog/engineering/git-pull-force/\">How to Perform a Git Force Pull</a></li>\n</ol>\n<p>Do comment on the subjects that you would like me to write about in the coming weeks :)</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n</style>","frontmatter":{"date":"January 27, 2021","updated_date":null,"description":"In this post, I will give you a walkthrough on merge and rebase, comparing Git rebase vs. Git merge to find out the similarities and differences.","title":"Git merge vs. Git Rebase: What's the difference?","tags":["GIT"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/84d7585291c78a887f774814c64479d6/ee604/merge.png","srcSet":"/static/84d7585291c78a887f774814c64479d6/69585/merge.png 200w,\n/static/84d7585291c78a887f774814c64479d6/497c6/merge.png 400w,\n/static/84d7585291c78a887f774814c64479d6/ee604/merge.png 800w,\n/static/84d7585291c78a887f774814c64479d6/f3583/merge.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Abhimanyu Singh Rathore","github":"abhir9","avatar":null}}}},{"node":{"excerpt":"An infrastructure layer that allows you to manage communication between the microservices of your application is a service mesh. As more…","fields":{"slug":"/engineering/istio-installation-and-service-configuration/"},"html":"<p>An infrastructure layer that allows you to manage communication between the microservices of your application is a service mesh. As more developers work with microservices, by consolidating common management and administrative tasks in a distributed setup, service meshes have developed to make the job easier and more effective.</p>\n<p>To know more about Istio, you can read this article on <a href=\"https://www.loginradius.com/blog/engineering/istio-service-mesh\">Istio service mesh</a> to understand the basic terminology, In this tutorial, will explain how to install and configure Istio. Let's get started.</p>\n<h2 id=\"installing-istio\" style=\"position:relative;\"><a href=\"#installing-istio\" aria-label=\"installing istio permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Installing Istio</h2>\n<p>Get the latest Istio release:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">curl -L https://istio.io/downloadIstio | sh -</span></code></pre>\n<p>Extract the archive and export the bin directory in the environment path.</p>\n<p>This will also install istioctl, a command-line tool to manage Istio service mesh.</p>\n<h3 id=\"configuration-profiles\" style=\"position:relative;\"><a href=\"#configuration-profiles\" aria-label=\"configuration profiles permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Configuration Profiles</h3>\n<p>Istio provides various built-in configuration profiles, a set of pre-defined configs related to data and control plane. We can customize the configs according to our needs.</p>\n<p>For testing locally or trying it ou, you can use a demo profile. For dev and other environments, we will be using the default configuration profile.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">istioctl install --set profile=demo</span></code></pre>\n<h3 id=\"customizing-configs\" style=\"position:relative;\"><a href=\"#customizing-configs\" aria-label=\"customizing configs permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Customizing configs</h3>\n<p>Run:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">istioctl profile dump default</span></code></pre>\n<p>to see the various configurations. We can change those flag using istioctl commands and --set flag.</p>\n<p>For development purpose, we can enabled/changes following flags:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">istioctl install --set addonComponents.kiali.enabled=true \\ </span>\n<span class=\"grvsc-line\">--set components.telemetry.enabled=true \\ </span>\n<span class=\"grvsc-line\">--set components.citadel.enabled=true \\ </span>\n<span class=\"grvsc-line\">--set values.global.proxy.privileged=true \\ </span>\n<span class=\"grvsc-line\">--set addonComponents.tracing.enabled=true \\ </span>\n<span class=\"grvsc-line\">--set values.pilot.traceSampling=100.0 \\ </span>\n<span class=\"grvsc-line\">--set values.global.proxy.tracer=datadog</span></code></pre>\n<p>The path value of <code>--set</code> flag is the YAML path, which you can see in the profile dump command.</p>\n<blockquote>\n<p>While changing any config, make sure to pass all the previous flags with the new ones. For example, if first time, you enabled istioctl install --set addonComponents.kiali.enabled=true and now let’s say, you want to enable citadel, then you have to pass both flags like this: istioctl install --set addonComponents.kiali.enabled=true --set components.telemetry.enabled=true.\nFailing to add any previously enabled variable will revert the config to its default values.\nOne way to store the dump in a file and do istioctl apply or use helm charts for Istio.</p>\n</blockquote>\n<h3 id=\"sidecar-injection\" style=\"position:relative;\"><a href=\"#sidecar-injection\" aria-label=\"sidecar injection permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Sidecar injection</h3>\n<p>For Istio to work properly, a sidecar Envoy proxy needs to be enabled for the services. By default, the Istio control plane will not enable any sidecar to any services. To enable sidecar, we have to add labels at the namespace level.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl label namespace dsl-test istio-injection=enabled</span></code></pre>\n<p>You need to have this label even if you do not want to add a sidecar to all your services.</p>\n<p>You need to restart the pods.</p>\n<p>For services, which do not require sidecar, we need to add the following annotation in the deployment template:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"># Pod Annotations </span>\n<span class=\"grvsc-line\">podAnnotations: </span>\n<span class=\"grvsc-line\">\tsidecar.istio.io/inject: &quot;false&quot;</span></code></pre>\n<h2 id=\"configuring-services\" style=\"position:relative;\"><a href=\"#configuring-services\" aria-label=\"configuring services permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Configuring Services</h2>\n<p>For demonstration, we will take two demo services demo-1 and demo-2, and configure both services with Istio, and will try to call demo-2 service from demo-1. Make sure there is an env variable in demo-1, which we will configure with demo-2 internal DNS url. The programming language for the two services does not matter here.</p>\n<p>A service configuration requires a VirtualService, DestinationRule, PeerAuthentication, and optionally a Gateway configuration.</p>\n<h3 id=\"gateway\" style=\"position:relative;\"><a href=\"#gateway\" aria-label=\"gateway permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Gateway</h3>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">apiVersion: networking.istio.io/v1alpha3 </span>\n<span class=\"grvsc-line\">kind: Gateway </span>\n<span class=\"grvsc-line\">metadata: </span>\n<span class=\"grvsc-line\">\tname: demo-1</span>\n<span class=\"grvsc-line\">spec: </span>\n<span class=\"grvsc-line\">\tselector: </span>\n<span class=\"grvsc-line\">\t\tistio: ingressgateway </span>\n<span class=\"grvsc-line\">\tservers: </span>\n<span class=\"grvsc-line\">\t- port: </span>\n<span class=\"grvsc-line\">\t\tnumber: 80 </span>\n<span class=\"grvsc-line\">\t\tname: http </span>\n<span class=\"grvsc-line\">\t\tprotocol: HTTP </span>\n<span class=\"grvsc-line\">\t- hosts: </span>\n<span class=\"grvsc-line\">\t\t- &quot;demo-1.example.com&quot;</span></code></pre>\n<p>Gateway is used when we want to access the services from the public network.</p>\n<p>Here we are using the default gateway provided by the Istio. We can also create multiple gateways and assign the proper name here.</p>\n<p>The above gateway configuration enables both HTTP and HTTPS communication. In the case of HTTPS, we have to supply the secret containing the CA certs and key.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">spec:</span>\n<span class=\"grvsc-line\">\tservers: </span>\n<span class=\"grvsc-line\">\t- port: </span>\n<span class=\"grvsc-line\">\t\tnumber: 443</span>\n<span class=\"grvsc-line\">\t\tname: http </span>\n<span class=\"grvsc-line\">\t\tprotocol: HTTP</span>\n<span class=\"grvsc-line\">\t  tls: </span>\n<span class=\"grvsc-line\">\t\tmode: SIMPLE </span>\n<span class=\"grvsc-line\">\t\tcredentialName: div4-dev-certs</span>\n<span class=\"grvsc-line\">\t  hosts: </span>\n<span class=\"grvsc-line\">\t\t- &quot;demo-1.example.com&quot;</span></code></pre>\n<p>We can apply the same gateway for demo-2. We just have to update the hosts and metadata name. Since we will demo-2 internally from demo-1, there is no need for an external gateway for demo-2 here.</p>\n<h3 id=\"virtualservices\" style=\"position:relative;\"><a href=\"#virtualservices\" aria-label=\"virtualservices permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>VirtualServices</h3>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">---</span>\n<span class=\"grvsc-line\">apiVersion: networking.istio.io/v1alpha3</span>\n<span class=\"grvsc-line\">kind: VirtualService</span>\n<span class=\"grvsc-line\">metadata:</span>\n<span class=\"grvsc-line\">  name: demo-1</span>\n<span class=\"grvsc-line\">spec:</span>\n<span class=\"grvsc-line\">  hosts:</span>\n<span class=\"grvsc-line\">  - &quot;demo-1.test.svc.cluster.local&quot;</span>\n<span class=\"grvsc-line\">  - &quot;demo-1.example.com&quot;</span>\n<span class=\"grvsc-line\">  gateways:</span>\n<span class=\"grvsc-line\">    - demo-1</span>\n<span class=\"grvsc-line\">  http:</span>\n<span class=\"grvsc-line\">  - route:</span>\n<span class=\"grvsc-line\">    - destination:</span>\n<span class=\"grvsc-line\">        host: demo-1.test.svc.cluster.local</span>\n<span class=\"grvsc-line\">        port:</span>\n<span class=\"grvsc-line\">          number: 80</span></code></pre>\n<p><strong>spec.hosts:</strong> Specifies the URL which the caller of the service will use. Here, dsl-es.pbdp.svc.cluster.local will be used by the services calling internally. The endpoint demo-1.example.com will be exposed publicly, and it should match the <strong>spec.servers.hosts</strong> value in Gateway config.</p>\n<p><strong>spec.gateways:</strong> In order for the gateways configured above to reach the service, we need to define the gateway metadata name here.</p>\n<p><strong>http.route.destination.host:</strong> This value should be the actual service FQDN.</p>\n<h3 id=\"destinationrule\" style=\"position:relative;\"><a href=\"#destinationrule\" aria-label=\"destinationrule permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>DestinationRule</h3>\n<p>After the virtualservice decides the destination hosts, DestinationRule defines the configuration on the actual service. DestinationRule is optional and is needed only in case we want to override the default behavior.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">---</span>\n<span class=\"grvsc-line\">apiVersion: networking.istio.io/v1alpha3</span>\n<span class=\"grvsc-line\">kind: DestinationRule</span>\n<span class=\"grvsc-line\">metadata:</span>\n<span class=\"grvsc-line\">  name: demo-1</span>\n<span class=\"grvsc-line\">spec:</span>\n<span class=\"grvsc-line\">  host: &quot;demo-1.test.svc.cluster.local&quot;</span>\n<span class=\"grvsc-line\">  trafficPolicy:</span>\n<span class=\"grvsc-line\">    loadBalancer:</span>\n<span class=\"grvsc-line\">      simple: ROUND_ROBIN</span>\n<span class=\"grvsc-line\">    tls:</span>\n<span class=\"grvsc-line\">      mode: ISTIO_MUTUAL</span></code></pre>\n<p><strong>spec.host:</strong> specifies service FQDN</p>\n<p><strong>spec.trafficPolicy:</strong> Specifies policy on the traffic. Here we can specify load balancing algorithms, TLS mode, circuit breaking policies.</p>\n<p><strong>spec.trafficPolicy.tls.mode:</strong> ISTIO_MUTUAL mode is a TLS mode where we will use the certificates generated by the Istio.</p>\n<p>A configuration like circuit breakers, outlier detection comes under the Destination Rule.</p>\n<h3 id=\"peerauthentication\" style=\"position:relative;\"><a href=\"#peerauthentication\" aria-label=\"peerauthentication permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>PeerAuthentication</h3>\n<p>This configuration defines how the other services will connect.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"10\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">---</span>\n<span class=\"grvsc-line\">apiVersion: security.istio.io/v1beta1</span>\n<span class=\"grvsc-line\">kind: PeerAuthentication</span>\n<span class=\"grvsc-line\">metadata:</span>\n<span class=\"grvsc-line\">  name: demo-1</span>\n<span class=\"grvsc-line\">spec:</span>\n<span class=\"grvsc-line\">  selector:</span>\n<span class=\"grvsc-line\">    matchLabels:</span>\n<span class=\"grvsc-line\">      app: demo-1</span>\n<span class=\"grvsc-line\">  mtls:</span>\n<span class=\"grvsc-line\">    mode: STRICT</span></code></pre>\n<p><strong>spec.selector.matchLabels.app:</strong> Specify the deployment label on which this configuration will be applied.</p>\n<p><strong>spec.mtls.mode:</strong> TLS mode. STRICT being the connection will always be mutual tls.</p>\n<p>PeerAuthentication can be applied to a whole namespace. This is useful when all the services in the namespace are part of the mesh.</p>\n<blockquote>\n<p>Apply the same configuration for virutalservice, destination, and peerauthentication by replacing demo-1 with demo-2 assuming both services are in the same namespace.</p>\n</blockquote>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"11\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl apply -f &lt;file&gt;.yaml -n test</span></code></pre>\n<p>Access the objects:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"12\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">kubectl get virtualservices -n pbdp</span>\n<span class=\"grvsc-line\">kubectl get gateways -n pbdp</span>\n<span class=\"grvsc-line\">kubectl get destinationrule -n pbdp</span>\n<span class=\"grvsc-line\">kubectl get peerauthentication -n pbdp</span></code></pre>\n<p>Now update the env for demo-2 with <code>demo-2.test.svc.cluster.local</code> in demo-1 service.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n</style>","frontmatter":{"date":"January 22, 2021","updated_date":null,"description":"This article will provide a step by step process on how to install and configure services using Istio.","title":"How to Install and Configure Istio","tags":["Istio","Service Mesh"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/452f4d9f7cb358e3d6224ed3aba3d5d6/ee604/Istio.png","srcSet":"/static/452f4d9f7cb358e3d6224ed3aba3d5d6/69585/Istio.png 200w,\n/static/452f4d9f7cb358e3d6224ed3aba3d5d6/497c6/Istio.png 400w,\n/static/452f4d9f7cb358e3d6224ed3aba3d5d6/ee604/Istio.png 800w,\n/static/452f4d9f7cb358e3d6224ed3aba3d5d6/db955/Istio.png 900w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Piyush Kumar","github":"kpiyush17","avatar":null}}}},{"node":{"excerpt":"In this article, we will address how to perform basic query operations in MongoDB. We are producing data at an unparalleled pace now…","fields":{"slug":"/engineering/basic-query-operations-in-mongodb/"},"html":"<p>In this article, we will address how to perform basic query operations in MongoDB. We are producing data at an unparalleled pace now following the global spread of the internet. Since it will require us to collect/request the required data from the database to conduct some kind of analysis, it is of utmost importance that we choose the right tool to query the data.</p>\n<p>This is where MongoDB comes in, specifically. MongoDB is an unstructured database which, in the form of documents, stores data. In addition, MongoDB is very effective in <a href=\"https://www.loginradius.com/blog/engineering/live-data-migration-mongodb/\">handling enormous amounts of data</a> and is the most commonly used NoSQL database as it provides rich query language and versatile and easy data access.</p>\n<h2 id=\"create-a-sample-database\" style=\"position:relative;\"><a href=\"#create-a-sample-database\" aria-label=\"create a sample database permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Create a Sample Database</h2>\n<p>Before the start, we will create a sample DB with some sample data to perform all operations.</p>\n<p>We will create a database with name <em>myDB</em> and will create a collection with name <em>orders</em>. For this, the statement would be as follows.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt; use myDB</span>\n<span class=\"grvsc-line\">&gt; db.createCollection(&quot;orders&quot;)</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<p><em>MongoDB doesn't use the rows and columns. It stores the data in a document format. A collection is a group of documents.</em></p>\n<p>You can check all collections in a database by using the following statement.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt; use myDB</span>\n<span class=\"grvsc-line\">&gt;show collections</span>\n<span class=\"grvsc-line\">orders</span>\n<span class=\"grvsc-line\">system.indexes</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<p>Let's insert some documents by using the following statement.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt; db.orders.insert([</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;abc&quot;,</span>\n<span class=\"grvsc-line\">\t\tAddress:{&quot;City&quot;:&quot;Jaipur&quot;,&quot;Country&quot;:&quot;India&quot;},</span>\n<span class=\"grvsc-line\">\t\tPaymentMode&quot;:&quot;Card&quot;,</span>\n<span class=\"grvsc-line\">\t\tEmail:&quot;abc@mail.in&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 1000.00,</span>\n<span class=\"grvsc-line\">\t\tOrderItems:[</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;notebook&quot;,&quot;Price&quot;:&quot;150.00&quot;,&quot;Qty&quot;:10},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;paper&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;journal&quot;,&quot;Price&quot;:&quot;200.00&quot;,&quot;Qty&quot;:2},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;postcard&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:500}</span>\n<span class=\"grvsc-line\">\t\t]\t\t</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;xyz&quot;,</span>\n<span class=\"grvsc-line\">\t\tAddress:{&quot;City&quot;:&quot;Delhi&quot;,&quot;Country&quot;:&quot;India&quot;},</span>\n<span class=\"grvsc-line\">\t\tPaymentMode&quot;:&quot;Cash&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 800.00,</span>\n<span class=\"grvsc-line\">\t\tOrderItems:[</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;notebook&quot;,&quot;Price&quot;:&quot;150.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;paper&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;postcard&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:500}</span>\n<span class=\"grvsc-line\">\t\t]\t\t</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;ron&quot;,</span>\n<span class=\"grvsc-line\">\t\tAddress:{&quot;City&quot;:&quot;New York&quot;,&quot;Country&quot;:&quot;USA&quot;},</span>\n<span class=\"grvsc-line\">\t\tPaymentMode&quot;:&quot;Card&quot;,</span>\n<span class=\"grvsc-line\">\t\tEmail:&quot;ron@mail.com&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 800.00,</span>\n<span class=\"grvsc-line\">\t\tOrderItems:[</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;notebook&quot;,&quot;Price&quot;:&quot;150.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;postcard&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:00}</span>\n<span class=\"grvsc-line\">\t\t]\t\t</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">])</span></code></pre>\n<p><em>A document is the equivalent of an RDBMS row. It doesn't need to have the same schema in each document. It means a document might not have any field that doesn't have any value.</em></p>\n<h2 id=\"query-documents\" style=\"position:relative;\"><a href=\"#query-documents\" aria-label=\"query documents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Query Documents</h2>\n<h3 id=\"find-method\" style=\"position:relative;\"><a href=\"#find-method\" aria-label=\"find method permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>find() method</h3>\n<p>You need to use the find() method to query documents from MongoDB collections. The following statement will retrieve all documents from the collection.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt; db.orders.find()</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607534c&quot;)</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;abc&quot;,</span>\n<span class=\"grvsc-line\">\t\tAddress:{&quot;City&quot;:&quot;Jaipur&quot;,&quot;Country&quot;:&quot;India&quot;},</span>\n<span class=\"grvsc-line\">\t\tPaymentMode&quot;:&quot;Card&quot;,</span>\n<span class=\"grvsc-line\">\t\tEmail:&quot;abc@mail.com&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 1000.00,</span>\n<span class=\"grvsc-line\">\t\tOrderItems:[</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;notebook&quot;,&quot;Price&quot;:&quot;150.00&quot;,&quot;Qty&quot;:10},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;paper&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;journal&quot;,&quot;Price&quot;:&quot;200.00&quot;,&quot;Qty&quot;:2},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;postcard&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:500}</span>\n<span class=\"grvsc-line\">\t\t]\t\t</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607544c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;xyz&quot;,</span>\n<span class=\"grvsc-line\">\t\tAddress:{&quot;City&quot;:&quot;Delhi&quot;,&quot;Country&quot;:&quot;India&quot;},</span>\n<span class=\"grvsc-line\">\t\tPaymentMode&quot;:&quot;Cash&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 800.00,</span>\n<span class=\"grvsc-line\">\t\tOrderItems:[</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;notebook&quot;,&quot;Price&quot;:&quot;150.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;paper&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;postcard&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:500}</span>\n<span class=\"grvsc-line\">\t\t]</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607644c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;ron&quot;,</span>\n<span class=\"grvsc-line\">\t\tAddress:{&quot;City&quot;:&quot;New York&quot;,&quot;Country&quot;:&quot;USA&quot;},</span>\n<span class=\"grvsc-line\">\t\tPaymentMode&quot;:&quot;Card&quot;,</span>\n<span class=\"grvsc-line\">\t\tEmail:&quot;ron@mail.com&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 600.00,</span>\n<span class=\"grvsc-line\">\t\tOrderItems:[</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;notebook&quot;,&quot;Price&quot;:&quot;150.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;postcard&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:00}</span>\n<span class=\"grvsc-line\">\t\t]</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<h3 id=\"projection\" style=\"position:relative;\"><a href=\"#projection\" aria-label=\"projection permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Projection</h3>\n<p>If you want to fetch only selected fields then you can use the projection. Following statement will fetch only <em>Customer</em> and <em>Email</em> field.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt; db.orders.find( { }, { Customer: 1, Email: 1 })</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607534c&quot;)</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;abc&quot;,</span>\n<span class=\"grvsc-line\">\t\tEmail:&quot;abc@mail.com&quot;</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607544c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;xyz&quot;\t\t</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607644c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;ron&quot;,</span>\n<span class=\"grvsc-line\">\t\tEmail:&quot;ron@mail.com&quot;\t\t</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<h3 id=\"filter-the-documents-by-specifying-a-condition\" style=\"position:relative;\"><a href=\"#filter-the-documents-by-specifying-a-condition\" aria-label=\"filter the documents by specifying a condition permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Filter the Documents by Specifying a Condition</h3>\n<p>Now we will learn how we can fetch the documents that match a specified condition. MongoDB provides many comparison operators for this.</p>\n<h4 id=\"1-eq-operator\" style=\"position:relative;\"><a href=\"#1-eq-operator\" aria-label=\"1 eq operator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. $eq Operator</h4>\n<p>The $eq operator checks the equality of the field value with the specified value. To fetch the order where <em>PaymentMode</em> is 'Card' you can use the following statement</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.orders.find( { PaymentMode: { $eq: &quot;Card&quot; } } )</span></code></pre>\n<p><em>This query can be written also like below</em></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.orders.find( { PaymentMode: &quot;Card&quot; } )</span></code></pre>\n<p><em>A similar SQL statement would be as follows</em></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">SELECT * FROM orders WHERE PaymentMode=&quot;Card&quot;</span></code></pre>\n<p><strong>Example</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.orders.find( { PaymentMode: &quot;Card&quot; }, { Customer: 1, PaymentMode: 1 } )</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607534c&quot;)</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;abc&quot;,</span>\n<span class=\"grvsc-line\">\t\tPaymentMode&quot;:&quot;Card&quot;\t\t\t\t</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607644c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;ron&quot;,</span>\n<span class=\"grvsc-line\">\t\tPaymentMode&quot;:&quot;Card&quot;</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<p><strong>$eq Operator with embedded document</strong></p>\n<p>You may have noticed that we inserted an embedded document <em>Address</em> in the <em>Orders</em> collection. If you want to fetch the order where <em>Country</em> is 'India' you can use a dot notation like the following statement.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { &quot;Address.Country&quot;: { $eq: &quot;India&quot; } } )</span></code></pre>\n<p><em>This query can be written also like below</em></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"10\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { &quot;Address.Country&quot;:&quot;India&quot; } )</span></code></pre>\n<p><strong>Example</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"11\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { &quot;Address.Country&quot;: { $eq: &quot;India&quot; } } , { Customer: 1, Address: 1 })</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607534c&quot;)</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;abc&quot;,</span>\n<span class=\"grvsc-line\">\t\tAddress:{&quot;City&quot;:&quot;Jaipur&quot;,&quot;Country&quot;:&quot;India&quot;}</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607544c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;xyz&quot;,</span>\n<span class=\"grvsc-line\">\t\tAddress:{&quot;City&quot;:&quot;Delhi&quot;,&quot;Country&quot;:&quot;India&quot;}</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<p><strong>$eq Operator with array</strong></p>\n<p>$eq operator will retrieve all the documents if the specified condition is true for any item in an array. We have an <em>OrderItems</em> array in the document. If you want to filter the documents where 'paper' were also ordered then the statement would be as follows.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"12\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { &quot;OrderItems.ItemName&quot;: { $eq: &quot;paper&quot; } } )</span></code></pre>\n<p><em>This query can be written also like below</em></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"13\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { &quot;OrderItems.ItemName&quot;: &quot;paper&quot;  } )</span></code></pre>\n<p><strong>Example</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"14\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { &quot;OrderItems.ItemName&quot;: { $eq: &quot;paper&quot; } } , { Customer: 1, OrderItems: 1 })</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607534c&quot;)</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;abc&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderItems:[</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;notebook&quot;,&quot;Price&quot;:&quot;150.00&quot;,&quot;Qty&quot;:10},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;paper&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;journal&quot;,&quot;Price&quot;:&quot;200.00&quot;,&quot;Qty&quot;:2},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;postcard&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:500}</span>\n<span class=\"grvsc-line\">\t\t]\t\t</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607544c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;xyz&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderItems:[</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;notebook&quot;,&quot;Price&quot;:&quot;150.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;paper&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;postcard&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:500}</span>\n<span class=\"grvsc-line\">\t\t]</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<h4 id=\"2-gt-operator\" style=\"position:relative;\"><a href=\"#2-gt-operator\" aria-label=\"2 gt operator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. $gt Operator</h4>\n<p>You can use the $gt operator to retrieve the documents where a field’s value is greater than the specified value. The following statement will fetch the documents where <em>OrderTotal</em> is greater than 800.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"15\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.orders.find( { OrderTotal: { $gt: 800.00 } } )</span></code></pre>\n<p><em>A similar SQL statement would be as follows</em></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"16\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">SELECT * FROM orders WHERE OrderTotal&gt;800.00</span></code></pre>\n<p><strong>Example</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"17\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { &quot;OrderTotal&quot;: { $gt: 800.00 } } , { Customer: 1, OrderTotal: 1 })</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607534c&quot;)</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;abc&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 1000.00</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<h4 id=\"3-gte-operator\" style=\"position:relative;\"><a href=\"#3-gte-operator\" aria-label=\"3 gte operator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>3. $gte Operator</h4>\n<p>You can use the $gte operator to retrieve the documents where a field’s value is greater than or equal to the specified value. The following statement will fetch the documents where <em>OrderTotal</em> is greater than or equal to 800.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"18\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.orders.find( { OrderTotal: { $gte: 800.00 } } )</span></code></pre>\n<p><em>A similar SQL statement would be as follows</em></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"19\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">SELECT * FROM orders WHERE OrderTotal&gt;=800.00</span></code></pre>\n<p><strong>Example</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"20\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { &quot;OrderTotal&quot;: { $gte: 800.00 } } , { Customer: 1, OrderTotal: 1 })</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607534c&quot;)</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;abc&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 1000.00</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607544c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;xyz&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 800.00</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<h4 id=\"4-lt-operator\" style=\"position:relative;\"><a href=\"#4-lt-operator\" aria-label=\"4 lt operator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>4. $lt Operator</h4>\n<p>You can use the $lt operator to retrieve the documents where a field’s value is less than the specified value. The following statement will fetch the documents where <em>OrderTotal</em> is less than 800.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"21\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.orders.find( { OrderTotal: { $lt: 800.00 } } )</span></code></pre>\n<p><em>A similar SQL statement would be as follows</em></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"22\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">SELECT * FROM orders WHERE OrderTotal&lt;800.00</span></code></pre>\n<p><strong>Example</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"23\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { &quot;OrderTotal&quot;: { $lt: 800.00 } } , { Customer: 1, OrderTotal: 1 })</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607644c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;ron&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 600.00</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<h4 id=\"4-lte-operator\" style=\"position:relative;\"><a href=\"#4-lte-operator\" aria-label=\"4 lte operator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>4. $lte Operator</h4>\n<p>You can use the $lte operator to retrieve the documents where a field’s value is less than or equal to the specified value. Following statement will fetch the documents where <em>OrderTotal</em> is less than or equal to 800.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"24\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.orders.find( { OrderTotal: { $lte: 800.00 } } )</span></code></pre>\n<p><em>A similar SQL statement would be as follows</em></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"25\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">SELECT * FROM orders WHERE OrderTotal&lt;=800.00</span></code></pre>\n<p><strong>Example</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"26\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { &quot;OrderTotal&quot;: { $lte: 800.00 } } , { Customer: 1, OrderTotal: 1 })</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607544c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;xyz&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 800.00</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607644c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;ron&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderTotal: 600.00</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<h4 id=\"5-ne-operator\" style=\"position:relative;\"><a href=\"#5-ne-operator\" aria-label=\"5 ne operator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>5. $ne Operator</h4>\n<p>You can use the $ne operator to retrieve the documents where a field’s value is not equal to the specified value.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"27\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.orders.find( { PaymentMode: { $ne: &quot;Card&quot; } } )</span></code></pre>\n<p><em>A similar SQL statement would be as follows</em></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"28\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">SELECT * FROM orders WHERE PaymentMode != &quot;Card&quot;</span></code></pre>\n<p><strong>Example</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"29\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { &quot;PaymentMode&quot;: { $ne: &quot;Card&quot; } } , { Customer: 1, PaymentMode: 1 })</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607544c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;xyz&quot;,</span>\n<span class=\"grvsc-line\">\t\tPaymentMode&quot;:&quot;Cash&quot;</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<h4 id=\"6-in-operator\" style=\"position:relative;\"><a href=\"#6-in-operator\" aria-label=\"6 in operator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>6. $in Operator</h4>\n<p>You can use the $in operator to retrieve the documents where a field’s value is equal to any value in the specified array.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"30\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.orders.find( { OrderItems.ItemName: { $in: [&quot;journal&quot;,&quot;paper&quot;] } } )</span></code></pre>\n<p><strong>Example</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"31\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { OrderItems.ItemName: { $in: [&quot;journal&quot;,&quot;paper&quot;] } } , { Customer: 1, OrderItems: 1 })</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607534c&quot;)</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;abc&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderItems:[</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;notebook&quot;,&quot;Price&quot;:&quot;150.00&quot;,&quot;Qty&quot;:10},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;paper&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;journal&quot;,&quot;Price&quot;:&quot;200.00&quot;,&quot;Qty&quot;:2},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;postcard&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:500}</span>\n<span class=\"grvsc-line\">\t\t]\t\t</span>\n<span class=\"grvsc-line\">\t},</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607544c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;xyz&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderItems:[</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;notebook&quot;,&quot;Price&quot;:&quot;150.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;paper&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;postcard&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:500}</span>\n<span class=\"grvsc-line\">\t\t]</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<h4 id=\"7-nin-operator\" style=\"position:relative;\"><a href=\"#7-nin-operator\" aria-label=\"7 nin operator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>7. $nin Operator</h4>\n<p>You can use the $nin operator to retrieve the documents where a field’s value is not equal to any value in the specified array. It will also select the documents where the field does not exist.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"32\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.orders.find( { OrderItems.ItemName: { $nin: [&quot;journal&quot;,&quot;paper&quot;] } } )</span></code></pre>\n<p><strong>Example</strong></p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"33\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.find( { OrderItems.ItemName: { $nin: [&quot;journal&quot;,&quot;paper&quot;] } } , { Customer: 1, OrderItems: 1 })</span>\n<span class=\"grvsc-line\">\t{</span>\n<span class=\"grvsc-line\">\t\t&quot;_id&quot; : ObjectId(&quot;5dd4e2cc0821d3b44607644c&quot;),</span>\n<span class=\"grvsc-line\">\t\tCustomer: &quot;ron&quot;,</span>\n<span class=\"grvsc-line\">\t\tOrderItems:[</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;notebook&quot;,&quot;Price&quot;:&quot;150.00&quot;,&quot;Qty&quot;:5},</span>\n<span class=\"grvsc-line\">\t\t\t{&quot;ItemName&quot;:&quot;postcard&quot;,&quot;Price&quot;:&quot;10.00&quot;,&quot;Qty&quot;:00}</span>\n<span class=\"grvsc-line\">\t\t]</span>\n<span class=\"grvsc-line\">\t}</span>\n<span class=\"grvsc-line\">&gt;</span></code></pre>\n<h3 id=\"indexing\" style=\"position:relative;\"><a href=\"#indexing\" aria-label=\"indexing permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Indexing</h3>\n<p>We know that <a href=\"https://www.loginradius.com/blog/engineering/index-in-mongodb/\">indexing is very important</a> if we are performing the queries on a large database. Without indexing execution of a query can be expensive. We can add a simple ascending index on a single field by using the following statement.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"34\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&gt;db.Orders.createIndex({&quot;Customer&quot;:1})</span></code></pre>\n<p>MongoDB creates a unique index on ‘_id’ field by default. A unique index will prevent insertion of two documents with the same value for that field. If you want to create a unique index then the statement would be as follows.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"35\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">db.Orders.createIndex( { &quot;OrderId&quot;: 1 }, { unique: true } )</span></code></pre>\n<h2 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h2>\n<p>I hope you learned something new today, If you want to learn few more stuff on MongoDB, here is an interesting article on <a href=\"https://www.loginradius.com/blog/engineering/self-hosted-mongo/\">Self-Hosted MongoDB</a> I also invite you to try stuff on your own and share your experience in the comment section. Furthermore, if you face any problems with any of the above definitions, please feel free to ask me in the comments below.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n</style>","frontmatter":{"date":"January 20, 2021","updated_date":null,"description":null,"title":"How to Perform Basic Query Operations in MongoDB","tags":["MongoDB"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/4baf4f017625700154de23531c7ef2a8/ee604/coverImage.png","srcSet":"/static/4baf4f017625700154de23531c7ef2a8/69585/coverImage.png 200w,\n/static/4baf4f017625700154de23531c7ef2a8/497c6/coverImage.png 400w,\n/static/4baf4f017625700154de23531c7ef2a8/ee604/coverImage.png 800w,\n/static/4baf4f017625700154de23531c7ef2a8/f3583/coverImage.png 1200w,\n/static/4baf4f017625700154de23531c7ef2a8/5707d/coverImage.png 1600w,\n/static/4baf4f017625700154de23531c7ef2a8/eeb1b/coverImage.png 1920w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Anil Gupta","github":"anilswm","avatar":null}}}},{"node":{"excerpt":"As we all know, JSON Web Tokens are a way of sending information between parties in a way where the sender's authenticity can be verified…","fields":{"slug":"/engineering/invalidating-jwt/"},"html":"<p>As we all know, JSON Web Tokens are a way of sending information between parties in a way where the sender's authenticity can be verified. It is essentially a JSON object with a signature. Using this signature, services that issue these tokens can verify that they are the ones who issued this token and thus can trust the claims which are contained within. </p>\n<p>The trustworthiness of these tokens make them popular for use in authorization and authentication scenarios:</p>\n<ul>\n<li>In authorization workflows, JSON Web Tokens are distributed to users with claims containing the resources and services that are allowed for that user. The issuing service can perform its database lookups to determine the user's authorization levels when the token is being generated and issued. Since the signature can be used to verify that the token is authentic and issued by a trusted source, for subsequent transactions using the token, the service can safely take the token at its word. This saves the service from needing to check its database for the user's relevant permissions every time a transaction is performed.</li>\n<li>In authentication workflows such as OAuth2, JSON Web Tokens are often used as part of a larger workflow, where they are useful to securely transmit information between parties. Since the resource server and authenticating server are different, these tokens ensure that the information being received by these parties is valid and authentic.</li>\n</ul>\n<p>For this post, we'll be focusing on the former use case. So having a token with trustworthy claims is great; we can take the token at its word, and trust all of the information that it has contained within as gospel. Our server is unburdened from having to potentially make database calls to verify the user's role, their permissions, their existence, or even if they're logged in. Once the server has generated the token, as far as it is concerned, no state has to be maintained regarding the validity of the token. It will expire once its expiration time included in its claim has passed.</p>\n<p>But before we go ahead and use this for all of our authorization needs, we have to remember that while JSON Web Tokens themselves are stateless, to have a robust, feasible, and controllable authorization workflow, we'll have to maintain some state one way or another.</p>\n<p>You can think of an authorization token as an elementary school hall pass. The teacher (resource server) knows that it is a legitimate hall pass because it is green, 6 cm x 12 cm and has a signature from another member of the faculty. Now imagine that you've issued a hall pass, but now you need to take it back (you've changed your mind, or the kid did something bad). Your options are:</p>\n<ul>\n<li>Go to the kid and take the pass back (browser deletes the token from its storage). However, the kid made a photocopy, and can still roam the halls with relative ease.</li>\n<li>Wait till the hall pass expires (wait till the token expiry claim passes). Green hall passes are only valid on Mondays. He can still roam the halls freely for the remainder of Monday (the horror).</li>\n<li>Change the entire format of the hall pass (change the secret used to sign the token). The crisis has been averted, but now you'll need to handicraft another 5 whole hall passes for the class.</li>\n</ul>\n<p>Other than the 3rd option which may or may not be feasible depending on your use case (most likely not), we can see that it is not possible to reliably remove or revoke a token without maintaining state. The solutions that I've looked upon Stack Overflow for invalidating these tokens boil down to relying on some form of state, one way or another. Don't get me wrong however, this is not a bad thing in my opinion. Using JSON Web Tokens can and do allow us to minimize the state that we do have to maintain, with minimal added complexity.</p>\n<p>So let's look at some ways that we can couple state and JSON Web Tokens that allow us to invalidate these tokens effectively.</p>\n<h3 id=\"token-whitelist\" style=\"position:relative;\"><a href=\"#token-whitelist\" aria-label=\"token whitelist permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Token Whitelist</h3>\n<p>We can maintain a database table containing all of the tokens issued by our server that we would like to accept as valid. This would be a 1:1 session store, with every transaction occurring requiring this table to be checked to prevent an invalidated token from being accepted. While we would not be able to reduce the amount of state being maintained on our server, JSON Web Tokens still provide us with the utility of its trusted claims (and the performance benefits of not needing to check those).</p>\n<h3 id=\"token-blacklist\" style=\"position:relative;\"><a href=\"#token-blacklist\" aria-label=\"token blacklist permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Token Blacklist</h3>\n<p>We can maintain a database table containing all of the tokens issued by our server that we do NOT want to accept as valid. Every transaction that occurs will require this table to be checked, to prevent an invalidated token from being accepted. Each record would only have to be maintained until the token itself expires. I can't think of any use case where a table of invalidated tokens would regularly be larger than a table of active tokens, so I'd imagine that the table maintained would almost always be smaller than maintaining a table of active tokens.</p>\n<h3 id=\"using-a-dynamic-secret-to-sign\" style=\"position:relative;\"><a href=\"#using-a-dynamic-secret-to-sign\" aria-label=\"using a dynamic secret to sign permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Using a Dynamic Secret to Sign</h3>\n<p>This solution still needs a database lookup, but interestingly requires no state. For this, we can use the hash of a piece of data to sign the token itself. For example, by using the hash of a user's password, when the user changes their password, subsequent transactions involving an old token will fail, as the signature will fail to be verified. The effectiveness of this, however, would depend on your requirements, as this would be limited to invalidating tokens based on changing data (such as changing roles, passwords, etc.). It would not allow you to invalidate a token whenever you want.</p>\n<h3 id=\"concluding-remarks\" style=\"position:relative;\"><a href=\"#concluding-remarks\" aria-label=\"concluding remarks permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Concluding Remarks</h3>\n<p>I think that JSON Web Tokens coupled with a token blacklist is a fantastic way to manage authorization in web applications. This allows you to leverage the benefits of these tokens in reducing the network calls needed to secure your application, reduce the amount of data you need to store to manage sessions, and do so in a reliable way without introducing too much complexity.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","frontmatter":{"date":"January 18, 2021","updated_date":null,"description":"A discussion on invalidating JSON Web Tokens.","title":"Invalidating JSON Web Tokens","tags":["JSON Web Tokens","JWT"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/79aa8bd08d0b463cb8261d80f51fa641/ee604/unsplash.png","srcSet":"/static/79aa8bd08d0b463cb8261d80f51fa641/69585/unsplash.png 200w,\n/static/79aa8bd08d0b463cb8261d80f51fa641/497c6/unsplash.png 400w,\n/static/79aa8bd08d0b463cb8261d80f51fa641/ee604/unsplash.png 800w,\n/static/79aa8bd08d0b463cb8261d80f51fa641/f3583/unsplash.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Nick Chim","github":"nickc95","avatar":null}}}}]},"markdownRemark":{"excerpt":"Google has prepared a roadmap to restrict third-party cookies in Chrome. Since 04 January 2024, Chrome has rolled out third-party cookie…","fields":{"slug":"/engineering/identity-impact-of-google-chrome-thirdparty-cookie-restrictions/"},"html":"<p>Google has prepared a roadmap to restrict third-party cookies in Chrome. Since 04 January 2024, Chrome has rolled out third-party cookie restrictions for 1% of stable clients and 20% of Canary, Dev, and Beta clients.</p>\n<p><strong>What does it mean for user authentication?</strong></p>\n<p>On one hand, Google believes third-party cookies are widely used for cross-site tracking, greatly affecting user privacy. Hence, Google wants to phase out (or restrict) supporting third-party cookies in Chrome by early Q2 2025 (subject to regulatory processes).</p>\n<p>On the other hand, Google introduced Privacy Sandbox to support the use cases (other than cross-site tracking and advertising) previously implemented using third-party cookies.</p>\n<p>In this article, we’ll discuss:</p>\n<ul>\n<li>How is user authentication (identity) affected?</li>\n<li>What is Google offering as part of Privacy Sandbox to support various identity use cases when third-party cookies are phased out?</li>\n</ul>\n<h2 id=\"how-is-user-authentication-affected\" style=\"position:relative;\"><a href=\"#how-is-user-authentication-affected\" aria-label=\"how is user authentication affected permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How is User Authentication Affected?</h2>\n<p>Third-party cookie restrictions affect user authentication in three ways, as follows.</p>\n<h3 id=\"external-identity-providers\" style=\"position:relative;\"><a href=\"#external-identity-providers\" aria-label=\"external identity providers permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>External Identity Providers</h3>\n<p>If your website or app uses an external Identity Provider (IdP) — like LoginRadius, the IdP sets a third-party cookie when the user authenticates on your app.</p>\n<h3 id=\"web-sso\" style=\"position:relative;\"><a href=\"#web-sso\" aria-label=\"web sso permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Web SSO</h3>\n<p>If you have multiple apps across domains within your organization and authentication is handled using an IdP (internal or external) with web SSO, you already use third-party cookies to facilitate seamless access for each user using a single set of credentials.</p>\n<p>If you have implemented web SSO with one primary domain and multiple sub-domains of the primary domain, third-party cookie restrictions may not apply. For now, Google doesn’t consider the cookies set by sub-domains as third-party cookies, although this stance may change in the future.</p>\n<p>For example, you have apps at <code>example.com</code>, <code>travel.example.com</code>, <code>stay.example.com</code>, and web SSO is handled by <code>auth.example.com</code>. In this case, third-party cookie restrictions don’t apply.</p>\n<h3 id=\"federated-sso\" style=\"position:relative;\"><a href=\"#federated-sso\" aria-label=\"federated sso permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Federated SSO</h3>\n<p>Federated SSO is similar to, albeit different from, web SSO. It can handle multiple IdPs and applications—aka., Service Providers (SPs)—spanning multiple organizations. It can also implement authentication scenarios that are usually implemented through web SSO.</p>\n<p>Usually, authentication is handled on a separate pop-up or page when the user wants to authenticate rather than on the application or website a user visits. </p>\n<p>For example, you already use federated SSO if you facilitate authentication for a set of apps through multiple social identity providers as well as traditional usernames and passwords.</p>\n<blockquote>\n<p><strong>Note</strong>: It is also possible to store tokens locally, not within cookies. In this case, third-party cookie restrictions won’t affect token-based authentication. However, the restrictions still affect authentication where tokens are stored within third-party cookies (a common and secure method).</p>\n</blockquote>\n<h2 id=\"chromes-alternatives-for-third-party-cookies\" style=\"position:relative;\"><a href=\"#chromes-alternatives-for-third-party-cookies\" aria-label=\"chromes alternatives for third party cookies permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Chrome’s Alternatives for Third-Party Cookies</h2>\n<p>Google has been developing alternative features and capabilities for Chrome to replace third-party cookies as part of its Privacy Sandbox for Web initiative.</p>\n<p>Specific to authentication, Google recommends the following:</p>\n<ol>\n<li>Cookies Having Independent Partitioned State (CHIPS)</li>\n<li>Storage Access API</li>\n<li>Related Website Sets</li>\n<li>Federated Credential Management (FedCM) API</li>\n</ol>\n<h3 id=\"cookies-having-independent-partitioned-state-chips\" style=\"position:relative;\"><a href=\"#cookies-having-independent-partitioned-state-chips\" aria-label=\"cookies having independent partitioned state chips permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Cookies Having Independent Partitioned State (CHIPS)</h3>\n<p><a href=\"https://developers.google.com/privacy-sandbox/3pcd/chips\">CHIPS</a> are a restricted way of setting third-party cookies on a top-level site without making them accessible on other top-level sites. Thus, they limit cross-site tracking and enable specific cross-site functionalities, such as maps, chat, and payment embeds.</p>\n<p>For example, a user visits <code>a.com</code> with a map embed from <code>map-example.com</code>, which can set a partitioned cookie that is only accessible on a.com. </p>\n<p>If the user visits <code>b.com</code> with a map embed from <code>map-example.com</code>, it cannot access the partitioned cookie set on <code>a.com</code>. It has to create a separate partitioned cookie specific to <code>b.com</code>, thus blocking cross-site tracking yet allowing limited cross-site functionality.</p>\n<p>You should specifically opt for partitioned cookies (CHIPS), which are set with partitioned and secure cookie attributes.</p>\n<p>If you’re using an external identity provider for your application, CHIPS is a good option to supplant third-party cookie restrictions. </p>\n<p>However, CHIPS may not be ideal if you have a web SSO or federated SSO implementation. It creates separate partitioned cookies for each application with a separate domain, which can increase complexity and create compatibility issues.</p>\n<h3 id=\"storage-access-api\" style=\"position:relative;\"><a href=\"#storage-access-api\" aria-label=\"storage access api permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Storage Access API</h3>\n<p>With <a href=\"https://developers.google.com/privacy-sandbox/3pcd/storage-access-api\">Storage Access API</a>, you can access the local storage in a third-party context through iframes, similar to when users visit it as a top-level site in a first-party context. That is, it gives access to unpartitioned cookies and storage.</p>\n<p>Storage Access API requires explicit user approval to grant access, similar to locations, camera, and microphone permissions. If the user denies access, unpartitioned cookies and storage won’t be accessible in a third-party context.</p>\n<p>It is most suitable when loading cross-site resources and interactions, such as:</p>\n<p>Verifying user sessions when allowing interactions on an embedded social post or providing personalization for an embedded video.\nEmbedded documents requiring user verification status to be accessible.</p>\n<p>As it requires explicit user approval, it is advisable to use Storage Access API when you can’t implement an identity use case with the other options.</p>\n<h3 id=\"related-website-sets\" style=\"position:relative;\"><a href=\"#related-website-sets\" aria-label=\"related website sets permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Related Website Sets</h3>\n<p>With <a href=\"https://developers.google.com/privacy-sandbox/3pcd/related-website-sets\">Related Website Sets</a>, you can declare a <code>primary</code> website and <code>associatedSites</code> for limited purposes to grant third-party cookie access and local storage for a limited number of sites.</p>\n<p>Chrome automatically recognizes related website sets declared, accepted, and maintained in this open-source GitHub repository: <a href=\"https://github.com/GoogleChrome/related-website-sets\">Related Website Sets</a></p>\n<p>It provides access through Storage Access API directly without prompting for user approval, but only after the user interacts with the relevant iframe.</p>\n<p>It is important to declare a limited number of domains in related website sets that are meaningful and used for specific purposes. Google may block or suspend any exploitative use of this feature.</p>\n<p>The top-level site can also request approval for specific cross-site resources and scripts to Storage Access API using <code>resuestStorageAccessFor()</code> API.</p>\n<p>If you’re using an external identity provider for your web application, you can declare the domain of the identity provider in the related set to ensure limited third-party cookies and storage access to the identity provider, thus ensuring seamless user authentication.</p>\n<p>Related Website Sets can also work to supplement third-party cookie restrictions in web SSO and federated SSO if the number of web applications (or domains) is limited.</p>\n<h3 id=\"federated-credential-management-fedcm-api\" style=\"position:relative;\"><a href=\"#federated-credential-management-fedcm-api\" aria-label=\"federated credential management fedcm api permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Federated Credential Management (FedCM) API</h3>\n<p>FedCM API enables federated SSO without third-party cookies.</p>\n<p>With FedCM API, a user follows these steps for authentication:</p>\n<ol>\n<li>The User navigates to a Service Provider (SP) — aka., Relying Party (RP)</li>\n<li>As the user requests to authenticate, the SP requests the browser through FedCM API to initiate authentication.</li>\n<li>The browser displays a list of available identity providers (supported by the RP), such as social IdPs like Google, Apple, LinkedIn, and Facebook, or other OAuth IdPs like LoginRadius.</li>\n<li>Once the user selects an IdP, the browser communicates with the IdP. Upon valid authentication, the IdP generates a secure token.\nThe browser delivers this secure token to the RP to facilitate user authorization.</li>\n</ol>\n<p>You can access a user demo of FedCM here: <a href=\"https://fedcm-rp-demo.glitch.me/\">FedCM</a>. </p>\n<p>For more information about implementing federated SSO with FedCM API, go through the <a href=\"https://developers.google.com/privacy-sandbox/3pcd/fedcm-developer-guide\">FedCM developer guide</a>.</p>\n<h2 id=\"how-is-loginradius-preparing-for-the-third-party-cookie-phase-out\" style=\"position:relative;\"><a href=\"#how-is-loginradius-preparing-for-the-third-party-cookie-phase-out\" aria-label=\"how is loginradius preparing for the third party cookie phase out permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How is LoginRadius Preparing for the Third-party Cookie Phase-out?</h2>\n<p>Firstly, we’re committed to solving our customers' user identity pain points — and preparing for the third-party cookies phase-out is no different.</p>\n<p>We’ll implement the most relevant and widely useful solutions to facilitate a smooth transition for our customers.</p>\n<p>Please subscribe to our blog for more information. We’ll update you on how we help with the third-party cookie phase-out.</p>\n<h2 id=\"in-conclusion\" style=\"position:relative;\"><a href=\"#in-conclusion\" aria-label=\"in conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>In Conclusion</h2>\n<p>The proposed changes to phase out third-party cookies and suggested alternatives are evolving as Google has been actively collaborating and discussing changes with the border community.</p>\n<p>Moreover, browsers like Firefox, Safari, and Edge may approach restricting third-party cookies differently than Google does.</p>\n<p>From LoginRadius, we’ll keep you updated on what we’re doing as a leading Customer Identity and Access Management (CIAM) vendor to prepare for the third-party cookie phase-out.</p>\n<h2 id=\"glossary\" style=\"position:relative;\"><a href=\"#glossary\" aria-label=\"glossary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Glossary</h2>\n<p><strong>Top-level site</strong>: It is the primary site a user has visited.</p>\n<p><strong>First-party cookie</strong>: A cookie set by the top-level site.</p>\n<p><strong>Third-party cookie</strong>: A cookie set by a domain other than the top-level site. For example, let’s assume that a user has visited <code>a.com</code>, which might use an embed from <code>loginradius.com</code> to facilitate authentication. If <code>loginradius.com</code> sets a cookie when the user visits <code>a.com</code>, it is called a third-party cookie as the user hasn’t directly visited <code>loginradius.com</code>.</p>\n<h2 id=\"references\" style=\"position:relative;\"><a href=\"#references\" aria-label=\"references permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>References</h2>\n<ul>\n<li><a href=\"https://developers.google.com/privacy-sandbox/3pcd/prepare/prepare-for-phaseout\">Changes to Chrome's treatment of third-party cookies</a></li>\n<li><a href=\"https://developers.google.com/privacy-sandbox/3pcd/guides/identity\">Check the impact of the third-party cookie changes on your sign-in workflows</a></li>\n</ul>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","frontmatter":{"date":"July 08, 2024","updated_date":null,"description":"Google Chrome has planned to phase out third-party cookies, which will affect different website functionalities depending on third-party cookies. This blog focuses on how this phase-out affects identity and user authentication and discusses alternatives for overcoming challenges.","title":"How Chrome’s Third-Party Cookie Restrictions Affect User Authentication?","tags":["Identity","Cookies","Chrome"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/eb7396060c0adc430dbed2d04b63d431/ee604/third-party-cookies-phaseout-chrome.png","srcSet":"/static/eb7396060c0adc430dbed2d04b63d431/69585/third-party-cookies-phaseout-chrome.png 200w,\n/static/eb7396060c0adc430dbed2d04b63d431/497c6/third-party-cookies-phaseout-chrome.png 400w,\n/static/eb7396060c0adc430dbed2d04b63d431/ee604/third-party-cookies-phaseout-chrome.png 800w,\n/static/eb7396060c0adc430dbed2d04b63d431/f3583/third-party-cookies-phaseout-chrome.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Raghunath Reddy","github":"raghunath-r-a","avatar":null}}}},"pageContext":{"limit":6,"skip":90,"currentPage":16,"type":"//engineering//","numPages":52,"pinned":"17fa0d7b-34c8-51c4-b047-df5e2bbaeedb"}},"staticQueryHashes":["1171199041","1384082988","2100481360","23180105","528864852"]}