Permalink
Browse files

More Connection -> MongoClient in docs PYTHON-423

  • Loading branch information...
1 parent 541f518 commit 1d2118e66c57aa839ce776e57cdfbf11bc86c5c5 @behackett behackett committed Nov 17, 2012
Showing with 27 additions and 28 deletions.
  1. +2 −2 README.rst
  2. +2 −2 doc/conf.py
  3. +10 −10 doc/faq.rst
  4. +11 −12 doc/python3.rst
  5. +2 −2 doc/tutorial.rst
View
@@ -52,12 +52,12 @@ Examples
Here's a basic example (for more see the *examples* section of the docs):
>>> import pymongo
->>> connection = pymongo.Connection("localhost", 27017)
+>>> connection = pymongo.MongoClient("localhost", 27017)
>>> db = connection.test
>>> db.name
u'test'
>>> db.my_collection
-Collection(Database(Connection('localhost', 27017), u'test'), u'my_collection')
+Collection(Database(MongoClient('localhost', 27017), u'test'), u'my_collection')
>>> db.my_collection.save({"x": 10})
ObjectId('4aba15ebe23f6b53b0000000')
>>> db.my_collection.save({"x": 8})
View
@@ -70,8 +70,8 @@
doctest_test_doctest_blocks = False
doctest_global_setup = """
-from pymongo.connection import Connection
-connection = Connection()
+from pymongo.mongo_client import MongoClient
+connection = MongoClient()
connection.drop_database("doctest_test")
db = connection.doctest_test
"""
View
@@ -14,22 +14,22 @@ for threaded applications.
How does connection pooling work in PyMongo?
--------------------------------------------
-Every :class:`~pymongo.connection.Connection` instance has built-in
+Every :class:`~pymongo.mongo_client.MongoClient` instance has built-in
connection pooling. By default, each thread gets its own socket reserved on its
first operation. Those sockets are held until
-:meth:`~pymongo.connection.Connection.end_request` is called by that
+:meth:`~pymongo.mongo_client.MongoClient.end_request` is called by that
thread.
-Calling :meth:`~pymongo.connection.Connection.end_request` allows the
+Calling :meth:`~pymongo.mongo_client.MongoClient.end_request` allows the
socket to be returned to the pool, and to be used by other threads
instead of creating a new socket. Judicious use of this method is
important for applications with many threads or with long running
threads that make few calls to PyMongo operations.
-Alternatively, a :class:`~pymongo.connection.Connection` created with
+Alternatively, a :class:`~pymongo.mongo_client.MongoClient` created with
``auto_start_request=False`` will share sockets (safely) among all threads.
-When :meth:`~pymongo.connection.Connection.disconnect` is called by any thread,
+When :meth:`~pymongo.mongo_client.MongoClient.disconnect` is called by any thread,
all sockets are closed. PyMongo will create new sockets as needed.
Does PyMongo support Python 3?
@@ -47,7 +47,7 @@ Currently there is no great way to use PyMongo in conjunction with `Tornado
<http://www.tornadoweb.org/>`_ or `Twisted <http://twistedmatrix.com/>`_.
PyMongo provides built-in connection pooling, so some of the benefits of those
frameworks can be achieved just by writing multi-threaded code that shares a
-:class:`~pymongo.connection.Connection`.
+:class:`~pymongo.mongo_client.MongoClient`.
There are asynchronous MongoDB drivers in Python: `AsyncMongo for Tornado
<https://github.com/bitly/asyncmongo>`_ and `TxMongo for Twisted
@@ -62,10 +62,10 @@ avoid blocking the event loop:
`MongoDB profiler <http://www.mongodb.org/display/DOCS/Database+Profiler>`_
to watch for slow queries.
-- Create a single :class:`~pymongo.connection.Connection` instance for your
+- Create a single :class:`~pymongo.mongo_client.MongoClient` instance for your
application in your startup code, before starting the IOLoop.
-- Configure the :class:`~pymongo.connection.Connection` with a short
+- Configure the :class:`~pymongo.mongo_client.MongoClient` with a short
``socketTimeoutMS`` so slow operations result in a
:class:`~pymongo.errors.TimeoutError`, rather than blocking the loop and
preventing your application from responding to other requests.
@@ -145,9 +145,9 @@ UTC. In versions >= 1.7, the driver will automatically convert aware
datetimes to UTC before saving them. By default, datetimes retrieved
from the server (no matter what version of the driver you're using)
will be naive and represent UTC. In newer versions of the driver you
-can set the :class:`~pymongo.connection.Connection` `tz_aware`
+can set the :class:`~pymongo.mongo_client.MongoClient` `tz_aware`
parameter to ``True``, which will cause all
-:class:`~datetime.datetime` instances returned from that Connection to
+:class:`~datetime.datetime` instances returned from that MongoClient to
be aware (UTC). This setting is recommended, as it can force
application code to handle timezones properly.
View
@@ -30,7 +30,7 @@ read it back. Notice the byte string is decoded back to :class:`bytes`::
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
- >>> c = pymongo.Connection()
+ >>> c = pymongo.MongoClient()
>>> c.test.bintest.insert({'binary': b'this is a byte string'})
ObjectId('4f9086b1fba5222021000000')
>>> c.test.bintest.find_one()
@@ -43,7 +43,7 @@ to :class:`~bson.binary.Binary`::
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
- >>> c = pymongo.Connection()
+ >>> c = pymongo.MongoClient()
>>> c.test.bintest.find_one()
{u'binary': Binary('this is a byte string', 0), u'_id': ObjectId('4f9086b1fba5222021000000')}
@@ -151,26 +151,25 @@ directory after running ``python setup.py install`` the untranslated modules
will be the first thing in your path. Importing pymongo will result in an
exception similar to::
- Python 3.1.4 (default, Mar 21 2012, 14:34:01)
- [GCC 4.5.3] on linux2
+ Python 3.1.5 (default, Jun 2 2012, 12:24:49)
+ [GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
- File "pymongo/__init__.py", line 104, in <module>
- from pymongo.connection import Connection
- File "pymongo/connection.py", line 573
- except Exception, why:
- ^
- SyntaxError: invalid syntax
+ File "pymongo/__init__.py", line 58, in <module>
+ version = get_version_string()
+ File "pymongo/__init__.py", line 54, in get_version_string
+ if isinstance(version_tuple[-1], basestring):
+ NameError: global name 'basestring' is not defined
Note the path in the traceback (``pymongo/__init__.py``). Changing out of the
source directory takes the untranslated modules out of your path::
$ cd ..
$ python
- Python 3.1.4 (default, Mar 21 2012, 14:34:01)
- [GCC 4.5.3] on linux2
+ Python 3.1.5 (default, Jun 2 2012, 12:24:49)
+ [GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> pymongo.__file__
View
@@ -29,8 +29,8 @@ can start it like so:
$ mongod
-Making a Connection
--------------------
+Making a Connection with MongoClient
+------------------------------------
The first step when working with **PyMongo** is to create a
:class:`~pymongo.mongo_client.MongoClient` to the running **mongod**
instance. Doing so is easy:

0 comments on commit 1d2118e

Please sign in to comment.