Skip to content

Commit 3aee72f

Browse files
committed
- JAVA-387: DBCollection#findOne(DBObject o, DBObject fields) doesn't markAsPartialObject
1 parent 4e96ee3 commit 3aee72f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/com/mongodb/DBCollection.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,11 @@ public final DBObject findOne( DBObject o )
556556
*/
557557
public final DBObject findOne( DBObject o, DBObject fields ) {
558558
Iterator<DBObject> i = __find( o , fields , 0 , -1 , 0, getOptions() );
559-
return i == null ? null : i.next();
559+
DBObject obj = (i == null ? null : i.next());
560+
if ( fields != null && fields.keySet().size() > 0 ){
561+
obj.markAsPartialObject();
562+
}
563+
return obj;
560564
}
561565

562566
/**

src/test/com/mongodb/JavaClientTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,24 @@ public void testPartial1()
289289
assertEquals( 1 , out.get( "a" ) );
290290
assertNull( out.get( "b" ) );
291291

292+
// make sure can't insert back partial
293+
try {
294+
c.update(out, out);
295+
assertTrue(false);
296+
} catch (IllegalArgumentException ex) {
297+
}
298+
299+
out = c.findOne( null , BasicDBObjectBuilder.start().add( "b" , 1 ).get() );
300+
assertEquals( 2 , out.get( "b" ) );
301+
assertNull( out.get( "a" ) );
302+
303+
// make sure can't insert back partial
304+
try {
305+
c.update(out, out);
306+
assertTrue(false);
307+
} catch (IllegalArgumentException ex) {
308+
}
309+
292310
}
293311

294312
@Test

0 commit comments

Comments
 (0)