Junior — Middle
Can you give an example of a scenario where a NoSQL database is used?
sobes.tech AI
Answer from AI
NoSQL databases are well-suited for projects with large volumes of unstructured or semi-structured data, where high write speed and scalability are important.
Example scenario: A social networking web application where users create posts, comments, and likes. The data structure can be flexible and frequently changing. Using a document-oriented database, such as MongoDB, allows storing data in JSON-like documents, easily adding new fields, and quickly scaling the system as the number of users grows.
# Example of writing a document in MongoDB using PyMongo
from pymongo import MongoClient
client = MongoClient('mongodb://localhost:27017/')
db = client.social_network
posts = db.posts
post = {"user_id": 123, "content": "Hello, world!", "likes": 0}
posts.insert_one(post)