diff --git a/src/querytyper/mongo/query.py b/src/querytyper/mongo/query.py index 70a6130..6f52945 100644 --- a/src/querytyper/mongo/query.py +++ b/src/querytyper/mongo/query.py @@ -172,7 +172,13 @@ def __contains__( other: T, ) -> QueryCondition: """Overload in operator.""" - return regex_query(self.name, re.compile(other)) + if not issubclass(cast(type, self.field_type), str): + raise TypeError( + f"Cannot check if field {self.name} contains {other} because {self.name} is not a subclass of str but {self.field_type}" + ) + if not isinstance(other, str): + raise ValueError("Comparison value must be a valid string.") + return self == {"$regex": other} def exists( diff --git a/tests/mongo/test_pymongo_integration.py b/tests/mongo/test_pymongo_integration.py index 01ae691..898512e 100644 --- a/tests/mongo/test_pymongo_integration.py +++ b/tests/mongo/test_pymongo_integration.py @@ -30,6 +30,6 @@ def test_integration_with_pymongo() -> None: assert found_dummy.int_field == 1 query = MongoQuery("test" in QueryModel.str_field) assert isinstance(query, dict) - # assert query + assert query found_docs = list(collection.find(query)) assert len(found_docs) == doc_num