|
1 | 1 | 'use strict';
|
2 | 2 | const { withClient, withClientV2, setupDatabase, ignoreNsNotFound } = require('./shared');
|
3 | 3 | const test = require('./shared').assert;
|
4 |
| -const { expect } = require('chai'); |
5 | 4 | const { MongoError } = require('../../src/error');
|
6 | 5 | const { Long } = require('../../src');
|
| 6 | +const chai = require('chai'); |
| 7 | +const expect = chai.expect; |
| 8 | +chai.use(require('chai-subset')); |
7 | 9 |
|
8 | 10 | describe('Bulk', function () {
|
9 | 11 | before(function () {
|
@@ -1146,6 +1148,37 @@ describe('Bulk', function () {
|
1146 | 1148 | * Ordered
|
1147 | 1149 | *
|
1148 | 1150 | *******************************************************************/
|
| 1151 | + it('should provide an accessor for operations on ordered bulk ops', function (done) { |
| 1152 | + var self = this; |
| 1153 | + var client = self.configuration.newClient(self.configuration.writeConcernMax(), { |
| 1154 | + maxPoolSize: 1 |
| 1155 | + }); |
| 1156 | + |
| 1157 | + client.connect(function (err, client) { |
| 1158 | + var db = client.db(self.configuration.db); |
| 1159 | + var col = db.collection('bulk_get_operations_test'); |
| 1160 | + |
| 1161 | + var batch = col.initializeOrderedBulkOp(); |
| 1162 | + batch.insert({ b: 1, a: 1 }); |
| 1163 | + batch |
| 1164 | + .find({ b: 2 }) |
| 1165 | + .upsert() |
| 1166 | + .updateOne({ $set: { a: 1 } }); |
| 1167 | + batch.insert({ b: 3, a: 2 }); |
| 1168 | + const batches = batch.batches; |
| 1169 | + expect(batches).to.have.lengthOf(3); |
| 1170 | + expect(batches[0].operations[0]).to.containSubset({ b: 1, a: 1 }); |
| 1171 | + expect(batches[1].operations[0]).to.containSubset({ |
| 1172 | + q: { b: 2 }, |
| 1173 | + u: { $set: { a: 1 } }, |
| 1174 | + multi: false, |
| 1175 | + upsert: true |
| 1176 | + }); |
| 1177 | + expect(batches[2].operations[0]).to.containSubset({ b: 3, a: 2 }); |
| 1178 | + client.close(done); |
| 1179 | + }); |
| 1180 | + }); |
| 1181 | + |
1149 | 1182 | it('should fail with w:2 and wtimeout write concern due single mongod instance ordered', {
|
1150 | 1183 | metadata: { requires: { topology: 'single', mongodb: '>2.5.4' } },
|
1151 | 1184 |
|
@@ -1217,6 +1250,37 @@ describe('Bulk', function () {
|
1217 | 1250 | * Unordered
|
1218 | 1251 | *
|
1219 | 1252 | *******************************************************************/
|
| 1253 | + it('should provide an accessor for operations on unordered bulk ops', function (done) { |
| 1254 | + var self = this; |
| 1255 | + var client = self.configuration.newClient(self.configuration.writeConcernMax(), { |
| 1256 | + maxPoolSize: 1 |
| 1257 | + }); |
| 1258 | + |
| 1259 | + client.connect(function (err, client) { |
| 1260 | + var db = client.db(self.configuration.db); |
| 1261 | + var col = db.collection('bulk_get_operations_test'); |
| 1262 | + |
| 1263 | + var batch = col.initializeUnorderedBulkOp(); |
| 1264 | + batch.insert({ b: 1, a: 1 }); |
| 1265 | + batch |
| 1266 | + .find({ b: 2 }) |
| 1267 | + .upsert() |
| 1268 | + .updateOne({ $set: { a: 1 } }); |
| 1269 | + batch.insert({ b: 3, a: 2 }); |
| 1270 | + const batches = batch.batches; |
| 1271 | + expect(batches).to.have.lengthOf(2); |
| 1272 | + expect(batches[0].operations[0]).to.containSubset({ b: 1, a: 1 }); |
| 1273 | + expect(batches[0].operations[1]).to.containSubset({ b: 3, a: 2 }); |
| 1274 | + expect(batches[1].operations[0]).to.containSubset({ |
| 1275 | + q: { b: 2 }, |
| 1276 | + u: { $set: { a: 1 } }, |
| 1277 | + multi: false, |
| 1278 | + upsert: true |
| 1279 | + }); |
| 1280 | + client.close(done); |
| 1281 | + }); |
| 1282 | + }); |
| 1283 | + |
1220 | 1284 | it('should fail with w:2 and wtimeout write concern due single mongod instance unordered', {
|
1221 | 1285 | metadata: { requires: { topology: 'single', mongodb: '>2.5.4' } },
|
1222 | 1286 |
|
|
0 commit comments