Skip to content

Commit f801a6c

Browse files
Jeny SadadiaJenySadadia
authored andcommitted
api.db: enable in and nin query operators
`in` operator: Enable support for query operator to return documents by matching field value from a list of multiple values. For instance nodes with state `running` and `done` can be retrieved by the following request: `http://API_URL/nodes?state__in=running,done` Multiple values should be comma-separated in the request URL. `nin` operator: Enable support for query operator to return documents that do not match any of the field value from a list of multiple values. For instance nodes with state other than `running` and `done` can be retrieved by the following request: `http://API_URL/nodes?state__nin=running,done` Multiple values should be comma-separated in the request URL just as `in` operator. Signed-off-by: Jeny Sadadia <jeny.sadadia@collabora.com>
1 parent c2b3b56 commit f801a6c

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

api/db.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class Database:
3737
'gte': '$gte',
3838
'ne': '$ne',
3939
're': '$regex',
40+
'in': '$in',
41+
'nin': '$nin',
4042
}
4143

4244
BOOL_VALUE_MAP = {
@@ -138,6 +140,9 @@ def _translate_operators(self, attributes):
138140
for op_name, op_value in value.items():
139141
op_key = self.OPERATOR_MAP.get(op_name)
140142
if op_key:
143+
if op_key in ('$in', '$nin'):
144+
# Create a list of values from ',' separated string
145+
op_value = op_value.split(",")
141146
if isinstance(op_value, str) and op_value.isdecimal():
142147
op_value = int(op_value)
143148
if translated_attributes.get(key):

0 commit comments

Comments
 (0)