MongoDB basics — Create, Show and Drop Collections

MongoDB basics — Create, Show and Drop Collections

MongoDB is a NoSQL database. This means that unlike relational databases there’s no set in stone schema with various row and columns or fields with well-defined data types. Analogue to traditional SQL database tables, MongoDB has collections. Where there were once rows in a SQL table, MongoDB has documents. Data is queried across all collections and documents using key-value pairs, which you will soon see.

The utility of MongoDB is its ease of use, scalability and the JSON like syntax with which the stored data is represented. On the other hand, if you wish to do crazy operations on your datasets like JOINs you may find MongoDB cumbersome and traditional SQL databases are better suited for that.

In any case, this article would not presume any familiarity with databases whatsoever. We will just assume that you have MongoDB installed on your server/desktop (it is available on Windows, Mac and Linux). With that installed we will create our sample database and see MongoDB in action.

Prerequisites

  1. MongoDB installation. You can follow the official documentation to install your current Operating System. OR
  2. Optionally, you can sign up for MongoDB atlas. They offer a free tier with 512MB of persistent storage. Perfect environment for experimentation or small projects.
  3. If you wish to not install any software whatsoever, you can visit Katacoda and use their web-based interface as an ephemeral sandboxed environment.

Getting Started

Assuming you have MongoDB server installed and a shell connected to the server we can start exploring a few features of it. But first a few terminologies — A mongodb server has a list of databases dbs in it. Each database can have multiple collections in it.

So for example, a University can have a personnel database which can then have various collections for different departments like one collection for Mathematics, one for Biology and so on.

Source

Leave a Reply

Your email address will not be published. Required fields are marked *

WP2Social Auto Publish Powered By : XYZScripts.com