MongoDB——写入耗时

mongodb写入10万条数据的耗时差不多是1s

复制代码
import time
import pymongo
from pymongo import MongoClient

# 连接到MongoDB
client = MongoClient('mongodb://localhost:27017/')
db = client['test_db']
collection = db['test_collection']

# 生成10万条数据
documents = [{"name": "example", "value": i, "timestamp": "2024-06-13T00:00:00Z"} for i in range(1000000)]

# 批量插入
start_time = time.time()
collection.insert_many(documents)
end_time = time.time()

print(f"写入10万条数据花费的时间: {end_time - start_time} 秒")
相关推荐
电商API_1800790524714 小时前
Python爬虫从入门到实战:核心技术与合规指南
大数据·数据库·爬虫
古城小栈14 小时前
从MySQL迁移到PostgreSQL
数据库·mysql·postgresql
是萝卜干呀14 小时前
Redis
数据库·redis·缓存
摇滚侠14 小时前
数据库类型有哪些,除了关系型数据库,还有哪些类型,列一个表格,并列出该类型的代表数据库管理系统
数据库
切糕师学AI14 小时前
DBeaver + PostgreSQL 中的 Global Backup 和 Backup 的区别?
数据库·postgresql·dbeaver
繁星星繁14 小时前
【Mysql】数据库基础
android·数据库·mysql
ttthe_MOon14 小时前
MySQL 基础:索引的定义与作用
数据库·mysql
心动啊12114 小时前
简单学下chromaDB
开发语言·数据库·python
妮妮喔妮15 小时前
redis热点key拆分和读多副本
数据库·redis·缓存