File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -916,7 +916,7 @@ def logout(self):
916916 # Sockets will be deauthenticated as they are used.
917917 self .connection ._purge_credentials (self .name )
918918
919- def dereference (self , dbref ):
919+ def dereference (self , dbref , ** kwargs ):
920920 """Dereference a :class:`~bson.dbref.DBRef`, getting the
921921 document it points to.
922922
@@ -928,14 +928,17 @@ def dereference(self, dbref):
928928
929929 :Parameters:
930930 - `dbref`: the reference
931+ - `**kwargs` (optional): any additional keyword arguments
932+ are the same as the arguments to
933+ :meth:`~pymongo.collection.Collection.find`.
931934 """
932935 if not isinstance (dbref , DBRef ):
933936 raise TypeError ("cannot dereference a %s" % type (dbref ))
934937 if dbref .database is not None and dbref .database != self .__name :
935938 raise ValueError ("trying to dereference a DBRef that points to "
936939 "another database (%r not %r)" % (dbref .database ,
937940 self .__name ))
938- return self [dbref .collection ].find_one ({"_id" : dbref .id })
941+ return self [dbref .collection ].find_one ({"_id" : dbref .id }, ** kwargs )
939942
940943 def eval (self , code , * args ):
941944 """Evaluate a JavaScript expression in MongoDB.
Original file line number Diff line number Diff line change @@ -399,6 +399,16 @@ def test_deref(self):
399399 db .test .save (obj )
400400 self .assertEqual (obj , db .dereference (DBRef ("test" , 4 )))
401401
402+ def test_deref_kwargs (self ):
403+ db = self .client .pymongo_test
404+ db .test .remove ({})
405+
406+ db .test .insert ({"_id" : 4 , "foo" : "bar" })
407+ self .assertEqual (SON ([("foo" , "bar" )]),
408+ db .dereference (DBRef ("test" , 4 ),
409+ fields = {"_id" : False },
410+ as_class = SON ))
411+
402412 def test_eval (self ):
403413 db = self .client .pymongo_test
404414 db .test .remove ({})
You can’t perform that action at this time.
0 commit comments