* Create a new OrderedBulkOperation or UnorderedBulkOperation instance * @internal
(collection: Collection, options: BulkWriteOptions, isOrdered: boolean)
| 866 | * @internal |
| 867 | */ |
| 868 | constructor(collection: Collection, options: BulkWriteOptions, isOrdered: boolean) { |
| 869 | this.collection = collection; |
| 870 | this.retryWrites = collection.db.options?.retryWrites; |
| 871 | // determine whether bulkOperation is ordered or unordered |
| 872 | this.isOrdered = isOrdered; |
| 873 | |
| 874 | const topology = getTopology(collection); |
| 875 | options = options == null ? {} : options; |
| 876 | // TODO Bring from driver information in hello |
| 877 | // Get the namespace for the write operations |
| 878 | const namespace = collection.s.namespace; |
| 879 | // Used to mark operation as executed |
| 880 | const executed = false; |
| 881 | |
| 882 | // Current item |
| 883 | const currentOp = undefined; |
| 884 | |
| 885 | // Set max byte size |
| 886 | const hello = topology.lastHello(); |
| 887 | |
| 888 | // If we have autoEncryption on, batch-splitting must be done on 2mb chunks, but single documents |
| 889 | // over 2mb are still allowed |
| 890 | const usingAutoEncryption = !!(topology.s.options && topology.s.options.autoEncrypter); |
| 891 | const maxBsonObjectSize = |
| 892 | hello && hello.maxBsonObjectSize ? hello.maxBsonObjectSize : 1024 * 1024 * 16; |
| 893 | const maxBatchSizeBytes = usingAutoEncryption ? 1024 * 1024 * 2 : maxBsonObjectSize; |
| 894 | const maxWriteBatchSize = hello && hello.maxWriteBatchSize ? hello.maxWriteBatchSize : 1000; |
| 895 | |
| 896 | // Calculates the largest possible size of an Array key, represented as a BSON string |
| 897 | // element. This calculation: |
| 898 | // 1 byte for BSON type |
| 899 | // # of bytes = length of (string representation of (maxWriteBatchSize - 1)) |
| 900 | // + 1 bytes for null terminator |
| 901 | const maxKeySize = (maxWriteBatchSize - 1).toString(10).length + 2; |
| 902 | |
| 903 | // Final results |
| 904 | const bulkResult: BulkResult = { |
| 905 | ok: 1, |
| 906 | writeErrors: [], |
| 907 | writeConcernErrors: [], |
| 908 | insertedIds: [], |
| 909 | nInserted: 0, |
| 910 | nUpserted: 0, |
| 911 | nMatched: 0, |
| 912 | nModified: 0, |
| 913 | nRemoved: 0, |
| 914 | upserted: [] |
| 915 | }; |
| 916 | |
| 917 | // Internal state |
| 918 | this.s = { |
| 919 | // Final result |
| 920 | bulkResult, |
| 921 | // Current batch state |
| 922 | currentBatch: undefined, |
| 923 | currentIndex: 0, |
| 924 | // ordered specific |
| 925 | currentBatchSize: 0, |
nothing calls this directly
no test coverage detected