-
Notifications
You must be signed in to change notification settings - Fork 52
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
DOCSP-32718: add CodeWhisperer comments to transactions code snippets #769
Conversation
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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 |
…mongodb#769) * DOCSP-32718: add CodeWhisperer comments to transactions code snippets
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