PYTHON Tutorial
MongoDB is a document-oriented database that stores data in JSON-like documents, making it flexible and scalable.
Documents in MongoDB represent real-world entities and can have arbitrary structure, unlike relational databases with predefined columns.
import pymongo
# Connect to the database
client = pymongo.MongoClient("mongodb://localhost:27017")
# Get the database
db = client.test_database
# Create a collection
collection = db.test_collection
# Insert a document
collection.insert_one({"name": "John", "age": 30})
# Find a document
document = collection.find_one({"name": "John"})
# Print the document
print(document)
MongoDB has a distributed architecture with primary and secondary servers. Data is replicated across servers for high availability and fault tolerance.
Its document-oriented nature allows for fast and efficient retrieval of complex data. The schemaless design provides flexibility to adapt to changing data requirements.