📔
Databases
  • Table of contents
  • SQL
    • Getting Started
      • PgAdmin Tool
    • Data Types
      • Arrays
      • Date/Time/Stamps
      • JSON
      • Internal Functions
      • Sequences
      • User Defined Data Types
    • Database
      • Schema
    • Table
      • Aggregation
      • Usefull Functions
      • Combining Tables
      • Constraints
      • Common Table Expression
      • GROUP BY and HAVING
      • OPERATORS
      • ORDER BY and DISTINCT
      • Views
      • WHERE Clause
    • Order of SQL Execution
    • Advance Table
      • Internals
      • Managing Tables
      • Partitioning Tables
      • Pivotal or Crosstab Tables
    • Joins
      • Cross & Natural Joins
      • Full, Multiple & Self Joins
      • Inner Join
      • Left and Right JOIN
    • Functions
      • Cursors
      • PL/pgSQL
      • Stored Procedures
      • Triggers
        • More on Triggers
    • Indexing
      • Custom Indexes
      • GIN Index
      • Indexes
      • SQL
      • Unique Index
    • Summarization
      • SubQueries
      • Window
  • MongoDB
    • Mongo Administration
    • MongoDB Aggregation
    • MQL
  • Redis
  • Cassandra
    • CQL
    • Data Modelling
      • Advance Data Modelling
    • Cassandra Administration
    • Cassandra Features
Powered by GitBook
On this page
  • MongoDB native
  • MongoDB setup Docker
  • Basic Commands
  • To delete

Was this helpful?

MongoDB

PreviousWindowNextMongo Administration

Last updated 2 years ago

Was this helpful?

MongoDB native

To connect to database

use the connect settings in mongodb atlas

Starting local database server

After installing, you can start the mongod by

sudo systemctl start mongod

if you receive an error : Failed to start mongod.service: Unit mongod.service not found.

Run the following command first:

sudo systemctl daemon-reload

Verify that MongoDB has started successfully.

sudo systemctl status mongod

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:

sudo systemctl enable mongod

Stop MongoDB.

As needed, you can stop the process by issuing the following command:

sudo systemctl stop mongod

Restart MongoDB.

sudo systemctl restart mongod

MongoDB setup Docker

sudo docker run --name mongo --network mongonet -d \
 -p 27017:27017 \
 -e MONGO_INITDB_ROOT_USERNAME=admin \
 -e MONGO_INITDB_ROOT_PASSWORD=pass  \
 mongo

sudo docker exec -it some-mongo sh

Begin using MongoDB.

mongo "mongodb+srv://<username>:<password>@<url>:<port>/<db>"

To show collections

show dbs
use <name of db>

show collections

Basic Commands

  • List all databases : show dbs

  • to switch to db : use <name_of_db>

  • to run a query : db.<name_of_collection>.[function name]

  • to iterate over many results : it

  • add : .pretty() to see json better

  • to find any one document from collection, just use .findOne()

  • to create new collection : db.createCollection("employees")

To shutdown db server

use admin
db.shutdownServer()
exit

To delete

drop collection
db.inspection.drop()

You can restart the process by issuing the following command:

Start a shell on the same host machine as the . You can run the shell without any command-line options to connect to a that is running on your localhost with default port 27017:

mongod
mongod
mongo
mongod
mongo
mongod