Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PyMongo - the Official MongoDB Python driver

License

NotificationsYou must be signed in to change notification settings

mongodb/mongo-python-driver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI VersionPython VersionsMonthly DownloadsAPI Documentation Status

About

The PyMongo distribution contains tools for interacting with MongoDBdatabase from Python. Thebson package is an implementation of theBSON format for Python. Thepymongo package isa native Python driver for MongoDB, offering both synchronous and asynchronous APIs. Thegridfs package is agridfsimplementation on top ofpymongo.

PyMongo supports MongoDB 4.0, 4.2, 4.4, 5.0, 6.0, 7.0, and 8.0.

Support / Feedback

For issues with, questions about, or feedback for PyMongo, please lookinto oursupport channels. Pleasedo not email any of the PyMongo developers directly with issues orquestions - you're more likely to get an answer onStackOverflow(using a "mongodb" tag).

Bugs / Feature Requests

Think you've found a bug? Want to see a new feature in PyMongo? Pleaseopen a case in our issue management tool, JIRA:

Bug reports in JIRA for all driver projects (i.e. PYTHON, CSHARP, JAVA)and the Core Server (i.e. SERVER) project arepublic.

How To Ask For Help

Please include all of the following information when opening an issue:

  • Detailed steps to reproduce the problem, including full traceback,if possible.

  • The exact python version used, with patch level:

python -c"import sys; print(sys.version)"
  • The exact version of PyMongo used, with patch level:
python -c"import pymongo; print(pymongo.version); print(pymongo.has_c())"
  • The operating system and version (e.g. Windows 7, OSX 10.8, ...)

  • Web framework or asynchronous network library used, if any, withversion (e.g. Django 1.7, mod_wsgi 4.3.0, gevent 1.0.1, Tornado4.0.2, ...)

Security Vulnerabilities

If you've identified a security vulnerability in a driver or any otherMongoDB project, please report it according to theinstructionshere.

Installation

PyMongo can be installed withpip:

python -m pip install pymongo

You can also download the project source and do:

pip install.

Donot install the "bson" package from pypi. PyMongo comes withits own bson package; running "pip install bson" installs a third-partypackage that is incompatible with PyMongo.

Dependencies

PyMongo supports CPython 3.9+ and PyPy3.10+.

Required dependencies:

Support formongodb+srv:// URIs requiresdnspython

Optional dependencies:

GSSAPI authentication requirespykerberos on Unix orWinKerberos on Windows. Thecorrect dependency can be installed automatically along with PyMongo:

python -m pip install"pymongo[gssapi]"

MONGODB-AWS authentication requirespymongo-auth-aws:

python -m pip install"pymongo[aws]"

OCSP (Online Certificate Status Protocol) requiresPyOpenSSL,requests,service_identity and mayrequirecertifi:

python -m pip install"pymongo[ocsp]"

Wire protocol compression with snappy requirespython-snappy:

python -m pip install"pymongo[snappy]"

Wire protocol compression with zstandard requireszstandard:

python -m pip install"pymongo[zstd]"

Client-Side Field Level Encryption requirespymongocrypt andpymongo-auth-aws:

python -m pip install"pymongo[encryption]"

You can install all dependencies automatically with the followingcommand:

python -m pip install"pymongo[gssapi,aws,ocsp,snappy,zstd,encryption]"

Examples

Here's a basic example (for more see theexamples section of thedocs):

>>>import pymongo>>> client= pymongo.MongoClient("localhost",27017)>>> db= client.test>>> db.name'test'>>> db.my_collectionCollection(Database(MongoClient('localhost', 27017), 'test'), 'my_collection')>>> db.my_collection.insert_one({"x":10}).inserted_idObjectId('4aba15ebe23f6b53b0000000')>>> db.my_collection.insert_one({"x":8}).inserted_idObjectId('4aba160ee23f6b543e000000')>>> db.my_collection.insert_one({"x":11}).inserted_idObjectId('4aba160ee23f6b543e000002')>>> db.my_collection.find_one(){'x': 10, '_id': ObjectId('4aba15ebe23f6b53b0000000')}>>>for itemin db.my_collection.find():...print(item["x"])...10811>>> db.my_collection.create_index("x")'x_1'>>>for itemin db.my_collection.find().sort("x", pymongo.ASCENDING):...print(item["x"])...81011>>> [item["x"]for itemin db.my_collection.find().limit(2).skip(1)][8, 11]

Documentation

Documentation is available atpymongo.readthedocs.io.

See thecontributing guide for how to build the documentation.

Learning Resources

Testing

The easiest way to run the tests is to run the following from the repository root.

pip install -e".[test]"pytest

For more advanced testing scenarios, see thecontributing guide.


[8]ページ先頭

©2009-2025 Movatter.jp