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:
- Flow Query Overview — Core concepts, getting a flow collection
- Search —
getOne(),getMany(),query(),count() - Insert —
insertOne(),insertMany() - Update —
updateOne(),updateMany(),updatePatch*() - Delete —
deleteOne(),deleteMany(),expireMany() - Advanced Operations — Field-level mutations with
flowData() - Bulk Transactions — Batch multiple operations atomically
- Aggregations — Aggregate pipelines,
$lookup, vector search
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