|
@@ -13,7 +13,7 @@ from lodel import logger
|
13
|
13
|
from lodel.leapi.leobject import CLASS_ID_FIELDNAME
|
14
|
14
|
|
15
|
15
|
from . import utils
|
16
|
|
-from .utils import object_collection_name,\
|
|
16
|
+from .utils import object_collection_name, collection_name, \
|
17
|
17
|
MONGODB_SORT_OPERATORS_MAP, connection_string
|
18
|
18
|
|
19
|
19
|
class MongoDbDataSourceError(Exception):
|
|
@@ -133,13 +133,14 @@ class MongoDbDatasource(object):
|
133
|
133
|
query_result_ordering = None
|
134
|
134
|
if order is not None:
|
135
|
135
|
query_result_ordering = utils.parse_query_order(order)
|
136
|
|
- results_field_list = None if len(field_list) == 0 else field_list
|
137
|
|
- limit = limit if limit is not None else 0
|
138
|
|
-
|
|
136
|
+
|
139
|
137
|
if group is None:
|
140
|
138
|
cursor = collection.find(
|
141
|
|
- filter=query_filters, projection=results_field_list,
|
142
|
|
- skip=offset, limit=limit, sort=query_result_ordering)
|
|
139
|
+ spec = query_filters,
|
|
140
|
+ fields=field_list,
|
|
141
|
+ skip=offset,
|
|
142
|
+ limit=limit if limit != None else 0,
|
|
143
|
+ sort=query_result_ordering)
|
143
|
144
|
else:
|
144
|
145
|
pipeline = list()
|
145
|
146
|
unwinding_list = list()
|
|
@@ -252,7 +253,8 @@ class MongoDbDatasource(object):
|
252
|
253
|
fname, op, val))
|
253
|
254
|
del(new_filters[i])
|
254
|
255
|
new_filters.append(
|
255
|
|
- (CLASS_ID_FIELDNAME, '=', target_child.__name__))
|
|
256
|
+ (CLASS_ID_FIELDNAME, '=',
|
|
257
|
+ collection_name(target_child.__name__)))
|
256
|
258
|
result += act(
|
257
|
259
|
target = target_child,
|
258
|
260
|
filters = new_filters,
|
|
@@ -436,17 +438,33 @@ class MongoDbDatasource(object):
|
436
|
438
|
@classmethod
|
437
|
439
|
def __filters2mongo(cls, filters):
|
438
|
440
|
res = dict()
|
|
441
|
+ eq_fieldname = [] #Stores field with equal comparison OP
|
439
|
442
|
for fieldname, op, value in filters:
|
440
|
443
|
oop = op
|
441
|
444
|
ovalue = value
|
442
|
445
|
op, value = cls.__op_value_conv(op, value)
|
|
446
|
+ if op == '=':
|
|
447
|
+ eq_fieldname.append(fieldname)
|
|
448
|
+ if fieldname in res:
|
|
449
|
+ logger.warning("Dropping previous condition. Overwritten \
|
|
450
|
+by an equality filter")
|
|
451
|
+ res[fieldname] = str(value)
|
|
452
|
+ continue
|
|
453
|
+ if fieldname in eq_fieldname:
|
|
454
|
+ logger.warning("Dropping condition : '%s %s %s'" % (
|
|
455
|
+ fieldname, op, value))
|
|
456
|
+ continue
|
|
457
|
+
|
443
|
458
|
if fieldname not in res:
|
444
|
459
|
res[fieldname] = dict()
|
445
|
460
|
if op in res[fieldname]:
|
446
|
461
|
logger.warning("Dropping condition : '%s %s %s'" % (
|
447
|
462
|
fieldname, op, value))
|
448
|
463
|
else:
|
449
|
|
- res[fieldname][op] = value
|
|
464
|
+ if op not in cls.lodel2mongo_op_map:
|
|
465
|
+ raise ValueError("Invalid operator : '%s'" % op)
|
|
466
|
+ new_op = cls.lodel2mongo_op_map[op]
|
|
467
|
+ res[fieldname][new_op] = value
|
450
|
468
|
return res
|
451
|
469
|
|
452
|
470
|
|