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

Function test

test/integration/crud/bulk.test.ts:1616–1656  ·  test/integration/crud/bulk.test.ts::test
()

Source from the content-addressed store, hash-verified

1614 it(class="st">'should apply hint via FindOperators', {
1615 metadata: { requires: { mongodb: class="st">'>= 4.4' } },
1616 async test() {
1617 const bulk = client.db().collection(class="st">'coll').initializeOrderedBulkOp();
1618
1619 const events = [];
1620 client.on(class="st">'commandStarted', event => {
1621 if ([class="st">'update', class="st">'delete'].includes(event.commandName)) {
1622 events.push(event);
1623 }
1624 });
1625
1626 class="cm">// updates
1627 bulk
1628 .find({ b: 1 })
1629 .hint({ b: 1 })
1630 .updateOne({ $set: { b: 2 } });
1631 bulk
1632 .find({ b: 2 })
1633 .hint({ b: 1 })
1634 .update({ $set: { b: 3 } });
1635 bulk.find({ b: 3 }).hint({ b: 1 }).replaceOne({ b: 2 });
1636
1637 class="cm">// deletes
1638 bulk.find({ b: 2 }).hint({ b: 1 }).deleteOne();
1639 bulk.find({ b: 1 }).hint({ b: 1 }).delete();
1640
1641 await bulk.execute();
1642
1643 expect(events).to.be.an(class="st">'array').with.length.at.least(1);
1644 expect(events[0]).property(class="st">'commandName').to.equal(class="st">'update');
1645 const updateCommand = events[0].command;
1646 expect(updateCommand).property(class="st">'updates').to.be.an(class="st">'array').with.length(3);
1647 updateCommand.updates.forEach(statement => {
1648 expect(statement).property(class="st">'hint').to.eql({ b: 1 });
1649 });
1650 expect(events[1]).property(class="st">'commandName').to.equal(class="st">'delete');
1651 const deleteCommand = events[1].command;
1652 expect(deleteCommand).property(class="st">'deletes').to.be.an(class="st">'array').with.length(2);
1653 deleteCommand.deletes.forEach(statement => {
1654 expect(statement).property(class="st">'hint').to.eql({ b: 1 });
1655 });
1656 }
1657 });
1658
1659 it(class="st">'should apply arrayFilters to bulk updates via FindOperators', async function () {

Callers

nothing calls this directly

Calls 15

onMethod · 0.80
startSessionMethod · 0.80
startTransactionMethod · 0.80
abortTransactionMethod · 0.80
endSessionMethod · 0.80
toArrayMethod · 0.80
withTransactionMethod · 0.80
collectionMethod · 0.65
executeMethod · 0.65
dbMethod · 0.45

Tested by

no test coverage detected