Aerostack
bar_chart

data-filter-query Edge Function — Data

Data

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.

navin @navin verified
Updated Mar 12, 2026
GitHub

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.

terminal — aerostack cli
$ npx aerostack add navin/data-filter-query
smart_toy

Use with AI Assistants

MCP

Connect 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.

claude_desktop_config.json
{
  "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
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" }
  • $regex uses JavaScript's RegExp — pattern is the string form without slashes
  • $exists: true matches fields that are not undefined; $exists: false matches missing fields

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

data
deployed_code

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 →

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.