DESCRIPTION.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. =======
  2. PyMongo
  3. =======
  4. :Info: See `the mongo site <http://www.mongodb.org>`_ for more information. See `github <http://github.com/mongodb/mongo-python-driver/tree>`_ for the latest source.
  5. :Author: Mike Dirolf
  6. :Maintainer: Bernie Hackett <bernie@mongodb.com>
  7. About
  8. =====
  9. The PyMongo distribution contains tools for interacting with MongoDB
  10. database from Python. The ``bson`` package is an implementation of
  11. the `BSON format <http://bsonspec.org>`_ for Python. The ``pymongo``
  12. package is a native Python driver for MongoDB. The ``gridfs`` package
  13. is a `gridfs
  14. <http://www.mongodb.org/display/DOCS/GridFS+Specification>`_
  15. implementation on top of ``pymongo``.
  16. Support / Feedback
  17. ==================
  18. For issues with, questions about, or feedback for PyMongo, please look into
  19. our `support channels <http://www.mongodb.org/about/support>`_. Please
  20. do not email any of the PyMongo developers directly with issues or
  21. questions - you're more likely to get an answer on the `mongodb-user
  22. <http://groups.google.com/group/mongodb-user>`_ list on Google Groups.
  23. Bugs / Feature Requests
  24. =======================
  25. Think you’ve found a bug? Want to see a new feature in PyMongo? Please open a
  26. case in our issue management tool, JIRA:
  27. - `Create an account and login <https://jira.mongodb.org>`_.
  28. - Navigate to `the PYTHON project <https://jira.mongodb.org/browse/PYTHON>`_.
  29. - Click **Create Issue** - Please provide as much information as possible about the issue type and how to reproduce it.
  30. Bug reports in JIRA for all driver projects (i.e. PYTHON, CSHARP, JAVA) and the
  31. Core Server (i.e. SERVER) project are **public**.
  32. How To Ask For Help
  33. -------------------
  34. Please include all of the following information when opening an issue:
  35. - Detailed steps to reproduce the problem, including full traceback, if possible.
  36. - The exact python version used, with patch level::
  37. $ python -c "import sys; print(sys.version)"
  38. - The exact version of PyMongo used, with patch level::
  39. $ python -c "import pymongo; print(pymongo.version); print(pymongo.has_c())"
  40. - The operating system and version (e.g. Windows 7, OSX 10.8, ...)
  41. - Web framework or asynchronous network library used, if any, with version (e.g.
  42. Django 1.7, mod_wsgi 4.3.0, gevent 1.0.1, Tornado 4.0.2, ...)
  43. Security Vulnerabilities
  44. ------------------------
  45. If you’ve identified a security vulnerability in a driver or any other
  46. MongoDB project, please report it according to the `instructions here
  47. <http://docs.mongodb.org/manual/tutorial/create-a-vulnerability-report>`_.
  48. Installation
  49. ============
  50. If you have `setuptools
  51. <http://pythonhosted.org/setuptools/>`_ installed you
  52. should be able to do **easy_install pymongo** to install
  53. PyMongo. Otherwise you can download the project source and do **python
  54. setup.py install** to install.
  55. Do **not** install the "bson" package. PyMongo comes with its own bson package;
  56. doing "easy_install bson" installs a third-party package that is incompatible
  57. with PyMongo.
  58. Dependencies
  59. ============
  60. The PyMongo distribution is supported and tested on Python 2.x (where
  61. x >= 6) and Python 3.x (where x >= 2). PyMongo versions before 3.0 also
  62. support Python 2.4, 2.5, and 3.1.
  63. Optional packages:
  64. - `backports.pbkdf2 <https://pypi.python.org/pypi/backports.pbkdf2/>`_,
  65. improves authentication performance with SCRAM-SHA-1, the default
  66. authentication mechanism for MongoDB 3.0+. It especially improves
  67. performance on Python older than 2.7.8, or on Python 3 before Python 3.4.
  68. - `pykerberos <https://pypi.python.org/pypi/pykerberos>`_ is required for
  69. the GSSAPI authentication mechanism.
  70. - `Monotime <https://pypi.python.org/pypi/Monotime>`_ adds support for
  71. a monotonic clock, which improves reliability in environments
  72. where clock adjustments are frequent. Not needed in Python 3.3+.
  73. - `wincertstore <https://pypi.python.org/pypi/wincertstore>`_ adds support
  74. for verifying server SSL certificates using Windows provided CA
  75. certificates on older versions of python. Not needed or used with versions
  76. of Python 2 beginning with 2.7.9, or versions of Python 3 beginning with
  77. 3.4.0.
  78. - `certifi <https://pypi.python.org/pypi/certifi>`_ adds support for
  79. using the Mozilla CA bundle with SSL to verify server certificates. Not
  80. needed or used with versions of Python 2 beginning with 2.7.9 on any OS,
  81. versions of Python 3 beginning with Python 3.4.0 on Windows, or versions
  82. of Python 3 beginning with Python 3.2.0 on operating systems other than
  83. Windows.
  84. Additional dependencies are:
  85. - (to generate documentation) sphinx_
  86. - (to run the tests under Python 2.6) unittest2_
  87. Examples
  88. ========
  89. Here's a basic example (for more see the *examples* section of the docs):
  90. .. code-block:: pycon
  91. >>> import pymongo
  92. >>> client = pymongo.MongoClient("localhost", 27017)
  93. >>> db = client.test
  94. >>> db.name
  95. u'test'
  96. >>> db.my_collection
  97. Collection(Database(MongoClient('localhost', 27017), u'test'), u'my_collection')
  98. >>> db.my_collection.insert_one({"x": 10}).inserted_id
  99. ObjectId('4aba15ebe23f6b53b0000000')
  100. >>> db.my_collection.insert_one({"x": 8}).inserted_id
  101. ObjectId('4aba160ee23f6b543e000000')
  102. >>> db.my_collection.insert_one({"x": 11}).inserted_id
  103. ObjectId('4aba160ee23f6b543e000002')
  104. >>> db.my_collection.find_one()
  105. {u'x': 10, u'_id': ObjectId('4aba15ebe23f6b53b0000000')}
  106. >>> for item in db.my_collection.find():
  107. ... print item["x"]
  108. ...
  109. 10
  110. 8
  111. 11
  112. >>> db.my_collection.create_index("x")
  113. u'x_1'
  114. >>> for item in db.my_collection.find().sort("x", pymongo.ASCENDING):
  115. ... print item["x"]
  116. ...
  117. 8
  118. 10
  119. 11
  120. >>> [item["x"] for item in db.my_collection.find().limit(2).skip(1)]
  121. [8, 11]
  122. Documentation
  123. =============
  124. You will need sphinx_ installed to generate the
  125. documentation. Documentation can be generated by running **python
  126. setup.py doc**. Generated documentation can be found in the
  127. *doc/build/html/* directory.
  128. Testing
  129. =======
  130. The easiest way to run the tests is to run **python setup.py test** in
  131. the root of the distribution. Note that you will need unittest2_ to
  132. run the tests under Python 2.6.
  133. To verify that PyMongo works with Gevent's monkey-patching::
  134. $ python green_framework_test.py gevent
  135. Or with Eventlet's::
  136. $ python green_framework_test.py eventlet
  137. .. _sphinx: http://sphinx.pocoo.org/
  138. .. _unittest2: https://pypi.python.org/pypi/unittest2