diff --git a/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java b/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java index 060758fe193..0eac9e46c32 100644 --- a/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java +++ b/app/server/appsmith-plugins/mongoPlugin/src/main/java/com/external/plugins/MongoPlugin.java @@ -964,6 +964,7 @@ public Mono getStructure( } return true; }) + .sort((collectionName1, collectionName2) -> collectionName1.compareToIgnoreCase(collectionName2)) .flatMap(collectionName -> { final ArrayList columns = new ArrayList<>(); final ArrayList templates = new ArrayList<>(); diff --git a/app/server/appsmith-plugins/mongoPlugin/src/test/java/com/external/plugins/MongoPluginQueriesTest.java b/app/server/appsmith-plugins/mongoPlugin/src/test/java/com/external/plugins/MongoPluginQueriesTest.java index b221ac9e5ce..1ecb60056ca 100644 --- a/app/server/appsmith-plugins/mongoPlugin/src/test/java/com/external/plugins/MongoPluginQueriesTest.java +++ b/app/server/appsmith-plugins/mongoPlugin/src/test/java/com/external/plugins/MongoPluginQueriesTest.java @@ -655,6 +655,26 @@ public void testStructure() { .verifyComplete(); } + @Test + public void testStructure_should_return_collections_in_order() { + DatasourceConfiguration dsConfig = createDatasourceConfiguration(); + Mono structureMono = pluginExecutor + .datasourceCreate(dsConfig) + .flatMap(connection -> pluginExecutor.getStructure(connection, dsConfig, null)); + + StepVerifier.create(structureMono) + .assertNext(structure -> { + assertNotNull(structure); + assertEquals(3, structure.getTables().size()); + + // Check that the tables are sorted in ascending order + assertEquals("address", structure.getTables().get(0).getName()); + assertEquals("teams", structure.getTables().get(1).getName()); + assertEquals("users", structure.getTables().get(2).getName()); + }) + .verifyComplete(); + } + @Test public void testCountCommand() { DatasourceConfiguration dsConfig = createDatasourceConfiguration();