?print-pdf' Created for
Can you imagine such a workflow using only files to store data?
Reference: Differences between SQL and NoSQL
If Mongo Server is not started, you can start it manually by:
mongod --version
db version v7.0.5
Build Info: {
"version": "7.0.5",
"gitVersion": "7809d71e84e314b497f282ea8aa06d7ded3eb205",
"openSSLVersion": "OpenSSL 3.0.2 15 Mar 2022",
"modules": [],
...
}
mongosh --version
MongoDB shell version v4.4.9
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("84365a48-2b99-48e7-a5a0-8598ad39b06a") }
MongoDB server version: 4.4.9
mongo shell is the old one and it is included in the
MongoDB Server installationmongosh shell is a standalone product, it’s developed separately from the MongoDB Server.
db.help() help on db methods
db.mycoll.help() help on collection methods
show dbs show database names
show collections show collections in current database
show users show users in current database
use <db_name> set current database (create a new one, if there isn't any)
db.mycoll.find() list objects in collection mycoll
use database on non-existing database and it will be created. If the database exist it will be set as current.db.dropDatabase()db
> use python_course
switched to db python_course
> db.todos.insert({title: "Learn Python", completed: false})
WriteResult({ "nInserted" : 1 })
use command. In example above, this is "python_course" db.mongodb://username:password@localhost:27017/dbnamemongodb+srv://server.example.com/mongodb+srv:// URIs
# install pymongo driver
pip install pymongo
# install dnspython
pip install dnspython
from pymongo import MongoClient
def connect_to_local_cluster():
# connect using connection string:
# 'mongodb://<username?>:<password?>@localhost:27017/<dbname?>
connection_string = 'mongodb://localhost:27017/python_course'
return MongoClient(connection_string)
def connect_to_atlas_cluster():
# connect using connection string:
# mongodb+srv://<username>:<password>@cluster0.xm0yw.mongodb.net/<dbname?>
connection_string = 'mongodb+srv://power_user:q1a2z3@cluster0.xm0yw.mongodb.net/'
return MongoClient(connection_string)
atlas_client = connect_to_atlas_cluster()
local_client = connect_to_local_cluster()
# list databases
print(atlas_client.list_database_names())
print(local_client.list_database_names())