@@ -314,60 +314,54 @@ def update(self, spec, document,
314314 message .update (self .__full_name , upsert , multi ,
315315 spec , document , safe ), safe )
316316
317- def remove (self , spec_or_object_id = None , safe = False ):
317+ def remove (self , spec_or_id = None , safe = False ):
318318 """Remove a document(s) from this collection.
319319
320320 .. warning:: Calls to :meth:`remove` should be performed with
321321 care, as removed data cannot be restored.
322322
323- Raises :class:`~pymongo.errors.TypeError` if
324- `spec_or_object_id` is not an instance of (``dict``,
325- :class:`~pymongo.objectid.ObjectId`). If `safe` is ``True``
326- then the remove operation will be checked for errors, raising
323+ If `safe` is ``True`` then the remove operation will be
324+ checked for errors, raising
327325 :class:`~pymongo.errors.OperationFailure` if one
328326 occurred. Safe removes wait for a response from the database,
329327 while normal removes do not.
330328
331- If no `spec_or_object_id ` is given all documents in this
332- collection will be removed. This is not equivalent to calling
333- :meth:`~pymongo.database.Database.drop_collection`, however, as
334- indexes will not be removed.
329+ If `spec_or_id ` is ``None``, all documents in this collection
330+ will be removed. This is not equivalent to calling
331+ :meth:`~pymongo.database.Database.drop_collection`, however,
332+ as indexes will not be removed.
335333
336334 If `safe` is ``True`` returns the response to the *lastError*
337335 command. Otherwise, returns ``None``.
338336
339337 :Parameters:
340- - `spec_or_object_id` (optional): a ``dict`` or
341- :class:`~pymongo.son.SON` instance specifying which documents
342- should be removed; or an instance of
343- :class:`~pymongo.objectid.ObjectId` specifying the value of the
344- ``_id`` field for the document to be removed
338+ - `spec_or_id` (optional): a dictionary specifying the
339+ documents to be removed OR any other type specifying the
340+ value of ``"_id"`` for the document to be removed
345341 - `safe` (optional): check that the remove succeeded?
346342
343+ .. versionchanged:: 1.6+
344+ Accept any type other than a ``dict`` instance for removal
345+ by ``"_id"``, not just :class:`~pymongo.objectid.ObjectId`
346+ instances.
347347 .. versionchanged:: 1.4
348348 Return the response to *lastError* if `safe` is ``True``.
349349 .. versionchanged:: 1.2
350- The `spec_or_object_id ` parameter is now optional. If it is
350+ The `spec_or_id ` parameter is now optional. If it is
351351 not specified *all* documents in the collection will be
352352 removed.
353353 .. versionadded:: 1.1
354354 The `safe` parameter.
355355
356356 .. mongodoc:: remove
357357 """
358- #TODO accept anything but dict as an _id
359- spec = spec_or_object_id
360- if spec is None :
361- spec = {}
362- if isinstance (spec , ObjectId ):
363- spec = {"_id" : spec }
364-
365- if not isinstance (spec , dict ):
366- raise TypeError ("spec must be an instance of dict, not %s" %
367- type (spec ))
358+ if spec_or_id is None :
359+ spec_or_id = {}
360+ if not isinstance (spec_or_id , dict ):
361+ spec_or_id = {"_id" : spec_or_id }
368362
369363 return self .__database .connection ._send_message (
370- message .delete (self .__full_name , spec , safe ), safe )
364+ message .delete (self .__full_name , spec_or_id , safe ), safe )
371365
372366 def find_one (self , spec_or_id = None , * args , ** kwargs ):
373367 """Get a single document from the database.
0 commit comments