I don’t know MongoDB.

Tee Phitakgul
5 min readJan 26, 2021

MongoDB an open-source document database structure is NoSQL (no-relation) SQL data in Mongo. It is JSON

“IF YOU KNOW JSON YOU CAN USE MongoDB”

In MongoDB it will return the identity id of the document or in SQL. It is the id auto-generated record.

You will know about the topic

  • Install MongoDB Compass — tool for MongoDB
  • CMD with MongoDB Compass: Insert, Delete, Update and Find of the document
  • Cloud service MongoDB Atlas

First Topic

You need to download (MongoDB Compass or MongoDB Community Server)

link download: https://www.mongodb.com/try/download/community

In your computer should have 2 programs installed

After installation complete and start program MongoDB Compass should be like this

In connection, you will connection string for local

click localhost : 27017 or connectionString

mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&ssl=false

It’s a database on localhost 3 DB create default by MongoDB

Now Create DB > click create a database

name: dev

collection name: user >> look like a table SQL

after created click DB dev

See one collection is user

You can test import data with JSON CSV or file For example I will show with basic cmd

Secord Topic

CMD with MongoDB Compass: Insert, Delete, Update and Find of the document

Click console & use db:DEV

use dev

Show collections

show collections

Insert

db.user.insertOne( { name: "card", qty: 15 } )

Refresh for check result

_id auto-generate for MongoDB

db.user.insertMany( [{ name: "card16", qty: 16 },{ name: "card17", qty: 17 }] )
  • Find
db.user.find()
db.user.findOne({"name":"card17"})

I add insert one for test find more than one

db.user.insertOne( { name: "card2", qty: 17 } )db.user.find({"qty":17})
  • Delete
db.user.deleteOne({"name":"card16"})
db.user.deleteMany({"qty":17})
  • Update
db.user.insertOne( { name: "card16", qty: 16 } )db.user.insertOne( { name: "card16", qty: 166 } )

Insert 2 record for Test Update

I need to update this record from qty 15 to 155 where name = card

db.user.updateOne({"name":"card"}, {$set : {"qty":"155"}} )
db.user.updateMany({"name":"card16"}, {$set : {"qty":"66"}} )

Last TOPIC

Cloud service MongoDB Atlas

go to link: https://www.mongodb.com/cloud/atlas/lp/general/try?utm_source=compass&utm_medium=product

After you did register ( free tier cluster )

Click Build a Cluster

select > Cloud Provider

Create Cluster Name ( can’t rename )

Click Create Cluster

wait 1–3 min for creating Cluster

ready to use it

You need to create an account for authentication DB

Click Choose a connection method ( Up to You connect. I will test with MongoDB compass)

Open MongoDB Compass

Ctrl + N or new connection

If you can’t connect

Go to the Network access

Update to you select, I choose to “ALLOW ACCESS FROM ANYWHERE”

Wait 1–2 min for the updated cluster

Let’s go to MongoDB Compass

try again to connect with my cluster

DONE!

More Information

ref: https://docs.mongodb.com/manual/introduction/

https://docs.mongodb.com/manual/reference/

--

--