@@ -35,20 +35,23 @@ class Collection(object):
3535 def __init__ (self , database , name , options = None ):
3636 """Get / create a Mongo collection.
3737
38- Raises TypeError if name is not an instance of (str, unicode). Raises
39- InvalidName if name is not a valid collection name. Raises TypeError if
40- options is not an instance of dict. If options is non-empty a create
41- command will be sent to the database. Otherwise the collection will be
42- created implicitly on first use.
38+ Raises :class:`TypeError` if `name` is not an instance of
39+ :class:`basestring`. Raises
40+ :class:`~pymongo.errors.InvalidName` if `name` is not a valid
41+ collection name. Raises :class:`TypeError` if `options` is not
42+ an instance of :class:`dict`. If `options` is non-empty a
43+ create command will be sent to the database. Otherwise the
44+ collection will be created implicitly on first use.
4345
4446 :Parameters:
4547 - `database`: the database to get a collection from
4648 - `name`: the name of the collection to get
47- - `options`: dictionary of collection options.
48- see `pymongo.database.Database.create_collection` for details.
49+ - `options`: dictionary of collection options. see
50+ :meth:`~pymongo.database.Database.create_collection` for
51+ details.
4952 """
5053 if not isinstance (name , basestring ):
51- raise TypeError ("name must be an instance of (str, unicode) " )
54+ raise TypeError ("name must be an instance of basestring " )
5255
5356 if options is not None and not isinstance (options , dict ):
5457 raise TypeError ("options must be an instance of dict" )
@@ -466,21 +469,24 @@ def create_index(self, key_or_list, unique=False, ttl=300):
466469 """Creates an index on this collection.
467470
468471 Takes either a single key or a list of (key, direction) pairs.
469- The key(s) must be an instance of ``(str, unicode)` `, and the
472+ The key(s) must be an instance of :class:`basestring `, and the
470473 directions must be one of (:data:`~pymongo.ASCENDING`,
471474 :data:`~pymongo.DESCENDING`). Returns the name of the created
472475 index.
473476
474477 :Parameters:
475- - `key_or_list`: a single key or a list of (key, direction) pairs
476- specifying the index to create
477- - `unique` (optional): should this index guarantee uniqueness?
478- - `ttl` (optional): time window (in seconds) during which this index
479- will be recognized by subsequent calls to :meth:`ensure_index` -
480- see documentation for :meth:`ensure_index` for details
478+ - `key_or_list`: a single key or a list of (key, direction)
479+ pairs specifying the index to create
480+ - `unique` (optional): should this index guarantee
481+ uniqueness?
482+ - `ttl` (optional): time window (in seconds) during which
483+ this index will be recognized by subsequent calls to
484+ :meth:`ensure_index` - see documentation for
485+ :meth:`ensure_index` for details
481486 """
482487 if not isinstance (key_or_list , (str , unicode , list )):
483- raise TypeError ("key_or_list must either be a single key or a list of (key, direction) pairs" )
488+ raise TypeError ("key_or_list must either be a single key "
489+ "or a list of (key, direction) pairs" )
484490
485491 to_save = SON ()
486492 keys = helpers ._index_list (key_or_list )
@@ -500,10 +506,10 @@ def create_index(self, key_or_list, unique=False, ttl=300):
500506 def ensure_index (self , key_or_list , unique = False , ttl = 300 ):
501507 """Ensures that an index exists on this collection.
502508
503- Takes either a single key or a list of (key, direction)
504- pairs. The key(s) must be an instance of ``(str, unicode)``,
505- and the direction(s) must be one of
506- (:data:`~pymongo.ASCENDING`, :data:`~pymongo.DESCENDING`).
509+ Takes either a single key or a list of (key, direction) pairs.
510+ The key(s) must be an instance of :class:`basestring`, and the
511+ direction(s) must be one of (:data:`~pymongo.ASCENDING`,
512+ :data:`~pymongo.DESCENDING`).
507513
508514 Unlike :meth:`create_index`, which attempts to create an index
509515 unconditionally, :meth:`ensure_index` takes advantage of some
@@ -524,11 +530,13 @@ def ensure_index(self, key_or_list, unique=False, ttl=300):
524530 created. Returns ``None`` if the index already exists.
525531
526532 :Parameters:
527- - `key_or_list`: a single key or a list of (key, direction) pairs
528- specifying the index to ensure
529- - `unique` (optional): should this index guarantee uniqueness?
530- - `ttl` (optional): time window (in seconds) during which this index
531- will be recognized by subsequent calls to :meth:`ensure_index`
533+ - `key_or_list`: a single key or a list of (key, direction)
534+ pairs specifying the index to ensure
535+ - `unique` (optional): should this index guarantee
536+ uniqueness?
537+ - `ttl` (optional): time window (in seconds) during which
538+ this index will be recognized by subsequent calls to
539+ :meth:`ensure_index`
532540 """
533541 if not isinstance (key_or_list , (str , unicode , list )):
534542 raise TypeError ("key_or_list must either be a single key or a list of (key, direction) pairs" )
@@ -665,16 +673,17 @@ def group(self, key, condition, initial, reduce, finalize=None,
665673 def rename (self , new_name ):
666674 """Rename this collection.
667675
668- If operating in auth mode, client must be authorized as an admin to
669- perform this operation. Raises TypeError if new_name is not an instance
670- of (str, unicode). Raises InvalidName if new_name is not a valid
671- collection name.
676+ If operating in auth mode, client must be authorized as an
677+ admin to perform this operation. Raises :class:`TypeError` if
678+ `new_name` is not an instance of :class:`basestring`. Raises
679+ :class:`~pymongo.errors.InvalidName` if `new_name` is not a
680+ valid collection name.
672681
673682 :Parameters:
674683 - `new_name`: new name for this collection
675684 """
676685 if not isinstance (new_name , basestring ):
677- raise TypeError ("new_name must be an instance of (str, unicode) " )
686+ raise TypeError ("new_name must be an instance of basestring " )
678687
679688 if not new_name or ".." in new_name :
680689 raise InvalidName ("collection names cannot be empty" )
@@ -690,14 +699,14 @@ def rename(self, new_name):
690699 self .__database .connection .admin .command (rename_command )
691700
692701 def distinct (self , key ):
693- """Get a list of distinct values for `key` among all documents in this
694- collection.
702+ """Get a list of distinct values for `key` among all documents
703+ in this collection.
695704
696705 Raises :class:`TypeError` if `key` is not an instance of
697- ``(str, unicode)` `.
706+ :class:`basestring `.
698707
699- To get the distinct values for a key in the result set of a query
700- use :meth:`pymongo.cursor.Cursor.distinct`.
708+ To get the distinct values for a key in the result set of a
709+ query use :meth:`~ pymongo.cursor.Cursor.distinct`.
701710
702711 :Parameters:
703712 - `key`: name of key for which we want to get the distinct values
0 commit comments