Skip to main content

Database Query

Logic Bee provides a powerful, built-in data layer called Flow Query that abstracts database operations while enforcing access control, transaction safety, and multi-tenancy.

Getting Started

All database operations go through the Flow Query system. See the dedicated guides for each operation type:

Quick Example

// -->Get: the flow collection
const flowCollection = bob.flowGlobal.getFlowCollection('contacts/contacts');

// -->Search: get a document by ID
const doc = await flowCollection.docs.flowQuery()
.addPolicy('canRead')
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.docId(bob.dataPayload.docId)
.getOne();

Best Practices

  • Always scope queries with .user(bob.flowUser) for access control
  • Always attach bob.dbSession() to write operations for rollback safety
  • Use the appropriate access policy (canRead, canCreate, canUpdate, canDelete)
  • Prefer aggregation pipelines for complex data transformations