pymongo 是 MongoDB 的一个 Python 驱动,它允许开发者在 Python 程序中连接、操作和管理 MongoDB 数据库。它基于 MongoDB 的 BSON 序列化格式和网络协议,提供了类似于原生 MongoDB shell 的操作方式。可以通过pymongo 来连接 MongoDB,进行操作,如增删改查,并且它也支持事务操作。
-
安装
pip install pymongo
-
建立连接
from pymongo import MongoClient # Connect to a running MongoDB instance on the default host and port client = MongoClient() # Connect to a running MongoDB instance on the specified host and port client = MongoClient(