Legacy API
This page documents the legacy @logic-bee/flow-query package, which has been superseded by @logic-bee/data-flow. See Writing documents and the migration guide for equivalents. New code should use the new API.
Delete
Delete a document by setting the document status to "deleted" or removing it from the database completely.
deleteOne()
// -->Get: the flow collection
const flowCollection = bob.flowGlobal.getFlowCollection(bob.cfpPath);
// -->Delete: delete a document by id
const delete$ = await flowCollection.docs.flowQuery()
.addPolicy('canDelete')
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.docId(bob.dataPayload.docId)
.deleteOne();
deleteMany()
// -->Get: the flow collection
const flowCollection = bob.flowGlobal.getFlowCollection(bob.cfpPath);
// -->Delete: multiple documents by id
const delete$ = await flowCollection.docs.flowQuery()
.addPolicy('canDelete')
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.docIds(bob.dataPayload.docIds)
.deleteMany();
// -->Delete: multiple documents by id with a session
const delete$ = await flowCollection.docs.flowQuery()
.addPolicy('canDelete')
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.docIds(bob.dataPayload.docIds)
.deleteMany(bob.dbSession());
// -->Delete: multiple documents and remove from disk completely
const delete$ = await flowCollection.docs.flowQuery()
.addPolicy('canDelete')
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.docIds(bob.dataPayload.docIds)
.deleteMany(bob.dbSession(), true);
// -->Delete: by query and remove from disk completely
const delete$ = await flowCollection.docs.flowQuery()
.addPolicy('canDelete')
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.query({
'data.ownerId': bob.dataPayload.userId
})
.deleteMany(undefined, true);
expireMany()
Mark documents for deletion by setting an expiration time (in seconds).
await flowCollection.docs.flowQuery()
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.addPolicy('canUpdate')
.limit(1000)
.query({
'data.checksum': 'jbadyuguasd'
})
.expireMany(60);
Best Practices
✅ DOs:
- Always use
bob.dbSession()for delete operations - Always add the
canDeletepolicy to the delete flow query flowDocsis always an array (support bulk by default)
❌ DON'Ts:
- Do not run the query without
bob.dbSession()
Full Example: Frontend to Backend
- Frontend
- Request Payload
- Request Configuration
- Action
- Response
docIds = ['asdjbasuydasd']
// -->Execute: deleting docs
this.naoFlowService.reqData({
cfpSlug: 'projects',
action: 'data/delete-by-id',
data: { docIds },
naoQueryOptions: { docName: 'project', cfpPath: 'projects/projects' }
})
.execute()
.subscribe({
next: (res) => {
//
},
error: (err) => {
//
},
complete: () => {
//
},
});
{
"data": {
"naoQueryOptions": {
"docName": "project",
"cfpPath": "project/project"
},
"data": {
"docIds": ["jbasdygauygsduyasd"]
}
}
}
{
cfpPath: 'projects/projects',
slug: 'projects',
requestPresets: [
{
action: 'delete-by-id',
dataType: 'data',
requestTypes: ['POST', 'manual'],
compatibleFlowDocs: [
{ docType: 'project' }
],
allowPublicRequests: false,
jobs: [
{ eventName: 'nao-app-data/nao-app-data.data.validateCrudRequest', setInitialPayload: true, options: { requestType: 'getOneOrMultipleIds' } },
{ eventName: 'nao-app-data/nao-app-data.crudHooks.deleteById', returnPayload: true },
]
},
]
}
/**
* Delete one or more documents by id
*/
public static deleteDocument() {
return async (bob: BobRequest<{
data: {
data: { docIds: string[] },
naoQueryOptions: NaoQueryOptions
}
}>) => {
let ok = true, error: any = null, data;
try {
let flowDocs;
// -->Get: the flow collection
const flowCollection = bob.flowGlobal.getFlowCollection(bob.cfpPath);
// -->Query: set the query to the current document and flow collection
const delete$ = flowCollection.docs.flowQuery()
.addPolicy('canDelete')
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.docIds(bob.dataPayload.docIds)
.deleteMany(bob.dbSession());
// -->Set: the status
ok = delete$.ok;
data = delete$;
} catch (err) {
error = err;
ok = false;
}
// -->Return: result
return returnEventResult(bob, {ok, error, data});
};
}
{
"ok": true,
"meta": {
"workerId": "worker-101",
"requestId": "YSJPi7iNiBh",
"events": [
{
"eventName": "nao-app-data/nao-app-data.data.validateCrudRequest",
"ms": 8.65775
},
{
"eventName": "nao-app-data/nao-app-data.crudHooks.deleteById",
"ms": 212.63528399999998
}
],
"request": {
"eventName": "request",
"ms": 234.604202
},
"mode": "active",
"total": 3,
"jobsLog": []
},
"returnType": "data",
"eventType": "data",
"data": {
"ok": true,
"docIds": [
"asdjbasuydasd"
],
"hash": "Im3EL-aZh4tQU1iuSWRaD",
"transactionId": "nuwiSBgJruTWaw4t0YZhY"
}
}