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, Mutations, and the migration guide for equivalents. New code should use the new API.

Update

Updating one or more documents must be executed on a pre-defined flow document and sent to a cfpPath. The document body is validated against the form validators in the frontend and the Joi validator in the backend. For patch requests, validation will be partial — only validating the object keys you sent.

updateOne()

Update a document by its ID.

// -->Get: the flow collection
const flowCollection = bob.flowGlobal.getFlowCollection(bob.cfpPath);
// -->Query: set the query to the current document and flow collection
const update = await flowCollection.docs.flowQuery()
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.docId(bob.dataPayload.docId)
.updateOne({
dataConnections: bob.dataPayload.dataConnections
}, bob.dbSession());

updatePatchOne()

Performs one patch operation on the document based on user payload.

await userFlowCollection.docs.flowQuery()
.user(bob.flowUser)
.flowOptions({ docName: 'doc', cfpPath: 'users/users' })
.docId(bob.flowUser.id)
.updatePatchOne(bob.dataPayload.data, bob.dbSession());

updateMany()

Update multiple documents by updating the entire document body.

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

// -->Update: the documents that match the query
const update = await flowCollection.docs.flowQuery()
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.query({
'data.ownerId': bob.dataPayload.userId
})
.updateMany({
dataConnections: bob.dataPayload.dataConnections
}, bob.dbSession());

// -->Update: the documents with the Ids
const update = await flowCollection.docs.flowQuery()
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.docIds(bob.dataPayload.docIds)
.updateMany({
dataConnections: bob.dataPayload.dataConnections
}, bob.dbSession());

// -->Update: documents that match query but limited and sorted
const update = await flowCollection.docs.flowQuery()
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.query({
'data.ownerId': bob.dataPayload.userId
})
.limit(3)
.skip(2)
.sort({
'info.createdAt': -1
})
.updateMany({
dataConnections: bob.dataPayload.dataConnections
}, bob.dbSession());

updatePatchMany()

Performs a patch operation on multiple documents.

// -->Update: the documents that match the query
const update = await flowCollection.docs.flowQuery()
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.query({
'data.ownerId': bob.dataPayload.userId
})
.updatePatchOne({
dataConnections: bob.dataPayload.dataConnections
}, bob.dbSession());

// -->Update: the documents with the Ids
const update = await flowCollection.docs.flowQuery()
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.docIds(bob.dataPayload.docIds)
.updatePatchMany({
dataConnections: bob.dataPayload.dataConnections
}, bob.dbSession());

// -->Update: documents that match query but limited and sorted
const update = await flowCollection.docs.flowQuery()
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.query({
'data.ownerId': bob.dataPayload.userId
})
.limit(3)
.skip(2)
.sort({
'info.createdAt': -1
})
.updatePatchMany({
dataConnections: bob.dataPayload.dataConnections
}, bob.dbSession());

updateStatus()

// -->Query: update the status of the document
const updateStatus$ = await flowCollection.docs.flowQuery()
.addPolicy('canUpdate')
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions)
.updateStatus('active');

Best Practices

✅ DOs:

  • Always use bob.dbSession() for update operations so they can be reversed if there's an error

❌ DON'Ts:

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