|
@@ -121,7 +121,7 @@ class MongodbHandler:
|
|
|
except Exception as error:
|
|
|
self._log.log_and_raise_error(('Couldnt drop the collection {}. Error: {}').format(collection_name, error))
|
|
|
|
|
|
- def create_index(self, collection_name: str, key: str, direction: (str, int)='text'):
|
|
|
+ def create_index(self, collection_name: str, key: (str, int, list), 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.
|
|
@@ -132,14 +132,21 @@ class MongodbHandler:
|
|
|
|
|
|
assert(isinstance(collection_name, str)),\
|
|
|
"Parameter 'collection_name' must be a string type"
|
|
|
- assert(isinstance(key, (str, int))),\
|
|
|
- "Parameter 'key' must be a string or integer type"
|
|
|
+ assert(isinstance(key, (str, int, list))),\
|
|
|
+ "Parameter 'key' must be a string, integer or list type"
|
|
|
assert(direction in allowed_directions),\
|
|
|
"Parameter 'key' must be one of these values: 1, -1, '2d', 'geoHaystack', '2dsphere', 'hashed', 'text' "
|
|
|
assert(isinstance(direction, str)),\
|
|
|
"Parameter 'direction' must be a string type"
|
|
|
+ if type(key) == list:
|
|
|
|
|
|
- self._database[collection_name].create_index([(key, direction)], name=key)
|
|
|
+ key_list=[]
|
|
|
+ for item in key:
|
|
|
+ key_list.append((item,direction))
|
|
|
+
|
|
|
+ self._database[collection_name].create_index(key_list,name='_'.join(key))
|
|
|
+ else:
|
|
|
+ self._database[collection_name].create_index([(key, direction)], name=key)
|
|
|
|
|
|
|
|
|
def set_collection_schema(self, collection_name: str, schema_path: str,
|
|
@@ -228,7 +235,6 @@ class MongodbHandler:
|
|
|
data = data.iloc[0]
|
|
|
elif type(data) is list:
|
|
|
data = data[0]
|
|
|
-
|
|
|
self._database[collection_name].insert_one(data)
|
|
|
else:
|
|
|
self._database[collection_name].insert_many(data, ordered=ordered)
|