Skip to content

Commit e25fbdf

Browse files
committed
feat: include conditions to mongodb
Signed-off-by: Otavio Santana <[email protected]>
1 parent fbbc930 commit e25fbdf

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/DocumentQueryConversor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static Bson convert(CriteriaCondition condition) {
7575

7676
}
7777
default -> throw new UnsupportedOperationException("The condition " + condition.condition()
78-
+ " is not supported from mongoDB diana driver");
78+
+ " is not supported from Eclipse JNoSQL driver");
7979
};
8080
}
8181

jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/communication/MongoDBDocumentManagerTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
import org.assertj.core.api.SoftAssertions;
1919
import org.eclipse.jnosql.communication.TypeReference;
2020
import org.eclipse.jnosql.communication.semistructured.CommunicationEntity;
21+
import org.eclipse.jnosql.communication.semistructured.CriteriaCondition;
2122
import org.eclipse.jnosql.communication.semistructured.DatabaseManager;
2223
import org.eclipse.jnosql.communication.semistructured.DeleteQuery;
2324
import org.eclipse.jnosql.communication.semistructured.Element;
2425
import org.eclipse.jnosql.communication.semistructured.Elements;
2526
import org.eclipse.jnosql.communication.semistructured.SelectQuery;
2627
import org.eclipse.jnosql.databases.mongodb.communication.type.Money;
28+
import org.eclipse.jnosql.mapping.semistructured.MappingQuery;
2729
import org.junit.jupiter.api.Assertions;
2830
import org.junit.jupiter.api.BeforeAll;
2931
import org.junit.jupiter.api.BeforeEach;
@@ -627,6 +629,51 @@ void shouldInsertUUID() {
627629

628630
}
629631

632+
@Test
633+
void shouldFindContains() {
634+
var entity = getEntity();
635+
636+
entityManager.insert(entity);
637+
var query = new MappingQuery(Collections.emptyList(), 0L, 0L, CriteriaCondition.contains(Element.of("name",
638+
"lia")), COLLECTION_NAME, Collections.emptyList());
639+
640+
var result = entityManager.select(query).toList();
641+
SoftAssertions.assertSoftly(softly -> {
642+
softly.assertThat(result).hasSize(1);
643+
softly.assertThat(result.get(0).find("name").orElseThrow().get(String.class)).isEqualTo("Poliana");
644+
});
645+
}
646+
647+
@Test
648+
void shouldStartsWith() {
649+
var entity = getEntity();
650+
651+
entityManager.insert(entity);
652+
var query = new MappingQuery(Collections.emptyList(), 0L, 0L, CriteriaCondition.startsWith(Element.of("name",
653+
"Pol")), COLLECTION_NAME, Collections.emptyList());
654+
655+
var result = entityManager.select(query).toList();
656+
SoftAssertions.assertSoftly(softly -> {
657+
softly.assertThat(result).hasSize(1);
658+
softly.assertThat(result.get(0).find("name").orElseThrow().get(String.class)).isEqualTo("Poliana");
659+
});
660+
}
661+
662+
@Test
663+
void shouldEndsWith() {
664+
var entity = getEntity();
665+
666+
entityManager.insert(entity);
667+
var query = new MappingQuery(Collections.emptyList(), 0L, 0L, CriteriaCondition.endsWith(Element.of("name",
668+
"ana")), COLLECTION_NAME, Collections.emptyList());
669+
670+
var result = entityManager.select(query).toList();
671+
SoftAssertions.assertSoftly(softly -> {
672+
softly.assertThat(result).hasSize(1);
673+
softly.assertThat(result.get(0).find("name").orElseThrow().get(String.class)).isEqualTo("Poliana");
674+
});
675+
}
676+
630677

631678
private CommunicationEntity createDocumentList() {
632679
CommunicationEntity entity = CommunicationEntity.of("AppointmentBook");

0 commit comments

Comments
 (0)