2025.1.28(周二)

对于大数据集,关系型数据库可能不再适用。这时,NoSQL数据库如MongoDB就派上了用场。在学习MongoDB时,常见的问题是如何处理数据存储和查询效率。

如何在MongoDB中存储和查询大数据?

from pymongo import MongoClient

# 连接MongoDB
client = MongoClient('mongodb://localhost:27017/')
db = client['mydatabase']
collection = db['data']

# 插入数据
data = {'name': 'John', 'age': 30, 'city': 'New York'}
collection.insert_one(data)

# 查询数据
result = collection.find({'age': {'$gt': 25}})
for record in result:
    print(record)

 

posted @ 2025-02-13 19:35  记得关月亮  阅读(4)  评论(0)    收藏  举报