Skip to content

Commit be37048

Browse files
committed
DBPort.findOne returns null if no result rather than throw
1 parent 56a5d9f commit be37048

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/com/mongodb/DBPort.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ synchronized DBObject findOne( DB db , String coll , DBObject q ){
113113

114114
try {
115115
Response res = go( msg , db.getCollection( coll ) );
116-
if ( res.size() != 1 )
116+
if ( res.size() == 0 )
117+
return null;
118+
if ( res.size() > 1 )
117119
throw new MongoInternalException( "something is wrong. size:" + res.size() );
118120
return res.get(0);
119121
}
@@ -124,7 +126,10 @@ synchronized DBObject findOne( DB db , String coll , DBObject q ){
124126
}
125127

126128
synchronized CommandResult runCommand( DB db , DBObject cmd ) {
127-
return (CommandResult)findOne( db , "$cmd" , cmd );
129+
DBObject res = findOne( db , "$cmd" , cmd );
130+
if ( res == null )
131+
throw new MongoInternalException( "something is wrong, no command result" );
132+
return (CommandResult)res;
128133
}
129134

130135
synchronized CommandResult tryGetLastError( DB db , long last, WriteConcern concern){

0 commit comments

Comments
 (0)