@@ -723,6 +723,82 @@ void testDropIndexes_twoIndexesWithTheSameKey() {
723723 );
724724 }
725725
726+ // https://github.com/bwaldvogel/mongo-java-server/issues/246
727+ @ Test
728+ void testDropIndexes_string_twoIndexesWithTheSameKey () {
729+ collection .insertOne (json ("_id: 1, c: 10" ));
730+
731+ MongoCollection <Document > otherCollection = getCollection ("other" );
732+ otherCollection .insertOne (json ("_id: 1, c: 10" ));
733+
734+ String indexName = collection .createIndex (new Document ("c" , 1 ));
735+ otherCollection .createIndex (new Document ("c" , 1 ));
736+
737+ assertThat (collection .listIndexes ())
738+ .containsExactlyInAnyOrder (
739+ json ("key: {_id: 1}" ).append ("name" , "_id_" ).append ("v" , 2 ),
740+ json ("key: {c: 1}" ).append ("name" , "c_1" ).append ("v" , 2 )
741+ );
742+
743+ assertThat (otherCollection .listIndexes ())
744+ .containsExactlyInAnyOrder (
745+ json ("key: {_id: 1}" ).append ("name" , "_id_" ).append ("v" , 2 ),
746+ json ("key: {c: 1}" ).append ("name" , "c_1" ).append ("v" , 2 )
747+ );
748+
749+ collection .dropIndex (indexName );
750+
751+ assertThat (collection .listIndexes ())
752+ .containsExactlyInAnyOrder (
753+ json ("key: {_id: 1}" ).append ("name" , "_id_" ).append ("v" , 2 )
754+ );
755+
756+ assertThat (otherCollection .listIndexes ())
757+ .containsExactlyInAnyOrder (
758+ json ("key: {_id: 1}" ).append ("name" , "_id_" ).append ("v" , 2 ),
759+ json ("key: {c: 1}" ).append ("name" , "c_1" ).append ("v" , 2 )
760+ );
761+ }
762+
763+ // https://github.com/bwaldvogel/mongo-java-server/issues/247
764+ @ Test
765+ void testDropIndexes_all () {
766+ collection .insertOne (json ("_id: 1, c: 10, d:1" ));
767+
768+ MongoCollection <Document > otherCollection = getCollection ("other" );
769+ otherCollection .insertOne (json ("_id: 1, c: 10" ));
770+
771+ collection .createIndex (new Document ("c" , 1 ));
772+ collection .createIndex (new Document ("d" , 1 ));
773+ otherCollection .createIndex (new Document ("c" , 1 ));
774+
775+ assertThat (collection .listIndexes ())
776+ .containsExactlyInAnyOrder (
777+ json ("key: {_id: 1}" ).append ("name" , "_id_" ).append ("v" , 2 ),
778+ json ("key: {c: 1}" ).append ("name" , "c_1" ).append ("v" , 2 ),
779+ json ("key: {d: 1}" ).append ("name" , "d_1" ).append ("v" , 2 )
780+ );
781+
782+ assertThat (otherCollection .listIndexes ())
783+ .containsExactlyInAnyOrder (
784+ json ("key: {_id: 1}" ).append ("name" , "_id_" ).append ("v" , 2 ),
785+ json ("key: {c: 1}" ).append ("name" , "c_1" ).append ("v" , 2 )
786+ );
787+
788+ collection .dropIndex ("*" );
789+
790+ assertThat (collection .listIndexes ())
791+ .containsExactlyInAnyOrder (
792+ json ("key: {_id: 1}" ).append ("name" , "_id_" ).append ("v" , 2 )
793+ );
794+
795+ assertThat (otherCollection .listIndexes ())
796+ .containsExactlyInAnyOrder (
797+ json ("key: {_id: 1}" ).append ("name" , "_id_" ).append ("v" , 2 ),
798+ json ("key: {c: 1}" ).append ("name" , "c_1" ).append ("v" , 2 )
799+ );
800+ }
801+
726802 @ Test
727803 public void testCurrentOperations () {
728804 Document currentOperations = getAdminDb ().getCollection ("$cmd.sys.inprog" ).find ().first ();
0 commit comments