findOneAndDelete() - Atomic find and delete
Syntax
Parameters
filter (Object, required)
Filter criteria.
options (Object, optional)
Return value
Default returns deleted document object or null (not found).
If includeResultMetadata: true, return:
⚠️ IMPORTANT NOTE - MongoDB Driver 6.x Compatibility
monSQLize uses MongoDB Node.js driver 6.x, which makes important changes to the return value format of
findOneAndDelete:Driver 6.x (current version):
- By default, the document object is returned directly
- Requires explicit setting of
includeResultMetadata: trueto return complete metadataDriver 5.x and earlier:
- Return complete metadata
{ value, ok, lastErrorObject }by default✅ monSQLize processing:
- This difference has been automatically handled internally, users do not need to care about the driver version
- API behavior remains consistent and backward compatible
- For the current verification entry, see MongoDB Driver Version Compatibility Guide and findOneAnd* Return Value Unified Description
Core Features
Atomic guarantee
Common scenarios
Scenario 1: Task queue consumption
Scenario 2: Session cleanup
Scenario 3: Distributed lock release
Differences from other methods
Related methods
- deleteOne() - deletes a single document (does not return the document)
- deleteMany() - Delete documents in batches
- findOneAndUpdate() - Atomic find and update
- findOneAndReplace() - Atomic find and replace