Connection doc updates

This commit is contained in:
Ross Lawley 2013-04-23 20:55:37 +00:00
parent 5271f3b4a0
commit 9bd8b3e9a5

View File

@ -6,20 +6,23 @@ Connecting to MongoDB
To connect to a running instance of :program:`mongod`, use the
:func:`~mongoengine.connect` function. The first argument is the name of the
database to connect to. If the database does not exist, it will be created. If
the database requires authentication, :attr:`username` and :attr:`password`
arguments may be provided::
database to connect to::
from mongoengine import connect
connect('project1', username='webapp', password='pwd123')
connect('project1')
By default, MongoEngine assumes that the :program:`mongod` instance is running
on **localhost** on port **27017**. If MongoDB is running elsewhere, you may
provide :attr:`host` and :attr:`port` arguments to
on **localhost** on port **27017**. If MongoDB is running elsewhere, you should
provide the :attr:`host` and :attr:`port` arguments to
:func:`~mongoengine.connect`::
connect('project1', host='192.168.1.35', port=12345)
If the database requires authentication, :attr:`username` and :attr:`password`
arguments should be provided::
connect('project1', username='webapp', password='pwd123')
Uri style connections are also supported as long as you include the database
name - just supply the uri as the :attr:`host` to
:func:`~mongoengine.connect`::
@ -74,8 +77,8 @@ to point across databases and collections. Below is an example schema, using
Switch Database Context Manager
===============================
Sometimes you may want to switch the database to query against for a class,
for example, you archive older data into a separate database for performance
Sometimes you may want to switch the database to query against for a class
for example, archiving older data into a separate database for performance
reasons.
The :class:`~mongoengine.context_managers.switch_db` context manager allows