Query Data

Retrieve multiple data records with filtering, sorting, and pagination. Supports MongoDB-style query operators.

Basic Query

import fetch from "node-fetch";

const response = await fetch(
  "https://api.bluenexus.ai/api/v1/data/memories?page=1&limit=20&sortBy=createdAt&sortOrder=desc",
  {
    headers: {
      Authorization: `Bearer ${USER_ACCESS_TOKEN}`,
    },
  }
);

const result = await response.json();

// Example response:
// {
//   "data": [
//     {
//       "id": "66bd3762c23f9e3f152fb4d1",
//       "title": "Morning Workout",
//       "content": "Completed 30-minute run",
//       "category": "fitness",
//       "createdAt": "2024-12-15T09:00:00.000Z",
//       "updatedAt": "2024-12-15T09:00:00.000Z"
//     }
//   ],
//   "pagination": {
//     "page": 1,
//     "limit": 20,
//     "total": 150,
//     "pages": 8,
//     "hasNext": true,
//     "hasPrev": false
//   }
// }

See

Filter by Field

Filter by Date Range

Complex Filter with Multiple Conditions

Query Filter Reference

BlueNexus supports MongoDB-style query filters. Here are common filter operators:

Operator
Description
Example

$eq

Equal to

{ "category": { "$eq": "fitness" } }

$ne

Not equal to

{ "status": { "$ne": "deleted" } }

$gt

Greater than

{ "score": { "$gt": 80 } }

$gte

Greater than or equal to

{ "createdAt": { "$gte": "2024-12-01T00:00:00.000Z" } }

$lt

Less than

{ "priority": { "$lt": 5 } }

$lte

Less than or equal to

{ "updatedAt": { "$lte": "2024-12-31T23:59:59.999Z" } }

$in

Value in array

{ "category": { "$in": ["work", "personal"] } }

$nin

Value not in array

{ "status": { "$nin": ["archived", "deleted"] } }

$and

Logical AND

{ "$and": [{ "category": "work" }, { "priority": 1 }] }

$or

Logical OR

{ "$or": [{ "urgent": true }, { "priority": 1 }] }

$not

Logical NOT

{ "category": { "$not": { "$eq": "spam" } } }

Sorting and Pagination

Parameter
Description
Default
Range

page

Page number (1-based)

1

≥ 1

limit

Records per page

20

1 - 100

sortBy

Field to sort by

createdAt

createdAt, updatedAt

sortOrder

Sort order

desc

asc, desc

Best Practices

  • Use filters to reduce data transfer instead of fetching all records

  • Implement pagination for large datasets

  • Consider the trade-off between filter complexity and performance

Last updated