Browse Source

Change assert statement

ogert 4 years ago
parent
commit
a8bbdb2353
1 changed files with 3 additions and 3 deletions
  1. 3 3
      cdplib/db_handlers/MongodbHandler.py

+ 3 - 3
cdplib/db_handlers/MongodbHandler.py

@@ -97,7 +97,7 @@ class MongodbHandler:
         '''
         self._database[collection_name].drop()
 
-    def create_index(self, collection_name: str, key: str, direction: str='text'):
+    def create_index(self, collection_name: str, key: str, direction: (str, int)='text'):
         '''
         :param str collection_name: name on the collection for which the schema will be set.
         :param str key: Which value should be used as the index.
@@ -108,8 +108,8 @@ class MongodbHandler:
 
         assert(isinstance(collection_name, str)),\
             "Parameter 'collection_name' must be a string type"
-        assert(isinstance(key, str) and key in allowed_directions),\
-            "Parameter 'key' must be a string type and must be one of these values: 1, -1, '2d', 'geoHaystack', '2dsphere', 'hashed', 'text' "
+        assert(isinstance(key, (str, int)) & key in allowed_directions),\
+            "Parameter 'key' must be a string or integer type and must be one of these values: 1, -1, '2d', 'geoHaystack', '2dsphere', 'hashed', 'text' "
         assert(isinstance(direction, str)),\
             "Parameter 'direction' must be a string type"