Skip to content

Commit defc4a7

Browse files
JAVA-444: query before insert on index creation.
1 parent 9701ea6 commit defc4a7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main/com/mongodb/DBApiLayer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,10 @@ public void createIndex( final DBObject keys, final DBObject options, DBEncoder
359359
full.put( k , options.get( k ) );
360360
full.put( "key" , keys );
361361

362-
DBApiLayer.this.doGetCollection( "system.indexes" ).insert( new DBObject[]{ full } , false , WriteConcern.SAFE, encoder );
362+
DBCollection idxs = DBApiLayer.this.doGetCollection( "system.indexes" );
363+
//query first, maybe we should do an update w/upsert? -- need to test performance and lock behavior
364+
if ( idxs.findOne( full ) == null )
365+
idxs.insert( new DBObject[] { full }, WriteConcern.SAFE, encoder );
363366
}
364367

365368
final String _fullNameSpace;

0 commit comments

Comments
 (0)