Registry / database / pymongo

pymongo

JSON →
library4.17.0pypypi✓ verified 28d ago

Official MongoDB Python driver. Synchronous client for MongoDB. v4.0 removed all APIs deprecated in v3.x — insert(), update(), remove(), count(), save() all gone. Current version: 4.16.0 (Mar 2026). Python 3.9+ required (3.8 dropped in v4.11). AsyncMongoClient added as GA in v4.13. Most LLM-generated pymongo code uses v3 patterns that break on v4.

pip install pymongo
INSTALL
IMPORT
SIG · PYMONGO
P
pymongo
databasepythonv4.17.0
Install
2.7s avg
Import
404ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.17.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.430s · 25.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.7s · import 0.378s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MongoClient
from pymongo import MongoClient
from pymongo import MongoClient

Minimal pymongo 4.x CRUD operations.

# pip install 'pymongo[srv]' from pymongo import MongoClient client = MongoClient('mongodb+srv://user:pass@cluster.mongodb.net/') db = client['mydb'] col = db['users'] # Insert col.insert_one({'name': 'Alice', 'age': 30}) # Find for doc in col.find({'age': {'$gt': 18}}): print(doc) # Update col.update_one({'name': 'Alice'}, {'$set': {'age': 31}}) # Count print(col.count_documents({})) # Delete col.delete_one({'name': 'Alice'}) client.close()
Debug
Known issues
breakingcollection.insert() removed in v4.0. Raises AttributeError. LLMs trained on pre-2022 data consistently generate insert() calls.
fix
insert_one({'key': 'value'}) or insert_many([{...}, {...}])
affects: >= 4.0
breakingcollection.update() removed in v4.0. Raises AttributeError.
fix
update_one(filter, update) or update_many(filter, update)
affects: >= 4.0
breakingcollection.remove() removed in v4.0. Raises AttributeError.
fix
delete_one(filter) or delete_many(filter)
affects: >= 4.0
breakingcollection.count() removed in v4.0. Raises AttributeError.
fix
count_documents(filter) — note: count_documents({}) counts all docs. estimated_document_count() for fast approximate count.
affects: >= 4.0
breakingcollection.save() removed in v4.0.
fix
insert_one() for new docs, replace_one(filter, doc, upsert=True) for upsert.
affects: >= 4.0
breakingcollection.find_and_modify() removed in v4.0.
fix
find_one_and_update(), find_one_and_replace(), or find_one_and_delete()
affects: >= 4.0
gotchamongodb+srv:// connection strings require dnspython. 'pip install pymongo' alone raises ConfigurationError. Install with pip install 'pymongo[srv]'.
fix
pip install 'pymongo[srv]'
affects: all
gotchaMotor (async MongoDB) and PyMongo >= 4.9 version coupling. Motor < 3.6 is incompatible with PyMongo >= 4.9. Mixing versions causes ImportError or unexpected behavior.
fix
Use Motor >= 3.6 with PyMongo >= 4.9. Or use native AsyncMongoClient (GA in 4.13) instead of Motor.
affects: >= 4.9
gotchaPython 3.8 dropped in PyMongo 4.11. Python 3.9 is now minimum.
fix
Use Python 3.9+
affects: >= 4.11
deprecateddatetime.utcnow() pattern for MongoDB timestamps deprecated in Python 3.12. Use datetime.now(tz=timezone.utc) instead.
fix
from datetime import datetime, timezone; datetime.now(tz=timezone.utc)
affects: all
gotchaConnecting with `mongodb+srv://` can fail with `ConfigurationError` if the SRV DNS record (e.g., `_mongodb._tcp.cluster.mongodb.net`) for the provided hostname does not exist (`NXDOMAIN`). This is an external DNS issue, not a missing dependency.
fix
Verify the `mongodb+srv` connection string hostname and ensure its corresponding SRV DNS record exists and is correctly configured with your DNS provider.
affects: all
Upgrade
Version history
4.17.0latest on PyPI · released Apr 20, 2026
Audit
Dependencies
dnspythonoptionalRequired for mongodb+srv:// connection strings. Install via pymongo[srv].
Agent activity
17 hits · last 30 days
node
14
Resources