|
1 | 1 | 'use strict';
|
2 |
| -const { withClient, withClientV2, setupDatabase, ignoreNsNotFound } = require('./shared'); |
| 2 | +const { |
| 3 | + withClient, |
| 4 | + withClientV2, |
| 5 | + withMonitoredClient, |
| 6 | + setupDatabase, |
| 7 | + ignoreNsNotFound |
| 8 | +} = require('./shared'); |
3 | 9 | const test = require('./shared').assert;
|
4 | 10 | const { MongoError } = require('../../src/error');
|
5 | 11 | const { Long } = require('../../src');
|
@@ -1841,4 +1847,67 @@ describe('Bulk', function () {
|
1841 | 1847 | });
|
1842 | 1848 | })
|
1843 | 1849 | );
|
| 1850 | + |
| 1851 | + it('should apply collation via FindOperators', { |
| 1852 | + metadata: { requires: { mongodb: '>= 3.4' } }, |
| 1853 | + test: withMonitoredClient(['update', 'delete'], function (client, events, done) { |
| 1854 | + const locales = ['fr', 'de', 'es']; |
| 1855 | + const bulk = client.db().collection('coll').initializeOrderedBulkOp(); |
| 1856 | + |
| 1857 | + // updates |
| 1858 | + bulk |
| 1859 | + .find({ b: 1 }) |
| 1860 | + .collation({ locale: locales[0] }) |
| 1861 | + .updateOne({ $set: { b: 2 } }); |
| 1862 | + bulk |
| 1863 | + .find({ b: 2 }) |
| 1864 | + .collation({ locale: locales[1] }) |
| 1865 | + .update({ $set: { b: 3 } }); |
| 1866 | + bulk.find({ b: 3 }).collation({ locale: locales[2] }).replaceOne({ b: 2 }); |
| 1867 | + |
| 1868 | + // deletes |
| 1869 | + bulk.find({ b: 2 }).collation({ locale: locales[0] }).removeOne(); |
| 1870 | + bulk.find({ b: 1 }).collation({ locale: locales[1] }).remove(); |
| 1871 | + |
| 1872 | + bulk.execute(err => { |
| 1873 | + expect(err).to.not.exist; |
| 1874 | + expect(events).to.be.an('array').with.length.at.least(1); |
| 1875 | + expect(events[0]).property('commandName').to.equal('update'); |
| 1876 | + const updateCommand = events[0].command; |
| 1877 | + expect(updateCommand).property('updates').to.be.an('array').with.length(3); |
| 1878 | + updateCommand.updates.forEach((statement, idx) => { |
| 1879 | + expect(statement).property('collation').to.eql({ locale: locales[idx] }); |
| 1880 | + }); |
| 1881 | + expect(events[1]).property('commandName').to.equal('delete'); |
| 1882 | + const deleteCommand = events[1].command; |
| 1883 | + expect(deleteCommand).property('deletes').to.be.an('array').with.length(2); |
| 1884 | + deleteCommand.deletes.forEach((statement, idx) => { |
| 1885 | + expect(statement).property('collation').to.eql({ locale: locales[idx] }); |
| 1886 | + }); |
| 1887 | + client.close(done); |
| 1888 | + }); |
| 1889 | + }) |
| 1890 | + }); |
| 1891 | + |
| 1892 | + it('should throw an error if raw operations are passed to bulkWrite', function () { |
| 1893 | + const client = this.configuration.newClient(); |
| 1894 | + return client.connect().then(() => { |
| 1895 | + this.defer(() => client.close()); |
| 1896 | + |
| 1897 | + const coll = client.db().collection('single_bulk_write_error'); |
| 1898 | + return coll |
| 1899 | + .bulkWrite([ |
| 1900 | + { updateOne: { q: { a: 2 }, u: { $set: { a: 2 } }, upsert: true } }, |
| 1901 | + { deleteOne: { q: { c: 1 } } } |
| 1902 | + ]) |
| 1903 | + .then( |
| 1904 | + () => { |
| 1905 | + throw new Error('expected a bulk error'); |
| 1906 | + }, |
| 1907 | + err => { |
| 1908 | + expect(err).to.match(/Raw operations are not allowed/); |
| 1909 | + } |
| 1910 | + ); |
| 1911 | + }); |
| 1912 | + }); |
1844 | 1913 | });
|
0 commit comments