MCPcopy
hub / github.com/mongodb/node-mongodb-native / test

Function test

test/integration/crud/aggregation.test.ts:822–872  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

820 it('should not send a batchSize for aggregations with an out stage', {
821 metadata: { requires: { topology: ['single', 'replicaset'] } },
822 async test() {
823 const databaseName = this.configuration.db;
824 const client = this.configuration.newClient(this.configuration.writeConcernMax(), {
825 maxPoolSize: 1,
826 monitorCommands: true
827 });
828
829 const events = [];
830 client.on('commandStarted', filterForCommands(['aggregate'], events));
831 const coll1 = client.db(databaseName).collection('coll1');
832 const coll2 = client.db(databaseName).collection('coll2');
833
834 await client.connect();
835
836 await Promise.all([coll1.deleteMany({}), coll2.deleteMany({})])
837 .then(() => {
838 const docs = Array.from({ length: 10 }).map(() => ({ a: 1 }));
839 return Promise.all([
840 coll1.insertMany(docs),
841 client
842 .db(databaseName)
843 .createCollection('coll2')
844 .catch(() => null)
845 ]);
846 })
847 .then(() => {
848 return Promise.all(
849 [
850 coll1.aggregate([{ $out: 'coll2' }]),
851 coll1.aggregate([{ $out: 'coll2' }], { batchSize: 0 }),
852 coll1.aggregate([{ $out: 'coll2' }], { batchSize: 1 }),
853 coll1.aggregate([{ $out: 'coll2' }], { batchSize: 30 }),
854 coll1.aggregate([{ $match: { a: 1 } }, { $out: 'coll2' }]),
855 coll1.aggregate([{ $match: { a: 1 } }, { $out: 'coll2' }], { batchSize: 0 }),
856 coll1.aggregate([{ $match: { a: 1 } }, { $out: 'coll2' }], { batchSize: 1 }),
857 coll1.aggregate([{ $match: { a: 1 } }, { $out: 'coll2' }], { batchSize: 30 })
858 ].map(cursor => cursor.toArray())
859 );
860 })
861 .then(() => {
862 expect(events).to.be.an('array').with.a.lengthOf(8);
863 events.forEach(event => {
864 expect(event).to.have.property('commandName', 'aggregate');
865 expect(event)
866 .to.have.property('command')
867 .that.has.property('cursor')
868 .that.does.not.have.property('batchSize');
869 });
870 })
871 .finally(() => client.close());
872 }
873 });
874
875 it(

Callers

nothing calls this directly

Calls 15

filterForCommandsFunction · 0.90
writeConcernMaxMethod · 0.80
onMethod · 0.80
deleteManyMethod · 0.80
insertManyMethod · 0.80
toArrayMethod · 0.80
collectionMethod · 0.65
newClientMethod · 0.45
dbMethod · 0.45
connectMethod · 0.45
mapMethod · 0.45
createCollectionMethod · 0.45

Tested by

no test coverage detected