PYTHON Tutorial
MongoDB is a popular NoSQL database management system. It is known for its scalability, flexibility, and ease of use.
C:\Program Files\MongoDB\Server
directory./usr/local/mongodb
directory.sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get install mongodb-org
MongoDB uses a configuration file named mongod.conf
to store its settings. This file is located in the following directories:
C:\Program Files\MongoDB\Server\4.4\bin\mongod.conf
/usr/local/mongodb/bin/mongod.conf
/etc/mongod.conf
You can edit the mongod.conf
file to change the following settings:
data
.mongod.log
.Once you have installed and configured MongoDB, you can start the server by running the following command in a terminal window:
mongod --config /path/to/mongod.conf
You can now connect to the MongoDB server using a MongoDB client, such as the mongo
shell.
To connect to MongoDB from Python, you can use the following code:
import pymongo
# Create a client instance
client = pymongo.MongoClient("mongodb://localhost:27017")
# Get a database instance
db = client.mydb
# Get a collection instance
collection = db.mycollection
# Insert a document into the collection
collection.insert_one({"name": "John Doe"})
# Find a document in the collection
result = collection.find_one({"name": "John Doe"})
# Print the document's name
print(result["name"])