Skip to main content
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 canDelete policy to the delete flow query
  • flowDocs is always an array (support bulk by default)

❌ DON'Ts:

  • Do not run the query without bob.dbSession()

Full Example: Frontend to Backend

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: () => {
//
},
});