mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-25 19:59:54 -05:00
### Does this PR have any customer impact? No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Feature
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) No
### Are you introducing any new config? If yes, do you have tests with and without them being set? No
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
Support `let` variables and `$$NOW` in delete queries.
The values of the variables can be accessed in the query by using `$expr`.
Example:
```
{
delete: <collection>,
deletes: [
{
q: {$expr: {$eq: ["$_id", "$$varRef"]}},
limit: 0, // multi
}
],
let: {"varRef": 1},
...
}
```
We parse the `let` value (together with the time system variables - `$$NOW`) and propagate it through the aggregation and variable contexts.
----
#### AI description (iteration 1)
#### PR Classification
New feature
#### PR Summary
This pull request adds support for the `let` clause in delete operations.
- `delete.c`: Implemented logic to handle `let` clause in delete queries, including variable specification and collation.
- `bson_aggregation_pipeline_tests_let.out`: Added extensive test cases to validate the new `let` clause functionality in delete operations.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
Related work items: #3423118, #3613877
62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
/*-------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
*
|
|
* include/commands/delete.h
|
|
*
|
|
* Exports related to implementation of a single-document delete.
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef DELETE_H
|
|
#define DELETE_H
|
|
|
|
#include <postgres.h>
|
|
|
|
#include "metadata/collection.h"
|
|
|
|
|
|
/*
|
|
* DeleteOneParams describes delete operation for a single document.
|
|
*/
|
|
typedef struct
|
|
{
|
|
/* list of Deletions */
|
|
const bson_value_t *query;
|
|
|
|
/* sort order to use when selecting 1 row */
|
|
const bson_value_t *sort;
|
|
|
|
/* whether to return deleted document */
|
|
bool returnDeletedDocument;
|
|
|
|
/* fields to return if returning a document */
|
|
const bson_value_t *returnFields;
|
|
|
|
/* parsed variable spec*/
|
|
const bson_value_t *variableSpec;
|
|
} DeleteOneParams;
|
|
|
|
|
|
/*
|
|
* DeleteOneRow reflects the result of a single-row delete
|
|
* on a single shard.
|
|
*/
|
|
typedef struct
|
|
{
|
|
/* whether one row matched the query and was deleted */
|
|
bool isRowDeleted;
|
|
|
|
/* object_id of the deleted document (only used within delete_one) */
|
|
pgbson *objectId;
|
|
|
|
/* value of the deleted (and maybe projected) document, if requested and matched any */
|
|
pgbson *resultDeletedDocument;
|
|
} DeleteOneResult;
|
|
|
|
|
|
void CallDeleteOne(MongoCollection *collection, DeleteOneParams *deleteOneParams,
|
|
int64 shardKeyHash, text *transactionId, bool forceInlineWrites,
|
|
DeleteOneResult *result);
|
|
|
|
#endif
|