Skip to content

DOCSP-32718: add CodeWhisperer comments to transactions code snippets #769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 5, 2023

Conversation

ccho-mongodb
Copy link
Contributor

@ccho-mongodb ccho-mongodb commented Aug 30, 2023

Pull Request Info

PR Reviewing Guidelines

JIRA - https://jira.mongodb.org/browse/DOCSP-32718
Staging - https://docs-mongodbcom-staging.corp.mongodb.com/node/docsworker-xlarge/DOCSP-32718-transactions/fundamentals/transactions/

Self-Review Checklist

  • Is this free of any warnings or errors in the RST?
  • Did you run a spell-check?
  • Did you run a grammar-check?
  • Are all the links working?

Copy link
Collaborator

@jordan-smith721 jordan-smith721 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after removing the period from shorter single-line comments

@@ -1,12 +1,12 @@
const { MongoError, MongoClient } = require('mongodb');

// drop collections
// Drop the "customers", "inventory", and "orders" collections from the "testdb" database.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Drop the "customers", "inventory", and "orders" collections from the "testdb" database.
// Drop the "customers", "inventory", and "orders" collections from the "testdb" database

console.log('Unable to insert test data: ' + e);
}
}

// Print all documents in the "customers", "inventory", and "orders" collections.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Print all documents in the "customers", "inventory", and "orders" collections.
// Print all documents in the "customers", "inventory", and "orders" collections

await session.endSession();
}
}
// end placeOrder


// Run the full transaction example.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Run the full transaction example.
// Run the full transaction example

} else {
console.log('An error occured in the transaction, performing a data rollback:' + error);
}
// End the transaction without making the updates performed in the session.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// End the transaction without making the updates performed in the session.
// End the transaction without making the updates performed in the session

await session.abortTransaction();
} finally {
// End the transaction making all the changes performed in the session.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// End the transaction making all the changes performed in the session.
// End the transaction making all the changes performed in the session

const payment = { customer: 98765, total: 37.17 };

try {
// Call the method that updates the customer and inventory in a transaction.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Call the method that updates the customer and inventory in a transaction.
// Call the method that updates the customer and inventory in a transaction

await placeOrder(client, cart, payment);
} finally {
// Call a method that removes data from prior runs of this example.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Call a method that removes data from prior runs of this example.
// Call a method that removes data from prior runs of this example

@@ -86,47 +101,68 @@ async function placeOrder(client, cart, payment) {
}

const customerCollection = client.db('testdb').collection('customers');

// Within the session, add the order details to the "orders" array of the customer document.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Within the session, add the order details to the "orders" array of the customer document.
// Within the session, add the order details to the "orders" array of the customer document

if (checkInventory === null) {
throw new Error('Insufficient quantity or SKU not found.');
}

// Decrement the inventory of the item by the amount specified in the order.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Decrement the inventory of the item by the amount specified in the order.
// Decrement the inventory of the item by the amount specified in the order

const checkInventory = await inventoryCollection.findOne(
{
sku: item.sku,
qty: { $gte: item.qty }
},
{ session }
)
// Throw an exception if the item lacks sufficient quantity or SKU does not exist.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Throw an exception if the item lacks sufficient quantity or SKU does not exist.
// Throw an exception if the item lacks sufficient quantity or SKU does not exist

@ccho-mongodb ccho-mongodb merged commit 4db5c08 into mongodb:master Sep 5, 2023
@ccho-mongodb ccho-mongodb deleted the DOCSP-32718-transactions branch September 5, 2023 21:52
ccho-mongodb pushed a commit that referenced this pull request Sep 8, 2023
…#769)

* DOCSP-32718: add CodeWhisperer comments to transactions code snippets

(cherry picked from commit 4db5c08)
mongoKart pushed a commit to mongoKart/docs-node that referenced this pull request Nov 3, 2023
…mongodb#769)

* DOCSP-32718: add CodeWhisperer comments to transactions code snippets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants