data-filter-query Edge Function — Data
DataFilters an array of objects using a MongoDB-style query language supporting $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists, $regex, $and, $or, $not operators.
Edge function data-filter-query Filters an array of objects using a MongoDB-style query language supporting $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists, $regex, $and, $or, $not operators.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.
npx aerostack add navin/data-filter-query Use with AI Assistants
MCPConnect Claude, Cursor, or any MCP-compatible client — then call this function by slug
① Add MCP Server
Add this once — access all Aerostack functions from your AI tool.
{
"mcpServers": {
"aerostack": {
"url": "https://mcp.aerostack.dev",
"type": "http"
}
}
} ② Call this function
Ask your AI to use the call_function tool with this slug:
call_function({
slug: "data-filter-query",
args: {
"items": null,
"query": null
}
}) data-filter-query — MongoDB-style array filtering
Filters an array of objects using a MongoDB-style query language with comparison, logical, and regex operators.
API
POST /api/data-filter-query
Request body
| Field | Type | Required | Description |
|---|---|---|---|
items |
object[] |
✅ | Array of objects to filter |
query |
object |
✅ | Filter query using operators |
Supported operators:
| Operator | Description |
|---|---|
$eq |
Equal (also implicit: { field: value }) |
$ne |
Not equal |
$gt |
Greater than |
$gte |
Greater than or equal |
$lt |
Less than |
$lte |
Less than or equal |
$in |
Value in array |
$nin |
Value not in array |
$exists |
Field exists (true/false) |
$regex |
String matches regex pattern |
$and |
All conditions must match |
$or |
At least one condition must match |
$not |
Negates a condition |
Success response (200)
{
"success": true,
"data": {
"items": [{ "name": "Alice", "role": "admin" }],
"count": 1,
"total": 4
}
}
Error responses
| Code | HTTP | When |
|---|---|---|
INVALID_INPUT |
400 | Missing or invalid field |
INTERNAL_ERROR |
500 | Unexpected error |
Usage
cURL
curl -X POST "$FUNCTION_URL" \
-H "Content-Type: application/json" \
-d '{"items": [{"name":"Alice","age":30},{"name":"Bob","age":20}], "query": {"age": {"$gte": 25}}}'
TypeScript / JavaScript (HTTP)
const response = await fetch(FUNCTION_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
items: users,
query: { $and: [{ role: 'admin' }, { age: { $gte: 25 } }] },
}),
});
const { data } = await response.json();
console.log(data.items, data.count);
Direct import (Node / Bun / Deno)
import { filterQuery } from '@aerostack/functions/data-filter-query';
const { items, count } = filterQuery({ items: records, query: { status: 'active' } });
Use Cases
- Filtering in-memory datasets before displaying to a user without a database round-trip
- Building dynamic search/filter UIs where query conditions are constructed from user input
- Implementing configurable workflow conditions on JSON payloads
Notes
- Dot notation is supported for nested field access:
{ "user.role": "admin" } $regexuses JavaScript'sRegExp— pattern is the string form without slashes$exists: truematches fields that are notundefined;$exists: falsematches missing fields
Metadata
Tags
Publisher
@navin verified
Build and publish your own functions
Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.
More Data Functions
Browse Data Functions →data-aggregate-stats
by @navin
Computes descriptive statistics (count, sum, min, max, mean, median, stdDev, variance, percentiles) for an array of numbers.
data-array-group-by
by @navin
Groups an array of objects into a map keyed by the value of a specified property. Zero dependencies.
data-csv-parse
by @navin
Parses a CSV string into an array of row objects with headers, handling quoted fields, custom delimiters, and escaped characters.
data-csv-to-json
by @navin
Converts a CSV string to a typed JSON array, automatically inferring numbers, booleans, and null values from string fields.
data-deep-diff
by @navin
Computes a structural deep diff between two JSON-serializable values, classifying each change as added, removed, or modified.
data-sort-objects
by @navin
Sorts an array of objects by one or more fields with configurable direction, null handling, and nested field dot-notation support.
Frequently asked questions
What does the data-filter-query function do? +
data-filter-query is a serverless edge function for data automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.
How do I deploy the data-filter-query function? +
Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/data-filter-query ``` It will be live on Cloudflare Workers in seconds.
What runtime does data-filter-query use? +
data-filter-query runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.
Can I customise the data-filter-query function? +
Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.