<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ||Nishant||</title>
    <description>The latest articles on DEV Community by ||Nishant|| (@thenishant).</description>
    <link>https://dev.to/thenishant</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F449765%2F3a9eff11-feeb-40cd-9354-162029a98a08.jpeg</url>
      <title>DEV Community: ||Nishant||</title>
      <link>https://dev.to/thenishant</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thenishant"/>
    <language>en</language>
    <item>
      <title>Store images in MongoDB via Python</title>
      <dc:creator>||Nishant||</dc:creator>
      <pubDate>Tue, 02 Mar 2021 07:22:08 +0000</pubDate>
      <link>https://dev.to/thenishant/store-images-in-mongodb-via-python-2g73</link>
      <guid>https://dev.to/thenishant/store-images-in-mongodb-via-python-2g73</guid>
      <description>&lt;p&gt;Hello Coders,&lt;/p&gt;

&lt;p&gt;This article will brief you about &lt;code&gt;Storing the images in MongoDB via python code.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is what want to achieve:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fm2CSR4q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fm2CSR4q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Dependencies
&lt;/h3&gt;

&lt;p&gt;We will be using just 2 library dependencies, namely:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;GridFS&lt;/li&gt;
&lt;li&gt;PyMongo&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  What is GridFS?
&lt;/h4&gt;

&lt;p&gt;GridFS is the MongoDB specification for storing and retrieving large files such as images, audio files, video files, etc. It is kind of a file system to store files but its data is stored within MongoDB collections. GridFS has the capability to store files even greater than its document size limit of 16MB.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is pymongo?
&lt;/h3&gt;

&lt;p&gt;The PyMongo distribution contains tools for interacting with MongoDB database from Python. The &lt;code&gt;bson&lt;/code&gt; package is an implementation of the &lt;a href="http://bsonspec.org/" rel="noopener noreferrer"&gt;BSON&lt;/a&gt; format for Python. The pymongo package is a native Python driver for MongoDB. The gridfs package is a &lt;a href="https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.rst/" rel="noopener noreferrer"&gt;gridfs&lt;/a&gt; implementation on top of pymongo.&lt;/p&gt;

&lt;h4&gt;
  
  
  Now to Code
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Connect to MongoDB&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To install pymongo: &lt;code&gt;pip3 install pymongo&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pymongo&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;MongoClient&lt;/span&gt;

&lt;span class="c1"&gt;# Connect to the server with the hostName and portNumber.
&lt;/span&gt;&lt;span class="n"&gt;connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MongoClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27017&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Connect to the Database where the images will be stored.
&lt;/span&gt;&lt;span class="n"&gt;database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;DB_NAME&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Store the Image in the MongoDB&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;gridfs&lt;/span&gt;

&lt;span class="c1"&gt;#Create an object of GridFs for the above database.
&lt;/span&gt;&lt;span class="n"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gridfs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GridFS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#define an image object with the location.
&lt;/span&gt;&lt;span class="nb"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;image-4.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;#Open the image in read-only format.
&lt;/span&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rb&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;contents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;#Now store/put the image via GridFs object.
&lt;/span&gt;&lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;file&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That's it for now.&lt;br&gt;
Thanks for reading&lt;/p&gt;

</description>
      <category>python</category>
      <category>mongodb</category>
      <category>jpg</category>
    </item>
    <item>
      <title>Deploy any web app to Vercel</title>
      <dc:creator>||Nishant||</dc:creator>
      <pubDate>Fri, 04 Sep 2020 15:58:06 +0000</pubDate>
      <link>https://dev.to/thenishant/deploy-any-web-app-to-vercel-1ka8</link>
      <guid>https://dev.to/thenishant/deploy-any-web-app-to-vercel-1ka8</guid>
      <description>&lt;p&gt;Here is a quick and simple guide to deploy any web app to Vercel (previously known as Zeit).&lt;/p&gt;

&lt;h3&gt;
  
  
  The Flow
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Using &lt;a href="https://docusaurus.io/" rel="noopener noreferrer"&gt;Docusaurus&lt;/a&gt; which makes it easy to maintain Open Source documentation websites.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://vercel.com" rel="noopener noreferrer"&gt;Vercel&lt;/a&gt; account&lt;/li&gt;
&lt;li&gt;Deploy the web app with Vercel&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Assumption
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;I'll assume that you already have a web app in place, if not then create a new web app which acts as a documentation website. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 1: Getting started
&lt;/h4&gt;

&lt;p&gt;In order to create a web-app with &lt;a href="https://docusaurus.io/" rel="noopener noreferrer"&gt;Docusaurus&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a &lt;strong&gt;directory&lt;/strong&gt; and navigate inside to the directory.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npx docusaurus-init&lt;/code&gt;. This will create a web project in the following structure
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;directory-name&amp;gt;
├── Dockerfile
├── docker-compose.yml
├── docs
│   ├── doc1.md
│   ├── doc2.md
│   ├── doc3.md
│   ├── exampledoc4.md
│   └── exampledoc5.md
└── website
    ├── README.md
    ├── blog
    │   ├── 2016-03-11-blog-post.md
    │   ├── 2017-04-10-blog-post-two.md
    │   ├── 2017-09-25-testing-rss.md
    │   ├── 2017-09-26-adding-rss.md
    │   └── 2017-10-24-new-version-1.0.0.md
    ├── core
    │   └── Footer.js
    ├── package.json
    ├── pages
    │   └── en
    │       ├── help.js
    │       ├── index.js
    │       └── users.js
    ├── sidebars.json
    ├── siteConfig.js
    ├── static
    │   ├── css
    │   │   └── custom.css
    │   └── img
    │       ├── favicon.ico
    │       ├── oss_logo.png
    │       ├── undraw_code_review.svg
    │       ├── undraw_monitor.svg
    │       ├── undraw_note_list.svg
    │       ├── undraw_online.svg
    │       ├── undraw_open_source.svg
    │       ├── undraw_operating_system.svg
    │       ├── undraw_react.svg
    │       ├── undraw_tweetstorm.svg
    │       └── undraw_youtube_tutorial.svg
    └── yarn.lock
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Navigate to &lt;code&gt;website&lt;/code&gt; folder inside the &lt;code&gt;root directory&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;yarn start&lt;/code&gt; or &lt;code&gt;npm start&lt;/code&gt;. This should bring up the server and launches the web app on &lt;code&gt;localhost:3000&lt;/code&gt;. Example website should be up and running.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 2: Building
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Considering all the changes are done, now is the time to build the app. This can be done by using &lt;code&gt;yarn build&lt;/code&gt; or &lt;code&gt;npm build&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;vercel&lt;/code&gt; in your fav terminal to log in.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fb1hy1g6quaxoqnbwjqft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fb1hy1g6quaxoqnbwjqft.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You will then receive an email, verify that and you are now logged in.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 3: Deploying
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to &lt;code&gt;/build/&amp;lt;website-name&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;vercel&lt;/code&gt; to finally start deploying&lt;/li&gt;
&lt;li&gt;Follow the simple on-screen instructions to deploy it. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fj3twag8jlqjztmlhmrzz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fj3twag8jlqjztmlhmrzz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4: Chill out and enjoy
&lt;/h4&gt;

&lt;p&gt;Since you have deployed your web-app, its time to enjoy and start exploring something else.&lt;/p&gt;

&lt;p&gt;Reply in the comments if you enjoy this read or any suggestions to improve.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
