<?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: Onkar Janwa</title>
    <description>The latest articles on DEV Community by Onkar Janwa (@onkarjanwa).</description>
    <link>https://dev.to/onkarjanwa</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%2F31101%2Fe51722f0-36aa-4554-876f-dfbcf7f1fd15.jpg</url>
      <title>DEV Community: Onkar Janwa</title>
      <link>https://dev.to/onkarjanwa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/onkarjanwa"/>
    <language>en</language>
    <item>
      <title>Create and Drop MongoDB Database</title>
      <dc:creator>Onkar Janwa</dc:creator>
      <pubDate>Mon, 29 Nov 2021 11:31:09 +0000</pubDate>
      <link>https://dev.to/onkarjanwa/create-and-drop-mongodb-database-2o0e</link>
      <guid>https://dev.to/onkarjanwa/create-and-drop-mongodb-database-2o0e</guid>
      <description>&lt;p&gt;Learn commands to create and drop a MongoDB database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a database
&lt;/h2&gt;

&lt;p&gt;The below command is used to create or access a MongoDB database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use &amp;lt;database-name&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;strong&gt;&amp;lt;database-name&amp;gt;&lt;/strong&gt; with the name you want to keep to your database. &lt;/p&gt;

&lt;p&gt;The above use command does not create anything until you insert the first record. Here is an example of an insert command. In this example, we are inserting a task into&lt;br&gt;
the tasks collection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.tasks.insertOne({
    name: "Learn Chapter 1",
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The below command verifies the database creation. It returns names and sizes of all the&lt;br&gt;
databases.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;show databases;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see some databases other than todo. They are created by default by MongoDB on installation and are used for user management and system purpose.&lt;/p&gt;




&lt;h2&gt;
  
  
  Drop a database
&lt;/h2&gt;

&lt;p&gt;Run the following commands in the terminal below to drop a database.&lt;/p&gt;

&lt;p&gt;Select the database that you want to drop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use &amp;lt;database-name&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Drop the selected database&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.dropDatabase();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; This command will remove all the collections and documents.&lt;/p&gt;

&lt;p&gt;You may see the below error if you don’t have enough permission to drop a database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MongoServerError: not authorized on todo to execute command { dropDatabase: 1, lsid: { i
&amp;gt; d: UUID("1479ef4b-5e3f-42df-aaf8-93234469e6dc") }, $db: "todo" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;blockquote&gt;
&lt;p&gt;I have published an e-book on MongoDB, this e-book will help you learn MongoDB core concepts like queries, documents, embedded documents, operators, etc. with advanced features like CRUD Operations, Bulk Write Operations, GridFS, Indexing, Aggregation Pipeline, Authorization, etc. This e-book includes query examples with each chapter to practice database operations.&lt;br&gt;
&lt;a href="https://onkarjanwa.gumroad.com/l/PgxIb"&gt;Check out here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>mongodb</category>
    </item>
  </channel>
</rss>
