Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NODE-4014): Add let option to bulk write operations #3160

Merged
merged 8 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Next/assets/search.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/Next/classes/BulkOperationBase.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/Next/classes/OrderedBulkOperation.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/Next/classes/UnorderedBulkOperation.html

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions docs/Next/interfaces/BulkWriteOptions.html

Large diffs are not rendered by default.

Binary file removed docs/img/gray.png
Binary file not shown.
Binary file removed docs/img/logo-mongodb-header.png
Binary file not shown.
2 changes: 2 additions & 0 deletions src/bulk/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,8 @@ export interface BulkWriteOptions extends CommandOperationOptions {
keepGoing?: boolean;
/** Force server to assign _id values instead of driver. */
forceServerObjectId?: boolean;
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
let?: Document;
}

/**
Expand Down
200 changes: 200 additions & 0 deletions test/spec/crud/unified/bulkWrite-deleteMany-let.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
{
"description": "BulkWrite deleteMany-let",
"schemaVersion": "1.0",
"createEntities": [
{
"client": {
"id": "client0",
"observeEvents": [
"commandStartedEvent"
]
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "crud-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "coll0"
}
}
],
"initialData": [
{
"collectionName": "coll0",
"databaseName": "crud-tests",
"documents": [
{
"_id": 1
},
{
"_id": 2
}
]
}
],
"tests": [
{
"description": "BulkWrite deleteMany with let option",
"runOnRequirements": [
{
"minServerVersion": "5.0"
}
],
"operations": [
{
"object": "collection0",
"name": "bulkWrite",
"arguments": {
"requests": [
{
"deleteMany": {
"filter": {
"$expr": {
"$eq": [
"$_id",
"$$id"
]
}
}
}
}
],
"let": {
"id": 1
}
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"delete": "coll0",
"deletes": [
{
"q": {
"$expr": {
"$eq": [
"$_id",
"$$id"
]
}
},
"limit": 0
}
],
"let": {
"id": 1
}
}
}
}
]
}
],
"outcome": [
{
"collectionName": "coll0",
"databaseName": "crud-tests",
"documents": [
{
"_id": 2
}
]
}
]
},
{
"description": "BulkWrite deleteMany with let option unsupported (server-side error)",
"runOnRequirements": [
{
"minServerVersion": "3.6.0",
"maxServerVersion": "4.4.99"
}
],
"operations": [
{
"object": "collection0",
"name": "bulkWrite",
"arguments": {
"requests": [
{
"deleteOne": {
"filter": {
"$expr": {
"$eq": [
"$_id",
"$$id"
]
}
}
}
}
],
"let": {
"id": 1
}
},
"expectError": {
"errorContains": "'delete.let' is an unknown field",
"isClientError": false
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"delete": "coll0",
"deletes": [
{
"q": {
"$expr": {
"$eq": [
"$_id",
"$$id"
]
}
},
"limit": 1
}
],
"let": {
"id": 1
}
}
}
}
]
}
],
"outcome": [
{
"collectionName": "coll0",
"databaseName": "crud-tests",
"documents": [
{
"_id": 1
},
{
"_id": 2
}
]
}
]
}
]
}
86 changes: 86 additions & 0 deletions test/spec/crud/unified/bulkWrite-deleteMany-let.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
description: "BulkWrite deleteMany-let"

schemaVersion: "1.0"

createEntities:
- client:
id: &client0 client0
observeEvents: [ commandStartedEvent ]
- database:
id: &database0 database0
client: *client0
databaseName: &database0Name crud-tests
- collection:
id: &collection0 collection0
database: *database0
collectionName: &collection0Name coll0

initialData:
- collectionName: *collection0Name
databaseName: *database0Name
documents:
- { _id: 1 }
- { _id: 2 }

tests:
- description: "BulkWrite deleteMany with let option"
runOnRequirements:
- minServerVersion: "5.0"
operations:
- object: *collection0
name: bulkWrite
arguments:
requests:
- deleteMany:
filter: &filter
$expr:
$eq: [ "$_id", "$$id" ]
let: &let
id: 1
expectEvents:
- client: *client0
events:
- commandStartedEvent:
command:
delete: *collection0Name
deletes:
- q: *filter
limit: 0
let: *let
outcome:
- collectionName: *collection0Name
databaseName: *database0Name
documents:
- { _id: 2 }

- description: "BulkWrite deleteMany with let option unsupported (server-side error)"
runOnRequirements:
- minServerVersion: "3.6.0"
maxServerVersion: "4.4.99"
operations:
- object: *collection0
name: bulkWrite
arguments:
requests:
- deleteOne:
filter: *filter
let: *let
expectError:
errorContains: "'delete.let' is an unknown field"
isClientError: false
expectEvents:
- client: *client0
events:
- commandStartedEvent:
command:
delete: *collection0Name
deletes:
- q: *filter
limit: 1
let: *let
outcome:
- collectionName: *collection0Name
databaseName: *database0Name
documents:
- { _id: 1 }
- { _id: 2 }
Loading