0% found this document useful (0 votes)
33 views

Untitled

This document provides instructions for basic provisioning and use of a MongoDB database. It outlines how to: 1) Install the MongoDB Shell and tools; 2) Create a MongoDB Atlas account; 3) Connect to a MongoDB instance using the mongo shell command line; and 4) Run basic commands to insert, find, update, and delete documents to familiarize with MongoDB operations. It concludes by noting the next steps will involve running a MongoDB instance locally using Docker.

Uploaded by

Cristina Siscanu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Untitled

This document provides instructions for basic provisioning and use of a MongoDB database. It outlines how to: 1) Install the MongoDB Shell and tools; 2) Create a MongoDB Atlas account; 3) Connect to a MongoDB instance using the mongo shell command line; and 4) Run basic commands to insert, find, update, and delete documents to familiarize with MongoDB operations. It concludes by noting the next steps will involve running a MongoDB instance locally using Docker.

Uploaded by

Cristina Siscanu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

*** Basic Provisioning of a MongoDB Database ***

1. Install [Mongo Shell] and [MongoDB Database Tools] for your operating system
https://docs.mongodb.com/database-tools/installation/installation/
- Make sure that you add the folder to the PATH environment variable!!

2. Create a MongoDB Atlas account on the free tier


https://www.mongodb.com/cloud/atlas
- Click "Connect" and choose to connect with the mongo shell

3. Open Windows Terminal and type


> mongosh "mongodb+srv://cluster0.dusbo.mongodb.net/abdtest" --username abdroot
User is: abdroot | Password is: Test123 | DB name: abdtest
- Feel free to use this particular database instance or replace credentials with
your own

3. Try a few commands to familiarize yourself with the MongoDB system

Show the current database


> db

Use a specific database


> use abdtest

Get a list of all collections


> show collections

Insert a document into collection


> db.products.insertOne(
{ item: "canvas", qty: 100, tags: ["cotton"], size: { h: 28, w: 35.5, uom: "cm" }
}
)

Find all documents


> db.products.find();
> db.products.find({});
> db.products.find().pretty();

Insert multiple documents


> db.products.insertMany([
{ item: "journal", qty: 25, tags: ["blank", "red"], size: { h: 14, w: 21, uom:
"cm" } },
{ item: "mat", qty: 85, tags: ["gray"], size: { h: 27.9, w: 35.5, uom: "cm" } },
{ item: "mousepad", qty: 55, tags: ["gel", "blue"], size: { h: 19, w: 22.85,
uom: "cm" } }
])

Find a specific document


> db.products.find( { item: "mousepad" } )
> db.products.find( { qty: { $lt: 30 } } )

Count the number of documents


> db.products.countDocuments()

Update a specific document


> db.products.updateOne(
{ item: "mousepad" },
{
$set: { qty: 5 },
$currentDate: { lastModified: true }
}
)

Delete a document
> db.products.deleteOne( { item: "mousepad" } )

Drop collection
> db.products.drop()

NEXT:
We will run an instance of the MongoDB on our local machine. Familiarize yourself
with Docker (what it is, how you can run it, etc.)

You might also like