Browse Source

First implementation of the insert method in the mongodb datasource

Roland Haroutiounian 9 years ago
parent
commit
b17259cf02
2 changed files with 13 additions and 4 deletions
  1. 12
    3
      lodel/datasource/mongodb/datasource.py
  2. 1
    1
      lodel/datasource/mongodb/utils.py

+ 12
- 3
lodel/datasource/mongodb/datasource.py View File

@@ -105,9 +105,18 @@ class MongoDbDataSource(object):
105 105
         return result.deleted_count
106 106
 
107 107
     ## @brief updates one or a list of records
108
-    # @todo to be implemented
109
-    def update(self, target_cls, uid, **datas):
110
-        pass
108
+    # @param target_cls Emclass : class of the object to insert
109
+    # @param uids list : list of uids to update
110
+    # @param datas dict : datas to update (new values)
111
+    # @return int : Number of updated records
112
+    # @todo check if the values need to be parsed
113
+    def update(self, target_cls, uids, **datas):
114
+        if not isinstance(uids, list):
115
+            uids = [uids]
116
+        collection_name = utils.object_collection_name(target_cls.__class__)
117
+        collection = self.database[collection_name]
118
+        results = collection.update_many({'uid': {'$in': uids}}, datas)
119
+        return results.modified_count()
111 120
 
112 121
     ## @brief Inserts a record in a given collection
113 122
     # @param target_cls Emclass : class of the object to insert

+ 1
- 1
lodel/datasource/mongodb/utils.py View File

@@ -16,7 +16,7 @@ LODEL_OPERATORS_MAP = {
16 16
     '>': {'name': '$gt', 'value_type': None},
17 17
     ' in ': {'name': '$in', 'value_type': list},
18 18
     ' not in ': {'name': '$nin', 'value_type': list},
19
-    ' like ': {'name': '$eq', 'value_type': str},
19
+    ' like ': {'name': '$text', 'value_type': str},
20 20
     ' not like ': {'name': '', 'value_type': str},  # TODO Add the operator
21 21
     'OR': {'name': '$or', 'value_type': list},
22 22
     'AND': {'name': '$and', 'value_type': list}

Loading…
Cancel
Save