<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>How To - TheCodeBuzz</title>
	<atom:link href="https://thecodebuzz.com/category/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>https://thecodebuzz.com</link>
	<description>Best Practices for Software Development</description>
	<lastBuildDate>Sun, 31 Dec 2023 03:39:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://thecodebuzz.com/wp-content/uploads/2022/11/cropped-android-chrome-512x512-1-1-51x51.jpg</url>
	<title>How To - TheCodeBuzz</title>
	<link>https://thecodebuzz.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Get File Size in C# .NET</title>
		<link>https://thecodebuzz.com/how-to-get-file-size-in-csharp/</link>
					<comments>https://thecodebuzz.com/how-to-get-file-size-in-csharp/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 20 Mar 2023 03:13:00 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=15813</guid>

					<description><![CDATA[<p>How to Get File Size in C# .NET In this article, we will see a simple way to Get File Size in C#.NET. We will be using a very useful class FileInfo available in C#.NET. We will cover below aspects, FileInfo class provides properties and instance methods while dealing with the file, Below is a [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/how-to-get-file-size-in-csharp/">How to Get File Size in C# .NET</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">How to Get File Size in C# .NET</h1>



<figure class="wp-block-image size-full is-resized"><a href="https://www.thecodebuzz.com/unit-test-mock-file-methods-csharp-netcore-design/"><img fetchpriority="high" decoding="async" width="595" height="516" src="https://www.thecodebuzz.com/wp-content/uploads/2022/02/c-get-file-size.jpg" alt="c# get file size , Get File Size in C#, Get File Size in C#.NET" class="wp-image-20877" srcset="https://thecodebuzz.com/wp-content/uploads/2022/02/c-get-file-size.jpg 595w, https://thecodebuzz.com/wp-content/uploads/2022/02/c-get-file-size-300x260.jpg 300w" sizes="(max-width: 595px) 100vw, 595px" /></a></figure>



<p>In this article, we will see a simple way to Get File Size in C#.NET. </p>



<p>We will be using a very useful class <strong><em>FileInfo </em></strong>available in C#.NET.</p>



<p></p>



<p>We will cover below aspects,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-c-get-file-size-in-bytes">C# Get file size in Bytes</a></li><li><a href="#aioseo-c-get-file-size-in-kb">C# Get file size in KB</a></li><li><a href="#aioseo-c-get-file-size-in-mb-or-gb">C# get file size in MB or GB</a></li></ul></div>



<p></p>



<p></p>



<p><strong><em>FileInfo </em></strong>class provides properties and instance methods while dealing with the file,</p>



<p></p>



<ul class="wp-block-list">
<li><strong>Directory </strong>&#8211; retrieves an object that represents the parent directory of a file.</li>



<li><strong>DirectoryName</strong> &#8211;  retrieves the full path of the parent directory of a file.</li>



<li><strong>Exists </strong>&#8211; checks for the presence of a file.</li>



<li><strong>IsReadOnly </strong>&#8211; gets or sets a value that specifies whether a file can be modified.</li>



<li><strong>Length </strong>-gets the size of a file.</li>



<li>The name&nbsp;gets the name of a file.</li>
</ul>



<p></p>



<p>Below is a sample method that will give you file size in bytes which you can convert to KB or MB size as required. </p>



<p></p>



<pre class="wp-block-preformatted"> 
static long GetFileSize(string FilePath)
        {
            if (File.Exists(FilePath))
            {
                return new FileInfo(FilePath).Length;
            }
            return 0;
        }
</pre>



<p></p>



<p><strong><em>FileInfo </em></strong>class has a length property that gives the size, in bytes, of the current file.</p>



<p></p>



<pre class="wp-block-preformatted">            int bytesRead;

            string filePath = @"C:\Test\File\file-input- 
            thecodebuzz.txt";


            long fileSizeibBytes = GetFileSize(filePath);
            </pre>



<p></p>



<h2 class="wp-block-heading" id="aioseo-c-get-file-size-in-bytes"> C# Get file size in Bytes</h2>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">long fileSizeibBytes = GetFileSize(filePath);
</pre>



<p></p>



<h2 class="wp-block-heading" id="aioseo-c-get-file-size-in-kb">C# Get file size in KB</h2>



<p></p>



<p> Below is an example to get file size in KB using C#,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">long fileSizeibKbs = fileSizeibBytes / 1024;</pre>



<p></p>



<h2 class="wp-block-heading" id="aioseo-c-get-file-size-in-mb-or-gb">C# get file size in MB or GB</h2>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">long fileSizeibMbs = fileSizeibBytes / (1024*1024);
</pre>



<p><strong><em>References </em></strong>:</p>



<p></p>



<ul class="has-medium-font-size wp-block-list">
<li><em><a href="https://www.thecodebuzz.com/unit-test-mock-file-methods-csharp-netcore-design/" target="_blank" rel="noreferrer noopener" title="Unit Test and Mock File methods – Guidelines">Unit Test and Mock File methods</a></em></li>
</ul>



<p></p>



<ul class="has-medium-font-size wp-block-list">
<li><em><a href="https://www.thecodebuzz.com/wp-admin/post.php?post=18874&amp;action=edit" target="_blank" rel="noreferrer noopener">Open file in browser instead of downloading</a></em></li>
</ul>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/how-to-get-file-size-in-csharp/">How to Get File Size in C# .NET</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/how-to-get-file-size-in-csharp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Curl POST JSON with examples &#8211; Guidelines</title>
		<link>https://thecodebuzz.com/post-json-data-curl-commands-get-post-examples/</link>
					<comments>https://thecodebuzz.com/post-json-data-curl-commands-get-post-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 04 Aug 2022 01:46:00 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[curl authorization header]]></category>
		<category><![CDATA[curl authorization header api key]]></category>
		<category><![CDATA[curl authorization header base64]]></category>
		<category><![CDATA[curl authorization header bearer]]></category>
		<category><![CDATA[curl authorization header bearer example]]></category>
		<category><![CDATA[curl example basic auth]]></category>
		<category><![CDATA[curl example post]]></category>
		<category><![CDATA[curl example post json]]></category>
		<category><![CDATA[curl example post with body]]></category>
		<category><![CDATA[curl json format]]></category>
		<category><![CDATA[curl post data from file]]></category>
		<category><![CDATA[CURL post example]]></category>
		<category><![CDATA[curl post example basic authentication]]></category>
		<category><![CDATA[curl post file]]></category>
		<category><![CDATA[Curl POST JSON]]></category>
		<category><![CDATA[curl post json file as body]]></category>
		<category><![CDATA[curl post json file windows]]></category>
		<category><![CDATA[curl post json multiline]]></category>
		<category><![CDATA[curl post json with username and password]]></category>
		<category><![CDATA[curl post with username and password]]></category>
		<category><![CDATA[java curl post json example]]></category>
		<category><![CDATA[post curl example]]></category>
		<category><![CDATA[POST JSON data with CURL]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=17817</guid>

					<description><![CDATA[<p>Curl POST JSON command examples- Guidelines Today in this article, we shall see how to execute the Curl POST JSON command. CURL is a tool to transfer data from or to a server, using different types of protocol protocols. Today we shall cover below basic scenarios of using curl commands, Curl POST JSON with string [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/post-json-data-curl-commands-get-post-examples/">Curl POST JSON with examples – Guidelines</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading"><strong>Curl POST JSON command examples- Guidelines</strong></h1>



<figure class="wp-block-image size-large is-resized"><img decoding="async" width="944" height="469" src="https://www.thecodebuzz.com/wp-content/uploads/2021/08/POST-JSON-data-with-CURL-commands.jpg" alt="curl post json command, Curl JWT,CURL JWT" class="wp-image-17845" style="width:554px;height:275px" srcset="https://thecodebuzz.com/wp-content/uploads/2021/08/POST-JSON-data-with-CURL-commands.jpg 944w, https://thecodebuzz.com/wp-content/uploads/2021/08/POST-JSON-data-with-CURL-commands-300x149.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/08/POST-JSON-data-with-CURL-commands-768x382.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/08/POST-JSON-data-with-CURL-commands-785x390.jpg 785w" sizes="(max-width: 944px) 100vw, 944px" /></figure>



<p>Today in this article, we shall see how to execute the Curl POST JSON command.</p>



<p></p>



<p><strong>CURL </strong>is a tool to transfer data from or to a server, using different types of protocol protocols. </p>



<p></p>



<p></p>



<p>Today we shall cover below basic scenarios of using curl commands,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-curl-post-json-with-string-request">Curl POST JSON with string request</a></li><li><a href="#aioseo-curl-post-with-json-request">Curl POST JSON request</a></li><li><a href="#aioseo-curl-post-using-basic-authentication">CURL POST JSON using Basic Authentication</a></li><li><a href="#aioseo-curl-jwt-bearer-authentication">CURL JWT Bearer Authentication</a></li></ul></div>



<p></p>



<h2 class="wp-block-heading" id="aioseo-curl-post-json-with-string-request">Curl POST JSON with string request </h2>



<p></p>



<p><strong>Command :</strong></p>



<p></p>



<p>Post example with string object as request body</p>



<p></p>



<pre id="block-72fb6619-7bcf-4b8a-8e3b-0a5ca8fccacd" class="wp-block-preformatted has-medium-font-size">curl -X POST "your-post-url" -H "accept: text/plain" -H "Content-Type: application/json" -d "\"your string request data\""</pre>



<p></p>



<p>In the above command,</p>



<p></p>



<p id="block-7e0d7033-ccd4-44ab-99b3-cee8d6555be1"><em><code>-X</code>&nbsp;&#8212;-&gt; The HTTP verb indicating operation is GET, POST, PUT or DELETE, etc </em></p>



<p id="block-7e0d7033-ccd4-44ab-99b3-cee8d6555be1"><em><br>&#8211;<code>d or --data</code>&nbsp; &#8212;-&gt; the data you want to send. </em></p>



<p></p>



<p><strong><em>Exampl</em>e 1</strong></p>



<p></p>



<p>Above we are passing <strong><em>String object </em></strong>as a request body.</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">curl -X POST "https://localhost:44341/api/Values" -H "accept: text/plain" -H "Content-Type: application/json" -d "\"kjhlkjlj\""
</pre>



<p></p>



<h2 class="wp-block-heading" id="aioseo-curl-post-with-json-request">Curl POST JSON request</h2>



<p></p>



<p><em><strong>Example2</strong></em></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">curl -X POST "https://localhost:44341/api/Values" -H "accept: text/plain" -H "Content-Type: application/json" -d '{"key1":"value1", "key2":"value2"}'
</pre>



<p></p>



<p>Above we are passing JSON data as the request body parameter.</p>



<p></p>



<p>The response header is as below,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size"> access-control-allow-origin: * 
 content-type: text/plain; charset=utf-8 
 date: Fri, 24 Jan 2020 00:30:12 GMT 
 server: Microsoft-IIS/10.0 
 transfer-encoding: chunked 
 x-powered-by: ASP.NET </pre>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-curl-post-using-basic-authentication">CURL POST JSON using Basic Authentication</h2>



<p></p>



<p>Below is a simple command which you can use against API or service which expects Basic Authentication credentials.</p>



<p></p>



<p><strong><em>Command:</em></strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size"><em>curl -X POST "&lt;URL&gt;" -H "accept: text/plain" -H "Authorization: Basic &lt;TOKEN&gt;"</em></pre>



<p></p>



<p><strong><em>Example:</em></strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">curl -X POST "https://localhost:44378/Accounts" -H "accept: text/plain" -H "Authorization: Basic ZGZzZGY6c2Rmcw=="
</pre>



<p>I have executed the commands using Git Bash shell,</p>



<p></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="137" src="https://www.thecodebuzz.com/wp-content/uploads/2020/05/Testing-REST-API-Services-using-CURL-Basic-authentication-1024x137.jpg" alt="POST JSON data with CURL,Curl POST JSON command" class="wp-image-10648" srcset="https://thecodebuzz.com/wp-content/uploads/2020/05/Testing-REST-API-Services-using-CURL-Basic-authentication-1024x137.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2020/05/Testing-REST-API-Services-using-CURL-Basic-authentication-300x40.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2020/05/Testing-REST-API-Services-using-CURL-Basic-authentication-768x103.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2020/05/Testing-REST-API-Services-using-CURL-Basic-authentication-1536x205.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2020/05/Testing-REST-API-Services-using-CURL-Basic-authentication-2048x274.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2020/05/Testing-REST-API-Services-using-CURL-Basic-authentication-785x105.jpg 785w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p>One can also pass username and password in the format <strong><em>-u username: password</em></strong> which gets translated to Bas64 string.</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-curl-jwt-bearer-authentication">CURL JWT Bearer Authentication</h2>



<p></p>



<p>Below is a basic command which you can run use against API or service which expects <em><strong><a href="https://www.thecodebuzz.com/jwt-authentication-in-asp-net-core-3-0-with-examples/" target="_blank" rel="noreferrer noopener" title="JWT Authentication in ASP.NET Core with examples">JWT Bearer authentication credential</a>. </strong></em></p>



<p></p>



<p><strong><em>Command:</em></strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">curl -X POST "https://localhost:44341/api/Values" -H "accept: text/plain" -H "Authorization: Bearer &lt;token&gt;</pre>



<p></p>



<p><strong><em>Example:</em></strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">curl -X POST "https://localhost:44341/api/Values" -H "accept: text/plain" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1Nzk4MzkzODksImlzcyI6Imh0dHBzOi8vbG9jYWxob3N0OjQ0MzQxIiwiYXVkIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6NDQzNDEifQ.6UTixm8bekorxcw0lL8x-mBkNVaIK003LzMtkuIhasZ8"

</pre>



<p><strong><em>References: </em></strong></p>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/restful-api-url-naming-conventions-best-practices/" target="_blank" rel="noreferrer noopener" title="Testing REST API/Services using CURL Command Line"><em>Testing REST API/Services using CURL Command Line</em> </a></li>
</ul>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/restful-api-url-naming-conventions-best-practices/" target="_blank" rel="noreferrer noopener" title="Testing REST API/Services using CURL Command Line"><em>RESTFul API Naming Conventions</em></a></li>
</ul>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/post-json-data-curl-commands-get-post-examples/">Curl POST JSON with examples – Guidelines</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/post-json-data-curl-commands-get-post-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Add/Hide OpenAPI Swagger based on Environment (DEV, TEST, PROD)</title>
		<link>https://thecodebuzz.com/add-openapi-swagger-based-on-environment-dev-test-prod/</link>
					<comments>https://thecodebuzz.com/add-openapi-swagger-based-on-environment-dev-test-prod/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 01 Jul 2022 22:30:00 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[customize swagger ui .net core]]></category>
		<category><![CDATA[disable swagger in production]]></category>
		<category><![CDATA[exclude controller from swagger]]></category>
		<category><![CDATA[hide api from swagger c#]]></category>
		<category><![CDATA[hide controller from swagger]]></category>
		<category><![CDATA[hide controller from swagger c#]]></category>
		<category><![CDATA[hide endpoint from swagger]]></category>
		<category><![CDATA[hide methods from swagger]]></category>
		<category><![CDATA[hide swagger methods]]></category>
		<category><![CDATA[how to hide controller in swagger]]></category>
		<category><![CDATA[remove swagger routes]]></category>
		<category><![CDATA[restrict access to swagger ui net core]]></category>
		<category><![CDATA[show only specific apis on swagger]]></category>
		<category><![CDATA[springdoc-openapi-ui disable in production]]></category>
		<category><![CDATA[swagger configuration c web api]]></category>
		<category><![CDATA[swagger disable try it out]]></category>
		<category><![CDATA[swagger hide api]]></category>
		<category><![CDATA[swagger hide endpoint]]></category>
		<category><![CDATA[swagger ignore]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=13715</guid>

					<description><![CDATA[<p>Add/Hide OpenAPI Swagger based on Environment (DEV, TEST, PROD) Today in this article, We shall see how to enable Swagger OpenAPI documentation and Add/Hide OpenAPI Swagger based on Environment (DEV, TEST, PROD) You might get this requirement on a few occasions where you may want to control the display of API methods based on the [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/add-openapi-swagger-based-on-environment-dev-test-prod/">Add/Hide OpenAPI Swagger based on Environment (DEV, TEST, PROD)</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">Add/Hide OpenAPI Swagger based on Environment (DEV, TEST, PROD)</h1>



<figure class="wp-block-image"><img decoding="async" src="https://www.thecodebuzz.com/wp-content/uploads/2020/12/Add-OpenAPI-Swagger-based-on-environment-asp.net-core-like-DEV-TEST-etc-.NET-5-1024x468.jpg" alt="remove swagger routes" class="wp-image-13722"/></figure>



<p>Today in this article, We shall see how to enable Swagger OpenAPI documentation and Add/Hide OpenAPI Swagger based on Environment (DEV, TEST, PROD)</p>



<p></p>



<p>You might get this requirement on a few occasions where you may want to control the display of API methods based on the environment example <strong><em>DEV, TEST, PROD. </em></strong></p>



<p></p>



<p>There could be multiple requirements like hide or exclude routes API, endpoint, or Controller for Swagger OpenAPI documentation based on the environment your API running.</p>



<p></p>



<p>This customization could be of use to many of you as swagger is not just an API description tool. </p>



<p></p>



<p>It also allows you to test any of your APIs by passing inputs and getting the required results.</p>



<p></p>



<p>Today in this article, we will cover below aspects,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-create-asp-net-core-api">Create ASP.NET Core API</a></li><li><a href="#aioseo-add-swashbuckle-aspnetcore-nuget-package">Add Swashbuckle.AspNetCore NuGet package</a></li><li><a href="#aioseo-adding-idocumentfilter-implementation">Adding IDocumentFilter implementation</a></li><li><a href="#aioseo-remove-or-hide-api-routes-from-swagger-api-definition">Remove or Hide API routes from the Swagger API definition</a></li><li><a href="#aioseo-update-configureservices-method">Update ConfigureServices() method</a></li><li><a href="#aioseo-enabling-custom-attributes-on-method-or-controller">Enabling Custom Attributes on Method or Controller</a></li><li><a href="#aioseo-feature-toggle-for-swagger-routes">Feature Toggle for swagger routes</a></li></ul></div>



<p></p>



<p>Today we will control how to display API based on a selected environment i.e. if you are running your swagger in the “TEST” environment then it will not display API that is in DEV or in progress and not meant to be used in a higher environment.</p>



<p></p>



<p></p>



<p>ASP.NET Core uses&nbsp;<em><strong>OpenAPI V3.0</strong></em>&nbsp;specifications which are guidelines and specifications around how the API documentation should be.</p>



<p></p>



<p>In today’s article, we shall cover below,</p>



<p></p>



<ul class="wp-block-list">
<li><em><strong>Adding OpenAPI V3 documentation specification to API</strong></em></li>
</ul>



<p></p>



<ul class="wp-block-list">
<li><strong><em>Enabling&nbsp;</em>Swagger based on the Environment</strong></li>
</ul>



<p></p>



<h2 class="wp-block-heading" id="aioseo-create-asp-net-core-api">Create ASP.NET Core API</h2>



<p></p>



<p>Create ASP.NET Core 3.1 or .NET 5.0 API</p>



<p></p>



<figure class="wp-block-image"><img decoding="async" src="https://www.thecodebuzz.com/wp-content/uploads/2020/12/Add-OpenAPI-Swagger-based-on-environment-1024x498.jpg" alt="exclude controller from swagger, hide api from swagger c#" class="wp-image-13713"/></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-add-swashbuckle-aspnetcore-nuget-package">Add Swashbuckle.AspNetCore NuGet package</h2>



<p></p>



<p>Please add below Nuget package to your API using a <strong><em>Command prompt or PMC(package manager console) or Nuget Package Manager</em></strong></p>



<p></p>



<pre class="wp-block-preformatted">PM&gt; Install-Package Swashbuckle.AspNetCore -Version 5.6.3
</pre>



<p><strong>Note</strong>: Please use the version to the latest available.</p>



<p></p>



<p>This&nbsp;<strong>NuGet package</strong>&nbsp;shall add all other required components as shown below and you need not have to add them explicitly,</p>



<p></p>



<ul class="wp-block-list">
<li><strong>Swashbuckle.AspNetCore.SwaggerUI</strong></li>



<li><strong>Swashbuckle.AspNetCore.Swagger</strong></li>



<li><strong>Swashbuckle.AspNetCore.SwaggerGen</strong></li>
</ul>



<p></p>



<p>Let’s talk about a simple scenario where I have new API development going on and that API swagger definition I don’t want to be available to the TEST region yet.</p>



<p></p>



<p>Below are the two APIs that I would like to control the display based on the environment.</p>



<p></p>



<p><em>Let’s assume below the sample API route and I have already released it for DEV and then moved it to TEST environment.</em></p>



<p></p>



<pre class="wp-block-code"><code>        &#91;HttpGet]
        &#91;Route("US")]
        public IEnumerable&lt;WeatherForecastUS> GetWatherUSA()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new 
             WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries&#91;rng.Next(Summaries.Length)]
            })
            .ToArray();
        }</code></pre>



<p>       </p>



<p>Now let&#8217;s assume, I have a new route as below for UK which I would like to display for DEV alone but not the<strong><em> TEST or PROD</em></strong> region.</p>



<p>      </p>



<pre class="wp-block-code"><code>        &#91;HttpGet]
        &#91;Route("UK")]
        public IEnumerable&lt;WeatherForecastUK> GetWeatherUK()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new 
            WeatherForecastNew
            {
                DateOfForcast = DateTime.Now.AddDays(index),
                Temperature = rng.Next(-20, 55),
                Summary = Summaries&#91;rng.Next(Summaries.Length)]
            })
            .ToArray();
        }</code></pre>



<p></p>



<p>Currently, you shall<em><strong>&nbsp;see the swagger API&nbsp;</strong></em>definition generated as below,</p>



<p></p>



<figure class="wp-block-image"><img decoding="async" src="https://www.thecodebuzz.com/wp-content/uploads/2020/12/Add-OpenAPI-Swagger-based-on-environment-asp.net-core-1024x449.jpg" alt="hide route from swagger c#, hide controller from swagger, " class="wp-image-13714"/></figure>



<p></p>



<p>Please see the below article on enabling basic Swagger API documentation,</p>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/swagger-api-documentation-in-net-core-3-0/" target="_blank" rel="noreferrer noopener"><strong><em>Add Swagger API Documentation in ASP.NET Core 3.1</em></strong></a></li>
</ul>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-adding-idocumentfilter-implementation">Adding IDocumentFilter implementation</h2>



<p></p>



<p>Please add the&nbsp;<strong><em>IDocumentFilter</em></strong>&nbsp;implementation as below,</p>



<p></p>



<pre class="wp-block-preformatted">public class CustomEnviornmentFilter : IDocumentFilter
    {

        public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
        {
// Add your implementation here 
        }
      }
</pre>



<p></p>



<p>Below is the complete implementation for&nbsp;<em><strong>Apply&nbsp;</strong></em>method,</p>



<p></p>



<figure class="wp-block-image"><img decoding="async" src="https://www.thecodebuzz.com/wp-content/uploads/2020/12/Add-OpenAPI-Swagger-based-on-environment-asp.net-core-like-DEV-TEST-etc-1024x913.jpg" alt="Add/Hide OpenAPI Swagger based on Environment (DEV, TEST, PROD)" class="wp-image-13715"/></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-remove-or-hide-api-routes-from-swagger-api-definition">Remove or Hide API routes from the Swagger API definition</h2>



<p></p>



<p>Below is the implementation for removing the required routes from&nbsp;<strong><em>API&nbsp;</em></strong>documentation.</p>



<p></p>



<pre class="wp-block-code"><code>private static void RemoveOtherRoutes(OpenApiDocument swaggerDoc, string kepath)
        {
            var removeRoutes = swaggerDoc.Paths.Where(
                               x => x.Key.ToLower().Contains(kepath.ToLower()))
                                .ToList();
            removeRoutes.ForEach(x => { swaggerDoc.Paths.Remove(x.Key); });
        }</code></pre>



<pre class="wp-block-preformatted"></pre>



<h2 class="wp-block-heading" id="aioseo-update-configureservices-method">Update ConfigureServices() method</h2>



<p></p>



<p>You need to enable the above CustomDocument filter within&nbsp;<em><strong>AddSwaggerGen</strong></em>,</p>



<p></p>



<pre class="wp-block-preformatted"> c.DocumentFilter&lt;CustomEnviornmentFilter&gt;();
</pre>



<p>Please <a href="http://Add Swagger API Documentation in ASP.NET Core 3.1" target="_blank" rel="noreferrer noopener">here </a>for more details on the configuration.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-enabling-custom-attributes-on-method-or-controller">Enabling Custom Attributes on Method or Controller</h2>



<p></p>



<p>I see custom attribute annotation as the easiest way of managing the method environment.</p>



<p></p>



<p>Let’s create three Custom Attributes for&nbsp;<strong><em>Dev , Test and Prod</em></strong>&nbsp;as below,</p>



<p></p>



<pre class="wp-block-preformatted">    /// &lt;summary&gt;
    /// 
    /// &lt;/summary&gt;
    public class DevApiAttribute : ActionFilterAttribute
    {

    }

    /// &lt;summary&gt;
    /// 
    /// &lt;/summary&gt;
    public class TestApiAttribute : ActionFilterAttribute
    {
    }

    /// &lt;summary&gt;
    /// 
    /// &lt;/summary&gt;
    public class ProdApiAttribute : ActionFilterAttribute
    {
    }
</pre>



<p></p>



<p>Next, you need to just enable these attributes for each Controller or API route to specify the environment.</p>



<p></p>



<p></p>



<figure class="wp-block-image"><img decoding="async" src="https://www.thecodebuzz.com/wp-content/uploads/2020/12/Add-OpenAPI-Swagger-based-on-environment-asp.net-core-like-DEV-TEST-PROD-etc-992x1024.jpg" alt="swagger hide api, swagger hide endpoint" class="wp-image-13719"/></figure>



<p></p>



<p>Let’s execute the Swagger definition in&nbsp;<strong><em>DEV</em></strong>&nbsp;environment,</p>



<p></p>



<figure class="wp-block-image"><img decoding="async" src="https://www.thecodebuzz.com/wp-content/uploads/2020/12/Add-OpenAPI-Swagger-for-DEV-TEST-PROD-1024x399.jpg" alt="" class="wp-image-13720"/></figure>



<p></p>



<p>That&#8217;s all, with the above arrangements, the above routes for&nbsp;<strong><em>TEST or PROD&nbsp;</em></strong>will be removed/hidden from generated swagger documentation.</p>



<p></p>



<p>I found this way we get better control on what API to show or hide.</p>



<p></p>



<p>The above settings can be applied at the <strong><em>Controller </em></strong>or Individual <strong><em>method/route</em></strong> level. </p>



<p>Likewise please decorate your Routes/Methods or Controller as required.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-feature-toggle-for-swagger-routes">Feature Toggle for swagger routes</h2>



<p></p>



<p>The above way of hiding or removing the swagger route will also resemble feature toggling. </p>



<p></p>



<p>The good thing about this approach is you can very much integrate this logic with your existing feature toggle architecture if any.</p>



<p></p>



<p></p>



<ul class="wp-block-list" id="block-46f4148b-5ec6-424d-bcaa-52e6f9547046">
<li><strong><em><a href="https://www.thecodebuzz.com/swagger-api-documentation-in-net-core-2-2/" target="_blank" rel="noreferrer noopener">Add Swagger API documentation to .NET Core 2.2</a></em></strong></li>



<li><strong><em><a rel="noreferrer noopener" href="https://www.thecodebuzz.com/swagger-api-documentation-in-net-core-3-0/" target="_blank">Swagger API Documentation in .NET Core 3.1</a></em></strong></li>
</ul>



<p></p>



<p>Do you have any comments or suggestions or any better approach to deal with this?</p>



<p></p>



<p>Please sound off your comments below.</p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/add-openapi-swagger-based-on-environment-dev-test-prod/">Add/Hide OpenAPI Swagger based on Environment (DEV, TEST, PROD)</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/add-openapi-swagger-based-on-environment-dev-test-prod/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MongoDB Regex Like query pattern -Guidelines</title>
		<link>https://thecodebuzz.com/mongodb-regex-like-query-case-sensitive-pattern/</link>
					<comments>https://thecodebuzz.com/mongodb-regex-like-query-case-sensitive-pattern/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 07 Apr 2022 00:50:00 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Mongo]]></category>
		<category><![CDATA[Like query using Regex]]></category>
		<category><![CDATA[mongodb like query case-insensitive]]></category>
		<category><![CDATA[mongodb like query java]]></category>
		<category><![CDATA[mongodb like query node js]]></category>
		<category><![CDATA[mongodb like query php]]></category>
		<category><![CDATA[mongodb like query python]]></category>
		<category><![CDATA[mongodb string contains]]></category>
		<category><![CDATA[mongodb text search regex]]></category>
		<category><![CDATA[spring data mongodb like query]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=14367</guid>

					<description><![CDATA[<p>MongoDB Regex Like Query pattern &#8211; II Today in this article, we shall see how to write MongoDB Regex Like query ( resembles SQL &#8216;like&#8217; query) using regex pattern with case sensitive and insensitive search with examples. Today in this article, we will cover below aspects, I shall be explaining the queries using the like [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/mongodb-regex-like-query-case-sensitive-pattern/">MongoDB Regex Like query pattern -Guidelines</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">MongoDB Regex Like Query pattern &#8211; II</h1>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="292" src="https://www.thecodebuzz.com/wp-content/uploads/2022/02/mongodb-like-query-regex-1024x292.jpg" alt="MongoDB Like query Regex" class="wp-image-20873" srcset="https://thecodebuzz.com/wp-content/uploads/2022/02/mongodb-like-query-regex-1024x292.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2022/02/mongodb-like-query-regex-300x86.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2022/02/mongodb-like-query-regex-768x219.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/02/mongodb-like-query-regex-1536x438.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2022/02/mongodb-like-query-regex-785x224.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2022/02/mongodb-like-query-regex.jpg 1633w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Today in this article, we shall see how to write MongoDB Regex Like query ( resembles SQL &#8216;like&#8217; query) using<strong><em> regex pattern </em></strong>with <strong><em>case sensitive</em></strong> and <em><strong>insensitive</strong></em> search with examples.</p>



<p>Today in this article, we will cover below aspects,</p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-scenarios-1---mongodb-regex-query-with-like">Scenarios 1 &#8211; MongoDB Regex Query with Like</a></li><li><a href="#aioseo-scenarios-2--mongodb-regex-query-with-like-that-start-with-criteria">Scenarios 2 – MongoDB Regex Query with ‘Like’ that start with criteria</a></li><li><a href="#aioseo-scenarios-3--regex-end-with-match-mongo-query">Scenarios 3 – Regex End with match Mongo Query</a></li><li><a href="#aioseo-scenarios-4--regex-exact-match-mongo-query">Scenarios 4 – Regex Exact Match Mongo Query</a></li></ul></div>



<p>I shall be explaining the queries using the like query in MongoDB Shell. If you are interested to refer a <strong>mongo query without Regex</strong>, please refer to the article below,</p>



<p></p>



<ul class="wp-block-list"><li><a href="https://www.thecodebuzz.com/mongodb-query-with-like-start-with-or-end-with-guidelines/" target="_blank" rel="noreferrer noopener" title="MongoDB Query with ‘Like’ – Guidelines"><em><strong>MongoDB ‘Like’ Q</strong></em></a><em><strong><a href="https://www.thecodebuzz.com/mongodb-query-with-like-start-with-or-end-with-guidelines/" target="_blank" rel="noreferrer noopener" title="MongoDB Query with ‘Like’ – Guidelines">u</a></strong></em><a href="https://www.thecodebuzz.com/mongodb-query-with-like-start-with-or-end-with-guidelines/" target="_blank" rel="noreferrer noopener" title="MongoDB Query with ‘Like’ – Guidelines"><em><strong>ery pattern -Part 1</strong></em></a></li></ul>



<p></p>



<p>I have a sample <em><strong>MongoDB </strong></em>document below in one of the collections. Here we shall be trying to search all the documents using a MongoDB-like query</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
&#x5B;
  {
    &quot;_id&quot;: &quot;5db5a4476997188b2722c820&quot;,
    &quot;Name&quot;: &quot;Design Patterns&quot;,
    &quot;Price&quot;: 54.93,
    &quot;Category&quot;: &quot;Computers&quot;,
    &quot;Author&quot;: &quot;Ralph Johnson&quot;
  },
  {
    &quot;_id&quot;: &quot;5ff50353a29ce9564c2724e2&quot;,
    &quot;Name&quot;: &quot;Design Patterns&quot;,
    &quot;Price&quot;: 54.93,
    &quot;Category&quot;: &quot;Computers&quot;,
    &quot;Author&quot;: &quot;Mike Casper&quot;
  },
  {
    &quot;_id&quot;: &quot;5ff503cda29ce9564c2724e3&quot;,
    &quot;Name&quot;: &quot;Design Patterns&quot;,
    &quot;Price&quot;: 54.93,
    &quot;Category&quot;: &quot;Computers&quot;,
    &quot;Author&quot;: &quot;TheCodeBuzz&quot;
  }
 {
    &quot;_id&quot;: &quot;45b5a4476543188b2722c34550&quot;,
    &quot;Name&quot;: &quot;Design Patterns- II&quot;,
    &quot;Price&quot;: 60.93,
    &quot;Category&quot;: &quot;Computers&quot;,
    &quot;Author&quot;: &quot;Ralph johnson&quot;
  },
]
</pre></div>


<p></p>



<h2 class="wp-block-heading" id="aioseo-scenarios-1---mongodb-regex-query-with-like"><em>Scenarios 1</em> &#8211; MongoDB Regex Query with Like</h2>



<p></p>



<p>Let&#8217;s build MongoDB-like query using a regex for getting <strong><em>Author </em></strong>names where the name contains a word like <strong><em>&#8220;J&#8221;</em></strong> or &#8220;j&#8221; for the Author field.</p>



<p></p>



<p><strong><em>Assumptions: </em></strong></p>



<p></p>



<p><em><strong>&#8220;J&#8221;</strong> or &#8220;j&#8221; could be contained</em> at the <em><strong>start </strong>or <strong>last </strong>or in the </em><strong>middle </strong><em>or <strong>anywhere </strong>else of Author names</em>.</p>



<p></p>



<p><strong><em>Query pattern</em></strong></p>



<p></p>



<p><strong><em>MongoDB regex query with case-sensitive search</em></strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">{ Field Name: {'$regex' : 'string'}}</pre>



<p></p>



<p><strong><em>MongoDB regex query with case insensitive search</em></strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">{ Field Name: {'$regex' : 'string', '$options' : 'i'}}</pre>



<p></p>



<p><strong><em>Example Query 1</em></strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">db.Books.find({Author:{'$regex' : 'J'}})</pre>



<p></p>



<p><strong>Mongo Query Result :</strong></p>



<p></p>



<pre class="wp-block-preformatted">   db.Books.find({Author:{'$regex' : 'J'}})
   { "_id" : ObjectId("5db5a4476997188b2722c820"), "Name" : "Design Patterns", "Price" : 54.93, "Category" : "Computers", "Author" : "Ralph Johnson" }
   { "_id" : ObjectId("5ff503cda29ce9564c2724e3"), "Name" : "Code Refactoring", "Price" : 43.15, "Category" : "Computers", "Author" : "Julia Robert" } </pre>



<p></p>



<pre class="wp-block-preformatted">db.Books.find({Author:{'$regex' : 'j'}})
 { "_id" : ObjectId("5f34a2430c3ca98a8c9052d2"), "Name" : "Design Patterns", "Price" : 54.93, "Category" : "Computers", "Author" : "Ralph johnson" }
</pre>



<p><strong><em>Example Query </em>2</strong> &#8211; <strong><em>Case insensitiv</em>e</strong></p>



<p></p>



<p>Let&#8217;s now use <strong><em>case insensitiv</em>e </strong>query using $options,</p>



<p></p>



<pre id="block-ade62a2b-4fce-4721-82ca-2f9d431b739b" class="wp-block-preformatted has-medium-font-size">{ Author:{'$regex' : 'J', '$options' : 'i'}
</pre>



<p></p>



<p><strong>Mongo Query Result :</strong></p>



<p></p>



<p>Below is the query for like in MongoDB</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">  &gt; db.Books.find({Author:{'$regex' : 'J', '$options' : 'i'}})
   { "_id" : ObjectId("5db5a4476997188b2722c820"), "Name" : "Design Patterns", "Price" : 54.93, "Category" : "Computers", "Author" : "Ralph Johnson" }
   { "_id" : ObjectId("5f34a2430c3ca98a8c9052d2"), "Name" : "Design Patterns", "Price" : 54.93, "Category" : "Computers", "Author" : "Ralph johnson" }
   { "_id" : ObjectId("5ff503cda29ce9564c2724e3"), "Name" : "Code Refactoring", "Price" : 43.15, "Category" : "Computers", "Author" : "Julia Robert" } </pre>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="175" src="https://www.thecodebuzz.com/wp-content/uploads/2021/01/how-to-query-mongodb-with-like-using-regex-1024x175.jpg" alt="mongodb like query mongodb find like" class="wp-image-14382" srcset="https://thecodebuzz.com/wp-content/uploads/2021/01/how-to-query-mongodb-with-like-using-regex-1024x175.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/01/how-to-query-mongodb-with-like-using-regex-300x51.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/01/how-to-query-mongodb-with-like-using-regex-768x131.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/01/how-to-query-mongodb-with-like-using-regex-1536x263.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/01/how-to-query-mongodb-with-like-using-regex-2048x351.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2021/01/how-to-query-mongodb-with-like-using-regex-785x134.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-scenarios-2--mongodb-regex-query-with-like-that-start-with-criteria"><em>Scenarios&nbsp;</em>2 – MongoDB Regex Query with ‘Like’ that&nbsp;<em>start with</em>&nbsp;criteria</h2>



<p></p>



<p>Let’s build a query to get the list of items that start with some search criteria.&nbsp;<strong><em>Example&nbsp;</em></strong><em><strong>“Ro”</strong></em>&nbsp;for Author field.</p>



<p></p>



<p><strong><em>Query pattern</em></strong></p>



<pre class="wp-block-preformatted has-medium-font-size">{ Field Name : /^Ro/ }


Where Ro is your search cretieria.</pre>



<p></p>



<p><strong><em>Example Query </em></strong></p>



<p></p>



<pre id="block-8bafb9c5-f55c-47e0-ad4f-65962f593bbc" class="wp-block-preformatted has-medium-font-size"><strong>{ Author :{'$regex' : '^Ro', '$options' : 'i'}})</strong>
</pre>



<p><strong><em>Search Result:</em></strong></p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="71" src="https://www.thecodebuzz.com/wp-content/uploads/2021/01/mongodb-regex-query-start-with-query-1024x71.jpg" alt="mongodb like" class="wp-image-14385" srcset="https://thecodebuzz.com/wp-content/uploads/2021/01/mongodb-regex-query-start-with-query-1024x71.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/01/mongodb-regex-query-start-with-query-300x21.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/01/mongodb-regex-query-start-with-query-768x54.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/01/mongodb-regex-query-start-with-query-1536x107.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/01/mongodb-regex-query-start-with-query-2048x143.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2021/01/mongodb-regex-query-start-with-query-785x55.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-scenarios-3--regex-end-with-match-mongo-query"><em>Scenarios&nbsp;</em>3 – Regex End with match Mongo Query</h2>



<p></p>



<p>Let’s build a query to Get the list of items that ends with some search criteria.&nbsp;<strong><em>Example&nbsp;</em></strong><em><strong>“rt”</strong></em>&nbsp;for Author field</p>



<p></p>



<p><strong><em>Query pattern</em></strong></p>



<p></p>



<p class="has-medium-font-size">{ Field Name : { &#8216;$regex&#8217; :  &#8216;robert$&#8217; ,  &#8216;$options&#8217; : &#8216;i&#8217; } }</p>



<p></p>



<p><strong>Where </strong>&#8216;robert&#8217; is your search criteria </p>



<p></p>



<p><strong><em>Example Query</em></strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">{ Author :{'$regex' : 'robert$', '$options' : 'i'}}
</pre>



<p><strong><em>Mongo Shell results,</em></strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">   &gt; db.Books.find({ Author :{'$regex' : 'robert$', '$options' : 'i'}})
   { "_id" : ObjectId("5ff503cda29ce9564c2724e3"), "Name" : "Code Refactoring", "Price" : 43.15, "Category" : "Computers", "Author" : "Julia Robert" } </pre>



<p>Above query, we have Author “Julia Robert” that matches with search criteria.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-scenarios-4--regex-exact-match-mongo-query"><em>Scenarios&nbsp;</em>4 – Regex Exact Match Mongo Query</h2>



<p></p>



<p>Let&#8217;s look into Regex Exact Match Mongo Query.</p>



<p></p>



<p><strong><em>Query pattern</em></strong></p>



<p></p>



<p>{ Field Name : { &#8216;$regex&#8217; :  &#8216;robert$&#8217; ,  &#8216;$options&#8217; : &#8216;i&#8217; } }</p>



<p></p>



<p><strong>Where </strong>&#8216;robert&#8217; is your search criteria </p>



<p></p>



<p><strong><em>Example Query</em></strong>:</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">{ Author :{'$regex' : '^julia robert$', '$options' : 'i'}}</pre>



<p></p>



<p>Where &#8216;julia robert&#8217; is our exact search criteria. Here Author field value has to match exactly (but <strong><em>case insensitive</em></strong> )</p>



<p></p>



<p><strong><em>Mongo Shell results,</em></strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">   &gt; db.Books.find({ Author :{'$regex' : 'robert$', '$options' : 'i'}})
   { "_id" : ObjectId("5ff503cda29ce9564c2724e3"), "Name" : "Code Refactoring", "Price" : 43.15, "Category" : "Computers", "Author" : "Julia Robert" } </pre>



<p></p>



<p>Above query, we have Author “Julia Robert” that matches with exact search criteria.</p>



<p></p>



<p><strong><em>References:</em></strong></p>



<p></p>



<ul class="wp-block-list"><li><a href="https://www.thecodebuzz.com/mongodb-query-with-like-start-with-or-end-with-guidelines/" target="_blank" rel="noreferrer noopener" title="MongoDB Query with ‘Like’ – Guidelines"><strong><em>MongoDB Query with ‘Like’ without Regex– Guidelines</em></strong></a></li></ul>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/mongodb-regex-like-query-case-sensitive-pattern/">MongoDB Regex Like query pattern -Guidelines</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/mongodb-regex-like-query-case-sensitive-pattern/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Resolved- No hosted parallelism has been purchased or granted</title>
		<link>https://thecodebuzz.com/resolved-no-hosted-parallelism-has-been-purchased-or-granted/</link>
					<comments>https://thecodebuzz.com/resolved-no-hosted-parallelism-has-been-purchased-or-granted/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 03 Jan 2022 02:32:00 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[azure devops no hosted parallelism]]></category>
		<category><![CDATA[azure devops parallel jobs yaml]]></category>
		<category><![CDATA[azure devops parallel stages]]></category>
		<category><![CDATA[azure devops parallelism request]]></category>
		<category><![CDATA[azure devops parallelism request form]]></category>
		<category><![CDATA[disable parallelism azure devops]]></category>
		<category><![CDATA[how to resolve "no hosted parallelism has been purchased or granted" in free tier?]]></category>
		<category><![CDATA[what is hosted parallelism]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=20051</guid>

					<description><![CDATA[<p>Resolved- No hosted parallelism has been purchased or granted Today in this article, we will cover below aspects, Azure Pipelines CI/CD pipeline configuration gives an error, ##[error]No hosted parallelism has been purchased or granted. To request a free parallelism grant, please fill out the following form https://aka.ms/azpipelines-parallelism-request Resolution: The issue I found to be recent [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/resolved-no-hosted-parallelism-has-been-purchased-or-granted/">Resolved- No hosted parallelism has been purchased or granted</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">Resolved- No hosted parallelism has been purchased or granted</h1>



<p>Today in this article, we will cover below aspects,</p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-resolution">Resolution:</a></li></ul></div>



<p>Azure Pipelines <strong><em>CI/CD pipeline configuration</em></strong> gives an error,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size"><span class="has-inline-color has-vivid-red-color">##[error]No hosted parallelism has been purchased or granted. To request a free parallelism grant, please fill out the following form https://aka.ms/azpipelines-parallelism-request</span>

</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="378" src="https://www.thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-1024x378.jpg" alt="##[error]No hosted parallelism has been purchased or granted." class="wp-image-20052" srcset="https://thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-1024x378.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-300x111.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-768x283.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-1536x566.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-2048x755.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-785x289.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-resolution">Resolution:</h2>



<p></p>



<p>The issue I found to be recent updates from <strong>Microsoft guidelines</strong> and best practices. </p>



<p></p>



<p>  <strong>Microsoft guidelines</strong>  </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>We have temporarily disabled the free grant of parallel jobs for public projects and for certain private projects in new organizations. However, you can request this grant by submitting&nbsp;<a href="https://aka.ms/azpipelines-parallelism-request">a request</a>. Existing organizations and projects are not affected. Please note that it takes us 2-3 business days to respond to your free tier requests.</p></blockquote>



<p></p>



<p>As per the above guidelines,</p>



<p></p>



<ul class="wp-block-list"><li>New Azure DevOps public projects will no longer receive a free grant of concurrent pipelines. </li></ul>



<p></p>



<ul class="wp-block-list"><li>This policy won&#8217;t impact existing open-source or public project users. </li></ul>



<p></p>



<ul class="wp-block-list"><li>As a result, when you establish a new public project, you won&#8217;t be able to run pipelines.</li></ul>



<p></p>



<p></p>



<p>Additionally for getting access to Azure DevOps pipelines, please fill out the form using the below link,</p>



<p></p>



<p><strong>Azure DevOps Parallelism Request</strong> &#8211; <a href="https://aka.ms/azpipelines-parallelism-request" target="_blank" rel="noreferrer noopener">https://aka.ms/azpipelines-parallelism-request</a></p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="784" height="1024" src="https://www.thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-Azure-DevOps-Parallelism-Request-784x1024.jpg" alt="No hosted parallelism has been purchased " class="wp-image-20054" srcset="https://thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-Azure-DevOps-Parallelism-Request-784x1024.jpg 784w, https://thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-Azure-DevOps-Parallelism-Request-230x300.jpg 230w, https://thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-Azure-DevOps-Parallelism-Request-768x1003.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-Azure-DevOps-Parallelism-Request-398x520.jpg 398w, https://thecodebuzz.com/wp-content/uploads/2022/01/No-hosted-parallelism-has-been-purchased-or-granted.-To-request-a-free-parallelism-grant-please-fill-out-the-following-form-Azure-DevOps-Parallelism-Request.jpg 1024w" sizes="auto, (max-width: 784px) 100vw, 784px" /></figure>



<p></p>



<p>For more information please visit,</p>



<p></p>



<ul class="wp-block-list"><li><a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/licensing/concurrent-jobs?view=azure-devops&amp;tabs=ms-hosted" target="_blank" rel="noreferrer noopener"><strong>https://docs.microsoft.com/en-us/azure/devops/pipelines/licensing/concurrent-jobs?view=azure-devops&amp;tabs=ms-hosted</strong></a></li></ul>



<p></p>



<p></p>



<p>That&#8217;s all! Happy coding!</p>



<p></p>



<p>Does this help you fix your issue? </p>



<p></p>



<p>Do you have any better solutions or suggestions? Please sound off your comments below.</p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/resolved-no-hosted-parallelism-has-been-purchased-or-granted/">Resolved- No hosted parallelism has been purchased or granted</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/resolved-no-hosted-parallelism-has-been-purchased-or-granted/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
