You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -126,10 +130,10 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
126
130
);
127
131
}
128
132
if(isPolymorphicTarget){
129
-
process.env.HEAVY_DEBUG&&console.log(`⚠️ Field '${(filtersasIAdminForthSingleFilter).field}' not found in polymorphic target resource '${resource.resourceId}', allowing query to proceed.`);
133
+
process.env.HEAVY_DEBUG&&console.log(`⚠️ Field '${filtersAsSingle.field}' not found in polymorphic target resource '${resource.resourceId}', allowing query to proceed.`);
130
134
return{ok: true,error: ''};
131
135
}else{
132
-
thrownewError(`Field '${(filtersasIAdminForthSingleFilter).field}' not found in resource '${resource.resourceId}'. ${similar ? `Did you mean '${similar}'?` : ''}`);
136
+
thrownewError(`Field '${filtersAsSingle.field}' not found in resource '${resource.resourceId}'. ${similar ? `Did you mean '${similar}'?` : ''}`);
133
137
}
134
138
}
135
139
// value normalization
@@ -139,7 +143,7 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
139
143
}
140
144
if(filters.value.length===0){
141
145
// nonsense, and some databases might not accept IN []
// if "insecureRawSQL" filter is insecure sql string
156
-
if((filtersasIAdminForthSingleFilter).operator){
157
-
return{ok: false,error: `Field "operator" should not be specified in filter object alongside "insecureRawSQL": ${JSON.stringify(filters)}`};
160
+
if(filtersAsSingle.operator){
161
+
return{ok: false,error: `Field "operator" should not be specified in filter object alongside "insecureRawSQL" or "insecureRawNoSQL": ${JSON.stringify(filters)}`};
return{ok: false,error: `Field "value" should not be specified in filter object alongside "insecureRawSQL": ${JSON.stringify(filters)}`};
163
+
if(filtersAsSingle.value!==undefined){
164
+
return{ok: false,error: `Field "value" should not be specified in filter object alongside "insecureRawSQL" or "insecureRawNoSQL": ${JSON.stringify(filters)}`};
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/03-Customization/03-virtualColumns.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -176,6 +176,48 @@ import sqlstring from 'sqlstring';
176
176
This example will allow to search for some nested field in JSONB column, however you can use any SQL query here.
177
177
178
178
179
+
### Custom Mongo queries with `insecureRawNoSQL`
180
+
181
+
For MongoDB data sources, you can inject a raw Mongo filter object via `insecureRawNoSQL`. This is useful when the built-in filters are not enough or you need dot-notation and operators not covered by AdminForth helpers.
182
+
183
+
Important: The object you provide is sent directly to MongoDB. Validate and sanitize any user inputs to prevent abuse of operators like`$where`, `$regex`, etc.
184
+
185
+
Example — filter by nested field using dot-notation:
186
+
187
+
```ts title='./resources/apartments.ts'
188
+
...
189
+
hooks: {
190
+
list: {
191
+
beforeDatasourceRequest:async ({ query, body }: { query: any, body: any }) => {
192
+
// Add raw Mongo filter: meta.is_active must equal body.is_active
0 commit comments