mongodb atlast code example

Example 1: mongodb cmds

MongoDB

mongod --dbpath /users/yulin/Documents/data/db 
mongo (once mongod is ran OPEN ANOTHER TERMINAL THconnect to MongoDB)

ctrl-l to clear screen

show dbs
use {put db name here}
show collections
use {put collection name here} ex. -  use quizzes
use dbs ( or cd .. -- to go back dbs level)

or just stay @ db level 
db.createCollection(“quizzes”)
db.quizzes.find().pretty() 
db.quizzes.insert({“title”: 1}) (crud stuff)
db.quizzes.find({“title”: 1})
db.quizzes.remove({}) (remove all)
db.quizzes.remove({title: 1})
db.quizzes.update ({title: 1}, {title, 2}) (update by replaceing the entire object)
db.quizzes.update ({name: “yulin”}, {$set:{title: “Quiz 2”}})  (update by appending object)
db.quizzes.find({avg: {$gt: 85}}) (greater than)
db.quizzes.find({avg: {$gte: 85}}) (greater than or equal to)
db.quizzes.find({avg: {$lte: 85}}) (less than)

Example 2: mongodb atlas

MongoDB Atlas is the global cloud database service for modern
applications.

Deploy fully managed MongoDB across AWS, Azure, or GCP.

Best-in-class automation and proven practices guarantee availability,
scalability, and compliance with the most demanding data security and
privacy standards.

Use MongoDB's robust ecosystem of drivers, integrations, and tools
to build faster and spend less time managing your database.

Tags:

Misc Example