1 /** 2 MongoDB CRUD API definitions. 3 4 Copyright: © 2022 Jan Jurzitza 5 License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. 6 Authors: Jan Jurzitza 7 */ 8 module vibe.db.mongo.impl.crud; 9 10 import core.time; 11 12 import vibe.db.mongo.collection; 13 import vibe.data.bson; 14 15 import std.typecons; 16 17 @safe: 18 19 deprecated("Use UpdateOptions instead") 20 enum UpdateFlags { 21 none = 0, /// Normal update of a single document. 22 upsert = 1<<0, /// Creates a document if none exists. 23 multiUpdate = 1<<1, /// Updates all matching documents. 24 25 None = none, /// Deprecated compatibility alias 26 Upsert = upsert, /// Deprecated compatibility alias 27 MultiUpdate = multiUpdate /// Deprecated compatibility alias 28 } 29 30 deprecated("Use InsertOneOptions or InsertManyOptions instead") 31 enum InsertFlags { 32 none = 0, /// Normal insert. 33 continueOnError = 1<<0, /// For multiple inserted documents, continues inserting further documents after a failure. 34 35 None = none, /// Deprecated compatibility alias 36 ContinueOnError = continueOnError /// Deprecated compatibility alias 37 } 38 39 deprecated("Use FindOptions instead") 40 enum QueryFlags { 41 none = 0, /// Normal query 42 tailableCursor = 1<<1, /// 43 slaveOk = 1<<2, /// 44 oplogReplay = 1<<3, /// 45 noCursorTimeout = 1<<4, /// 46 awaitData = 1<<5, /// 47 exhaust = 1<<6, /// 48 partial = 1<<7, /// 49 50 None = none, /// Deprecated compatibility alias 51 TailableCursor = tailableCursor, /// Deprecated compatibility alias 52 SlaveOk = slaveOk, /// Deprecated compatibility alias 53 OplogReplay = oplogReplay, /// Deprecated compatibility alias 54 NoCursorTimeout = noCursorTimeout, /// Deprecated compatibility alias 55 AwaitData = awaitData, /// Deprecated compatibility alias 56 Exhaust = exhaust, /// Deprecated compatibility alias 57 Partial = partial /// Deprecated compatibility alias 58 } 59 60 deprecated("Use DeleteOptions instead") 61 enum DeleteFlags { 62 none = 0, 63 singleRemove = 1<<0, 64 65 None = none, /// Deprecated compatibility alias 66 SingleRemove = singleRemove /// Deprecated compatibility alias 67 } 68 69 /** 70 See_Also: $(LINK https://docs.mongodb.com/manual/reference/command/find/) 71 72 Standards: $(LINK https://github.com/mongodb/specifications/blob/525dae0aa8791e782ad9dd93e507b60c55a737bb/source/crud/crud.rst#id16) 73 */ 74 struct FindOptions 75 { 76 /** 77 Enables writing to temporary files on the server. When set to true, the server 78 can write temporary data to disk while executing the find operation. 79 80 This option is only supported by servers >= 4.4. 81 */ 82 @embedNullable @errorBefore(WireVersion.v44) 83 Nullable!bool allowDiskUse; 84 85 /** 86 Get partial results from a mongos if some shards are down (instead of throwing an error). 87 */ 88 @embedNullable 89 Nullable!bool allowPartialResults; 90 91 /** 92 The number of documents to return per batch. 93 */ 94 @embedNullable 95 Nullable!int batchSize; 96 97 /** 98 Determines whether to close the cursor after the first batch. 99 100 Set automatically if limit < 0 || batchSize < 0. 101 */ 102 @embedNullable 103 package Nullable!bool singleBatch; 104 105 /** 106 Collation allows users to specify language-specific rules for string 107 comparison, such as rules for letter-case and accent marks. 108 */ 109 @embedNullable @errorBefore(WireVersion.v34) 110 Nullable!Collation collation; 111 112 /** 113 Users can specify an arbitrary string to help trace the operation 114 through the database profiler, currentOp, and logs. 115 */ 116 @embedNullable 117 Nullable!string comment; 118 119 /** 120 Indicates the type of cursor to use. This value includes both 121 the tailable and awaitData options. 122 */ 123 @ignore CursorType cursorType; 124 125 /** 126 The index to use. Specify either the index name as a string or the index 127 key pattern. 128 129 If specified, then the query system will only consider plans using the 130 hinted index. 131 */ 132 @embedNullable 133 Nullable!Bson hint; 134 135 /** 136 The maximum number of documents to return. 137 138 A negative limit only returns a single batch of results. 139 */ 140 @embedNullable 141 Nullable!long limit; 142 143 /** 144 The exclusive upper bound for a specific index. 145 */ 146 @embedNullable 147 Nullable!Bson max; 148 149 /** 150 The maximum amount of time for the server to wait on new documents to 151 satisfy a tailable cursor query. This only applies to a TAILABLE_AWAIT 152 cursor. When the cursor is not a TAILABLE_AWAIT cursor, this option is 153 ignored. 154 155 Note: This option is specified as "maxTimeMS" in the getMore command and 156 not provided as part of the initial find command. 157 */ 158 @embedNullable @since(WireVersion.v32) 159 Nullable!long maxAwaitTimeMS; 160 161 /// ditto 162 void maxAwaitTime(Duration d) 163 @safe { 164 maxAwaitTimeMS = cast(long)d.total!"msecs"; 165 } 166 167 /** 168 Maximum number of documents or index keys to scan when executing the query. 169 */ 170 @embedNullable @deprecatedSince(WireVersion.v40) 171 Nullable!long maxScan; 172 173 /** 174 The maximum amount of time to allow the query to run. 175 */ 176 @embedNullable 177 Nullable!long maxTimeMS; 178 179 /// ditto 180 void maxTime(Duration d) 181 @safe { 182 maxTimeMS = cast(long)d.total!"msecs"; 183 } 184 185 /** 186 The exclusive lower bound for a specific index. 187 */ 188 @embedNullable 189 Nullable!Bson min; 190 191 /** 192 The server normally times out idle cursors after an inactivity period 193 (10 minutes) to prevent excess memory use. Set this option to prevent 194 that. 195 */ 196 @embedNullable 197 Nullable!bool noCursorTimeout; 198 199 /** 200 Enables optimization when querying the oplog for a range of ts values. 201 202 Note: this option is intended for internal replication use only. 203 */ 204 @embedNullable @deprecatedSince(WireVersion.v44) 205 Nullable!bool oplogReplay; 206 207 /** 208 Limits the fields to return for all matching documents. 209 */ 210 @embedNullable 211 Nullable!Bson projection; 212 213 /** 214 If true, returns only the index keys in the resulting documents. 215 */ 216 @embedNullable 217 Nullable!bool returnKey; 218 219 /** 220 Determines whether to return the record identifier for each document. If 221 true, adds a field $recordId to the returned documents. 222 */ 223 @embedNullable 224 Nullable!bool showRecordId; 225 226 /** 227 The number of documents to skip before returning. 228 */ 229 @embedNullable 230 Nullable!long skip; 231 232 /** 233 Prevents the cursor from returning a document more than once because of 234 an intervening write operation. 235 */ 236 @embedNullable @deprecatedSince(WireVersion.v40) 237 Nullable!bool snapshot; 238 239 /** 240 The order in which to return matching documents. 241 */ 242 @embedNullable 243 Nullable!Bson sort; 244 245 /** 246 If true, when an insert fails, return without performing the remaining 247 writes. If false, when a write fails, continue with the remaining writes, 248 if any. 249 250 Defaults to true. 251 */ 252 @embedNullable 253 Nullable!bool ordered; 254 255 /** 256 Specifies the read concern. Only compatible with a write stage. (e.g. 257 `$out`, `$merge`) 258 259 Aggregate commands do not support the $(D ReadConcern.Level.linearizable) 260 level. 261 262 Standards: $(LINK https://github.com/mongodb/specifications/blob/7745234f93039a83ae42589a6c0cdbefcffa32fa/source/read-write-concern/read-write-concern.rst) 263 */ 264 @embedNullable Nullable!ReadConcern readConcern; 265 } 266 267 /// 268 enum CursorType 269 { 270 /** 271 The default value. A vast majority of cursors will be of this type. 272 */ 273 nonTailable, 274 /** 275 Tailable means the cursor is not closed when the last data is retrieved. 276 Rather, the cursor marks the final object’s position. You can resume 277 using the cursor later, from where it was located, if more data were 278 received. Like any “latent cursor”, the cursor may become invalid at 279 some point (CursorNotFound) – for example if the final object it 280 references were deleted. 281 */ 282 tailable, 283 /** 284 Combines the tailable option with awaitData, as defined below. 285 286 Use with TailableCursor. If we are at the end of the data, block for a 287 while rather than returning no data. After a timeout period, we do 288 return as normal. The default is true. 289 */ 290 tailableAwait, 291 } 292 293 /** 294 See_Also: $(LINK https://www.mongodb.com/docs/manual/reference/command/distinct/) 295 296 Standards: $(LINK https://github.com/mongodb/specifications/blob/525dae0aa8791e782ad9dd93e507b60c55a737bb/source/crud/crud.rst#id16) 297 */ 298 struct DistinctOptions 299 { 300 /** 301 Collation allows users to specify language-specific rules for string 302 comparison, such as rules for letter-case and accent marks. 303 */ 304 @embedNullable @errorBefore(WireVersion.v34) 305 Nullable!Collation collation; 306 307 /** 308 The maximum amount of time to allow the query to run. 309 */ 310 @embedNullable 311 Nullable!long maxTimeMS; 312 313 /// ditto 314 void maxTime(Duration d) 315 @safe { 316 maxTimeMS = cast(long)d.total!"msecs"; 317 } 318 319 /** 320 Specifies the read concern. Only compatible with a write stage. (e.g. 321 `$out`, `$merge`) 322 323 Aggregate commands do not support the $(D ReadConcern.Level.linearizable) 324 level. 325 326 Standards: $(LINK https://github.com/mongodb/specifications/blob/7745234f93039a83ae42589a6c0cdbefcffa32fa/source/read-write-concern/read-write-concern.rst) 327 */ 328 @embedNullable Nullable!ReadConcern readConcern; 329 330 /** 331 Users can specify an arbitrary string to help trace the operation 332 through the database profiler, currentOp, and logs. 333 */ 334 @embedNullable 335 Nullable!string comment; 336 } 337 338 /** 339 See_Also: $(LINK https://www.mongodb.com/docs/manual/reference/command/count/) 340 and $(LINK https://www.mongodb.com/docs/manual/reference/method/db.collection.countDocuments/) 341 342 Standards: $(LINK https://github.com/mongodb/specifications/blob/525dae0aa8791e782ad9dd93e507b60c55a737bb/source/crud/crud.rst#id16) 343 */ 344 struct CountOptions 345 { 346 /** 347 Collation allows users to specify language-specific rules for string 348 comparison, such as rules for letter-case and accent marks. 349 */ 350 @embedNullable @errorBefore(WireVersion.v34) 351 Nullable!Collation collation; 352 353 /** 354 The index to use. Specify either the index name as a string or the index 355 key pattern. 356 357 If specified, then the query system will only consider plans using the 358 hinted index. 359 */ 360 @embedNullable 361 Nullable!Bson hint; 362 363 /** 364 The maximum number of documents to return. 365 366 A negative limit only returns a single batch of results. 367 */ 368 @embedNullable 369 Nullable!long limit; 370 371 /** 372 The maximum amount of time to allow the query to run. 373 */ 374 @embedNullable 375 Nullable!long maxTimeMS; 376 377 /// ditto 378 void maxTime(Duration d) 379 @safe { 380 maxTimeMS = cast(long)d.total!"msecs"; 381 } 382 383 /** 384 The number of documents to skip before returning. 385 */ 386 @embedNullable 387 Nullable!long skip; 388 389 /** 390 Specifies the read concern. Only compatible with a write stage. (e.g. 391 `$out`, `$merge`) 392 393 Aggregate commands do not support the $(D ReadConcern.Level.linearizable) 394 level. 395 396 Standards: $(LINK https://github.com/mongodb/specifications/blob/7745234f93039a83ae42589a6c0cdbefcffa32fa/source/read-write-concern/read-write-concern.rst) 397 */ 398 @embedNullable Nullable!ReadConcern readConcern; 399 } 400 401 /** 402 See_Also: $(LINK https://www.mongodb.com/docs/manual/reference/method/db.collection.estimatedDocumentCount/) 403 404 Standards: $(LINK https://github.com/mongodb/specifications/blob/525dae0aa8791e782ad9dd93e507b60c55a737bb/source/crud/crud.rst#id16) 405 */ 406 struct EstimatedDocumentCountOptions 407 { 408 /** 409 The maximum amount of time to allow the query to run. 410 */ 411 @embedNullable 412 Nullable!long maxTimeMS; 413 414 /// ditto 415 void maxTime(Duration d) 416 @safe { 417 maxTimeMS = cast(long)d.total!"msecs"; 418 } 419 } 420 421 /** 422 Represents available options for an aggregate call 423 424 See_Also: $(LINK https://www.mongodb.com/docs/manual/reference/command/aggregate/#dbcmd.aggregate) 425 426 Standards: $(LINK https://github.com/mongodb/specifications/blob/525dae0aa8791e782ad9dd93e507b60c55a737bb/source/crud/crud.rst#id16) 427 */ 428 struct AggregateOptions 429 { 430 // undocumented because this field isn't a spec field because it is 431 // out-of-scope for a driver 432 @embedNullable Nullable!bool explain; 433 434 /** 435 Enables writing to temporary files. When set to true, aggregation 436 operations can write data to the _tmp subdirectory in the dbPath 437 directory. 438 */ 439 @embedNullable 440 Nullable!bool allowDiskUse; 441 442 // non-optional since 3.6 443 // get/set by `batchSize`, undocumented in favor of that field 444 CursorInitArguments cursor; 445 446 /// Specifies the initial batch size for the cursor. 447 ref inout(Nullable!int) batchSize() 448 return @property inout @safe pure nothrow @nogc @ignore { 449 return cursor.batchSize; 450 } 451 452 /** 453 If true, allows the write to opt-out of document level validation. 454 This only applies when the $out or $merge stage is specified. 455 */ 456 @embedNullable @since(WireVersion.v32) 457 Nullable!bool bypassDocumentValidation; 458 459 /** 460 Collation allows users to specify language-specific rules for string 461 comparison, such as rules for letter-case and accent marks. 462 */ 463 @embedNullable @errorBefore(WireVersion.v34) 464 Nullable!Collation collation; 465 466 /** 467 Users can specify an arbitrary string to help trace the operation 468 through the database profiler, currentOp, and logs. 469 */ 470 @embedNullable 471 Nullable!string comment; 472 473 /** 474 The maximum amount of time for the server to wait on new documents to 475 satisfy a tailable cursor query. This only applies to a TAILABLE_AWAIT 476 cursor. When the cursor is not a TAILABLE_AWAIT cursor, this option is 477 ignored. 478 479 Note: This option is specified as "maxTimeMS" in the getMore command and 480 not provided as part of the initial find command. 481 */ 482 @embedNullable @since(WireVersion.v32) 483 Nullable!long maxAwaitTimeMS; 484 485 /// ditto 486 void maxAwaitTime(Duration d) 487 @safe { 488 maxAwaitTimeMS = cast(long)d.total!"msecs"; 489 } 490 491 /** 492 Specifies a time limit in milliseconds for processing operations on a 493 cursor. If you do not specify a value for maxTimeMS, operations will not 494 time out. 495 */ 496 @embedNullable 497 Nullable!long maxTimeMS; 498 499 /// ditto 500 void maxTime(Duration d) 501 @safe { 502 maxTimeMS = cast(long)d.total!"msecs"; 503 } 504 505 /** 506 The index to use for the aggregation. The index is on the initial 507 collection / view against which the aggregation is run. 508 509 The hint does not apply to $lookup and $graphLookup stages. 510 511 Specify the index either by the index name as a string or the index key 512 pattern. If specified, then the query system will only consider plans 513 using the hinted index. 514 */ 515 @embedNullable 516 Nullable!Bson hint; 517 518 /** 519 Map of parameter names and values. Values must be constant or closed 520 expressions that do not reference document fields. Parameters can then 521 be accessed as variables in an aggregate expression context 522 (e.g. `"$$var"`). 523 524 This option is only supported by servers >= 5.0. Older servers >= 2.6 (and possibly earlier) will report an error for using this option. 525 */ 526 @embedNullable 527 Nullable!Bson let; 528 529 /** 530 Specifies the read concern. Only compatible with a write stage. (e.g. 531 `$out`, `$merge`) 532 533 Aggregate commands do not support the $(D ReadConcern.Level.linearizable) 534 level. 535 536 Standards: $(LINK https://github.com/mongodb/specifications/blob/7745234f93039a83ae42589a6c0cdbefcffa32fa/source/read-write-concern/read-write-concern.rst) 537 */ 538 @embedNullable Nullable!ReadConcern readConcern; 539 } 540 541 /** 542 Standards: $(LINK https://github.com/mongodb/specifications/blob/525dae0aa8791e782ad9dd93e507b60c55a737bb/source/crud/crud.rst#insert-update-replace-delete-and-bulk-writes) 543 */ 544 struct BulkWriteOptions { 545 546 /** 547 If true, when a write fails, return without performing the remaining 548 writes. If false, when a write fails, continue with the remaining writes, 549 if any. 550 551 Defaults to true. 552 */ 553 @embedNullable 554 Nullable!bool ordered; 555 556 /** 557 If true, allows the write to opt-out of document level validation. 558 559 For servers < 3.2, this option is ignored and not sent as document 560 validation is not available. 561 562 For unacknowledged writes using OP_INSERT, OP_UPDATE, or OP_DELETE, the 563 driver MUST raise an error if the caller explicitly provides a value. 564 */ 565 @embedNullable 566 Nullable!bool bypassDocumentValidation; 567 568 /** 569 A document that expresses the 570 $(LINK2 https://www.mongodb.com/docs/manual/reference/write-concern/,write concern) 571 of the insert command. Omit to use the default write concern. 572 */ 573 @embedNullable 574 Nullable!WriteConcern writeConcern; 575 576 /** 577 Users can specify an arbitrary string to help trace the operation 578 through the database profiler, currentOp, and logs. 579 */ 580 @embedNullable 581 Nullable!string comment; 582 } 583 584 /** 585 See_Also: $(LINK https://docs.mongodb.com/manual/reference/command/insert/) 586 587 Standards: $(LINK https://github.com/mongodb/specifications/blob/525dae0aa8791e782ad9dd93e507b60c55a737bb/source/crud/crud.rst#insert-update-replace-delete-and-bulk-writes) 588 */ 589 struct InsertOneOptions { 590 /** 591 If true, allows the write to opt-out of document level validation. 592 593 For servers < 3.2, this option is ignored and not sent as document 594 validation is not available. 595 */ 596 @embedNullable 597 Nullable!bool bypassDocumentValidation; 598 599 /** 600 A document that expresses the 601 $(LINK2 https://www.mongodb.com/docs/manual/reference/write-concern/,write concern) 602 of the insert command. Omit to use the default write concern. 603 */ 604 @embedNullable 605 Nullable!WriteConcern writeConcern; 606 607 /** 608 Users can specify an arbitrary string to help trace the operation 609 through the database profiler, currentOp, and logs. 610 */ 611 @embedNullable 612 Nullable!string comment; 613 } 614 615 /** 616 See_Also: $(LINK https://docs.mongodb.com/manual/reference/command/insert/) 617 618 Standards: $(LINK https://github.com/mongodb/specifications/blob/525dae0aa8791e782ad9dd93e507b60c55a737bb/source/crud/crud.rst#insert-update-replace-delete-and-bulk-writes) 619 */ 620 struct InsertManyOptions { 621 /** 622 If true, allows the write to opt-out of document level validation. 623 624 For servers < 3.2, this option is ignored and not sent as document 625 validation is not available. 626 */ 627 @embedNullable 628 Nullable!bool bypassDocumentValidation; 629 630 /** 631 If true, when an insert fails, return without performing the remaining 632 writes. If false, when a write fails, continue with the remaining writes, 633 if any. 634 635 Defaults to true. 636 */ 637 @embedNullable 638 Nullable!bool ordered; 639 640 /** 641 A document that expresses the 642 $(LINK2 https://www.mongodb.com/docs/manual/reference/write-concern/,write concern) 643 of the insert command. Omit to use the default write concern. 644 */ 645 @embedNullable 646 Nullable!WriteConcern writeConcern; 647 648 /** 649 Users can specify an arbitrary string to help trace the operation 650 through the database profiler, currentOp, and logs. 651 */ 652 @embedNullable 653 Nullable!string comment; 654 } 655 656 /** 657 See_Also: $(LINK https://docs.mongodb.com/manual/reference/command/update/) 658 659 Standards: $(LINK https://github.com/mongodb/specifications/blob/525dae0aa8791e782ad9dd93e507b60c55a737bb/source/crud/crud.rst#insert-update-replace-delete-and-bulk-writes) 660 */ 661 struct UpdateOptions { 662 /** 663 A set of filters specifying to which array elements an update should 664 apply. 665 */ 666 @embedNullable @errorBefore(WireVersion.v36) 667 Nullable!(Bson[]) arrayFilters; 668 669 /** 670 If true, allows the write to opt-out of document level validation. 671 672 For servers < 3.2, this option is ignored and not sent as document 673 validation is not available. 674 */ 675 @embedNullable @since(WireVersion.v32) 676 Nullable!bool bypassDocumentValidation; 677 678 /** 679 Collation allows users to specify language-specific rules for string 680 comparison, such as rules for letter-case and accent marks. 681 */ 682 @embedNullable @errorBefore(WireVersion.v34) 683 Nullable!Collation collation; 684 685 /** 686 The index to use. Specify either the index name as a string or the index 687 key pattern. 688 689 If specified, then the query system will only consider plans using the 690 hinted index. 691 */ 692 @embedNullable 693 Nullable!Bson hint; 694 695 /** 696 When true, creates a new document if no document matches the query. 697 */ 698 @embedNullable 699 Nullable!bool upsert; 700 701 /** 702 A document that expresses the 703 $(LINK2 https://www.mongodb.com/docs/manual/reference/write-concern/,write concern) 704 of the insert command. Omit to use the default write concern. 705 */ 706 @embedNullable 707 Nullable!WriteConcern writeConcern; 708 709 /** 710 Users can specify an arbitrary string to help trace the operation 711 through the database profiler, currentOp, and logs. 712 */ 713 @embedNullable 714 Nullable!string comment; 715 } 716 717 /** 718 See_Also: $(LINK https://docs.mongodb.com/manual/reference/command/update/) 719 720 Standards: $(LINK https://github.com/mongodb/specifications/blob/525dae0aa8791e782ad9dd93e507b60c55a737bb/source/crud/crud.rst#insert-update-replace-delete-and-bulk-writes) 721 */ 722 struct ReplaceOptions { 723 /** 724 If true, allows the write to opt-out of document level validation. 725 726 For servers < 3.2, this option is ignored and not sent as document 727 validation is not available. 728 */ 729 @embedNullable 730 Nullable!bool bypassDocumentValidation; 731 732 /** 733 Collation allows users to specify language-specific rules for string 734 comparison, such as rules for letter-case and accent marks. 735 */ 736 @embedNullable @errorBefore(WireVersion.v34) 737 Nullable!Collation collation; 738 739 /** 740 The index to use. Specify either the index name as a string or the index 741 key pattern. 742 743 If specified, then the query system will only consider plans using the 744 hinted index. 745 */ 746 @embedNullable 747 Nullable!Bson hint; 748 749 /** 750 When true, creates a new document if no document matches the query. 751 */ 752 @embedNullable 753 Nullable!bool upsert; 754 755 /** 756 A document that expresses the 757 $(LINK2 https://www.mongodb.com/docs/manual/reference/write-concern/,write concern) 758 of the insert command. Omit to use the default write concern. 759 */ 760 @embedNullable 761 Nullable!WriteConcern writeConcern; 762 763 /** 764 Users can specify an arbitrary string to help trace the operation 765 through the database profiler, currentOp, and logs. 766 */ 767 @embedNullable 768 Nullable!string comment; 769 } 770 771 /** 772 See_Also: $(LINK https://docs.mongodb.com/manual/reference/command/delete/) 773 774 Standards: $(LINK https://github.com/mongodb/specifications/blob/525dae0aa8791e782ad9dd93e507b60c55a737bb/source/crud/crud.rst#insert-update-replace-delete-and-bulk-writes) 775 */ 776 struct DeleteOptions { 777 /** 778 Collation allows users to specify language-specific rules for string 779 comparison, such as rules for letter-case and accent marks. 780 */ 781 @embedNullable @errorBefore(WireVersion.v34) 782 Nullable!Collation collation; 783 784 /** 785 The index to use. Specify either the index name as a string or the index 786 key pattern. 787 788 If specified, then the query system will only consider plans using the 789 hinted index. 790 */ 791 @embedNullable 792 Nullable!Bson hint; 793 794 /** 795 A document that expresses the 796 $(LINK2 https://www.mongodb.com/docs/manual/reference/write-concern/,write concern) 797 of the insert command. Omit to use the default write concern. 798 */ 799 @embedNullable 800 Nullable!WriteConcern writeConcern; 801 802 /** 803 Users can specify an arbitrary string to help trace the operation 804 through the database profiler, currentOp, and logs. 805 */ 806 @embedNullable 807 Nullable!string comment; 808 809 /** 810 Map of parameter names and values. Values must be constant or closed 811 expressions that do not reference document fields. Parameters can then 812 be accessed as variables in an aggregate expression context 813 (e.g. `"$$var"`). 814 815 This option is only supported by servers >= 5.0. Older servers >= 2.6 (and possibly earlier) will report an error for using this option. 816 */ 817 @embedNullable 818 Nullable!Bson let; 819 } 820 821 struct BulkWriteResult { 822 /** 823 Number of documents inserted. 824 */ 825 long insertedCount; 826 827 /** 828 The identifiers that were automatically generated, if not set. 829 */ 830 BsonObjectID[size_t] insertedIds; 831 832 /** 833 Number of documents matched for update. 834 */ 835 long matchedCount; 836 837 /** 838 Number of documents modified. 839 */ 840 long modifiedCount; 841 842 /** 843 Number of documents deleted. 844 */ 845 long deletedCount; 846 847 /** 848 Number of documents upserted. 849 */ 850 long upsertedCount; 851 852 /** 853 Map of the index of the operation to the id of the upserted document. 854 */ 855 BsonObjectID[size_t] upsertedIds; 856 } 857 858 struct InsertOneResult { 859 /** 860 The identifier that was automatically generated, if not set. 861 */ 862 BsonObjectID insertedId; 863 } 864 865 struct InsertManyResult { 866 /** 867 The identifiers that were automatically generated, if not set. 868 */ 869 BsonObjectID[size_t] insertedIds; 870 } 871 872 struct DeleteResult { 873 /** 874 The number of documents that were deleted. 875 */ 876 long deletedCount; 877 } 878 879 struct UpdateResult { 880 /** 881 The number of documents that matched the filter. 882 */ 883 long matchedCount; 884 885 /** 886 The number of documents that were modified. 887 */ 888 long modifiedCount; 889 890 /** 891 The identifier of the inserted document if an upsert took place. Can be 892 none if no upserts took place, can be multiple if using the updateImpl 893 helper. 894 */ 895 BsonObjectID[] upsertedIds; 896 }