File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed
Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 55class DataDocumentsFilter (BaseModel ):
66 key : str
77 value : Any = "" # Can be str, int, etc. depending on the field type
8- operator : Optional [str ] = "equals" # 'equals', 'exists', 'not_exists'
8+ operator : Optional [str ] = "equals" # 'equals', 'exists', 'not_exists'
99
1010
1111class DataDocumentsRequest (BaseModel ):
Original file line number Diff line number Diff line change @@ -102,18 +102,18 @@ def get_query_for_filter(f: dict):
102102 key = f .get ("key" )
103103 value = f .get ("value" )
104104 operator = f .get ("operator" , "equals" )
105-
105+
106106 if not key :
107107 return {}
108-
108+
109109 if operator == "exists" :
110110 return {key : {"$exists" : True }}
111111 if operator == "not_exists" :
112112 return {key : {"$exists" : False }}
113-
113+
114114 if value is None :
115115 return {}
116-
116+
117117 if key == "all" :
118118 sample_doc = collection .find_one ()
119119 if sample_doc :
@@ -134,7 +134,7 @@ def get_query_for_filter(f: dict):
134134 query_val = value
135135 else :
136136 query_val = value
137-
137+
138138 if operator == "not_equals" :
139139 return {key : {"$ne" : query_val }}
140140 if operator == "greater_than" :
@@ -143,7 +143,7 @@ def get_query_for_filter(f: dict):
143143 return {key : {"$lt" : query_val }}
144144 if operator == "contains" :
145145 return {key : {"$regex" : re .escape (str (value )), "$options" : "i" }}
146-
146+
147147 # default equals
148148 if isinstance (query_val , str ) and key != "_id" :
149149 return {key : {"$regex" : re .escape (query_val ), "$options" : "i" }}
You can’t perform that action at this time.
0 commit comments