download lnk : https://www.mongodb.com/try/download/community
MongoDB compass - GUI for mongodb - gets installed with MongoDB
add path to env variable -
C:\Program Files\MongoDB\Server\6.0\bin
check the mongoD installation :
C:\Users\ravikumar>mongod -version
create a folder c:\data\db
C:\Users\ravikumar>mongod ==> if command prompt is not being displayed it means server is running
need to download mongoshell and install seperatelly from https://www.mongodb.com/try/download/shell
add path to env variable -
C:\mongosh-1.7.1-win32-x64\bin
VS Code Settings :
install MongoDB for vs code by MongoDB
open vs code in Backend folder and
PS D:\E-Dashboard\backend> npm install mongoose ==> connects node.js with mongodb database
check the MongoSH installation :
C:\Users\ravikumar>mongosh -version
C:\Users\ravikumar>mongosh ==> test> prompt will appear or on VS code terminal >> mongosh ==> to open mongosh Command line interface
test> show dbs ==> shows the list of available DBs
test> db ==> shows current db in use
test> use firstDB ==> creates new db and uses the new db
firstdb> db.createCollection("student") ==> creates table
firstdb> db.my_OLD_collection_name.renameCollection("new_Collection_Name") ==> rename the collection name
firstdb> db.student.insertOne({"rollno":1, "name":"ravi"}) ==> Enter record in table
firstdb> show collections ==> shows all the table ( collection) names
firstdb> db.student.find().pretty() ==> shows the table( collection) data
firstdb> db.my_collection_name.drop() ==> Delete a perticular collection
firstdb> db.products.deleteOne( { category: "toys" } )
firstdb> db.users.deleteMany({}) ==> Delete all documents in a collection
firstdb> db.users.deleteMany({ age: { $gt: 24 }}) ==> Delete all documents with age greater than 24
firstdb> db.collection.deleteMany({"collection1_name", {"collection2_name"}})
firstdb> db.student.drop() ==> deletes the table
firstdb> db.dropDatabase() ==> deletes the database.
SQL MongoDB
Database Database
Table Collection
Rows Documents
Column Field
create db folder
for every collection ( table ) there will be one model
********************** atlas mongo db *******************
https://cloud.mongodb.com/ login with gmail
create database >> user/password >> get IP address >> cluster = CRUD-app
connecting Atlas using command line interface :
Login to Atlas >> Database >> cluster0 >> Connect >> connect using mongoDB shell >> copy the connecting string
mongosh "mongodb+srv://cluster0.tw4gopa.mongodb.net/todoapp" --apiVersion 1 --username user
and replace
todoapp = db_name_here
user = username_here
Open command prompt and run the above monnection string directly without running mongosh and it will ask for password . Done !!
************************************************************
No comments:
Post a Comment