Skip to content

Commit 690f835

Browse files
authored
Fix typos in how-to-write-stored-procedures-triggers-udfs.md
1 parent 6717640 commit 690f835

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

articles/cosmos-db/nosql/how-to-write-stored-procedures-triggers-udfs.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ Once written, the stored procedure must be registered with a collection. To lear
5656

5757
### <a id="create-an-item"></a>Create items using stored procedures
5858

59-
When you create an item by using a stored procedure, the item is inserted into the Azure Cosmos DB container and an ID for the newly created item is returned. Creating an item is an asynchronous operation and depends on the JavaScript callback functions. The callback function has two parameters: one for the error object in case the operation fails, and another for a return value, in this case, the created object. Inside the callback, you can either handle the exception or throw an error. If a callback isn't provided and there's an error, the Azure Cosmos DB runtime throws an error.
59+
When you create an item using a stored procedure, the item is inserted into the Azure Cosmos DB container and an ID for the newly created item is returned. Creating an item is an asynchronous operation and depends on the JavaScript callback functions. The callback function has two parameters: one for the error object in case the operation fails, and another for a return value, in this case, the created object. Inside the callback, you can either handle the exception or throw an error. If a callback isn't provided and there's an error, the Azure Cosmos DB runtime throws an error.
6060

6161
The stored procedure also includes a parameter to set the description as a boolean value. When the parameter is set to true and the description is missing, the stored procedure throws an exception. Otherwise, the rest of the stored procedure continues to run.
6262

63-
The following example of a stored procedure takes an array of new Azure Cosmos DB items as input, inserts it into the Azure Cosmos DB container and returns the count of the items inserted. In this example, we're using the ToDoList sample from the [Quickstart .NET API for NoSQL](quickstart-dotnet.md).
63+
The following example of a stored procedure takes an array of new Azure Cosmos DB items as input, inserts it into the Azure Cosmos DB container, and returns the count of the items inserted. In this example, we're using the ToDoList sample from the [Quickstart .NET API for NoSQL](quickstart-dotnet.md).
6464

6565
```javascript
6666
function createToDoItems(items) {
@@ -101,7 +101,7 @@ function createToDoItems(items) {
101101

102102
### Arrays as input parameters for stored procedures
103103

104-
When you define a stored procedure in Azure portal, input parameters are always sent as a string to the stored procedure. Even if you pass an array of strings as an input, the array is converted to a string and sent to the stored procedure. To work around this, you can define a function within your stored procedure to parse the string as an array. The following code shows how to parse a string input parameter as an array:
104+
When you define a stored procedure in the Azure portal, input parameters are always sent as a string to the stored procedure. Even if you pass an array of strings as an input, the array is converted to a string and sent to the stored procedure. To work around this, you can define a function within your stored procedure to parse the string as an array. The following code shows how to parse a string input parameter as an array:
105105

106106
```javascript
107107
function sample(arr) {
@@ -119,13 +119,12 @@ function sample(arr) {
119119
You can implement transactions on items within a container by using a stored procedure. The following example uses transactions within a fantasy football gaming app to trade players between two teams in a single operation. The stored procedure attempts to read the two Azure Cosmos DB items, each corresponding to the player IDs passed in as an argument. If both players are found, then the stored procedure updates the items by swapping their teams. If any errors are encountered along the way, the stored procedure throws a JavaScript exception that implicitly aborts the transaction.
120120

121121
```javascript
122-
// JavaScript source code
123122
function tradePlayers(playerId1, playerId2) {
124123
var context = getContext();
125124
var container = context.getCollection();
126125
var response = context.getResponse();
127126

128-
var player1Document, player2Document;
127+
var player1Item, player2Item;
129128

130129
// query for players
131130
var filterQuery =
@@ -138,7 +137,7 @@ function tradePlayers(playerId1, playerId2) {
138137
function (err, items, responseOptions) {
139138
if (err) throw new Error("Error" + err.message);
140139

141-
if (items.length != 1) throw "Unable to find both names";
140+
if (items.length != 1) throw "Unable to find player 1";
142141
player1Item = items[0];
143142

144143
var filterQuery2 =
@@ -148,8 +147,8 @@ function tradePlayers(playerId1, playerId2) {
148147
};
149148
var accept2 = container.queryDocuments(container.getSelfLink(), filterQuery2, {},
150149
function (err2, items2, responseOptions2) {
151-
if (err2) throw new Error("Error" + err2.message);
152-
if (items2.length != 1) throw "Unable to find both names";
150+
if (err2) throw new Error("Error " + err2.message);
151+
if (items2.length != 1) throw "Unable to find player 2";
153152
player2Item = items2[0];
154153
swapTeams(player1Item, player2Item);
155154
return;
@@ -191,7 +190,7 @@ function bulkImport(items) {
191190
var container = getContext().getCollection();
192191
var containerLink = container.getSelfLink();
193192

194-
// The count of imported items, also used as current item index.
193+
// The count of imported items, also used as the current item index.
195194
var count = 0;
196195

197196
// Validate input.
@@ -213,9 +212,9 @@ function bulkImport(items) {
213212
function tryCreate(item, callback) {
214213
var isAccepted = container.createDocument(containerLink, item, callback);
215214

216-
// If the request was accepted, callback will be called.
217-
// Otherwise report current count back to the client,
218-
// which will call the script again with remaining set of items.
215+
// If the request was accepted, the callback will be called.
216+
// Otherwise report the current count back to the client,
217+
// which will call the script again with the remaining set of items.
219218
if (!isAccepted) getContext().getResponse().setBody(count);
220219
}
221220

@@ -230,7 +229,7 @@ function bulkImport(items) {
230229
// If we created all items, we are done. Just set the response.
231230
getContext().getResponse().setBody(count);
232231
} else {
233-
// Create next document.
232+
// Create the next document.
234233
tryCreate(items[count], callback);
235234
}
236235
}
@@ -397,13 +396,13 @@ For examples of how to register and use a UDF, see [How to work with user-define
397396

398397
## Logging
399398

400-
When using stored procedure, triggers, or UDFs, you can log the steps by enabling script logging. A string for debugging is generated when `EnableScriptLogging` is set to *true*, as shown in the following examples:
399+
When using stored procedures, triggers, or UDFs, you can log the steps by enabling script logging. A string for debugging is generated when `EnableScriptLogging` is set to *true*, as shown in the following examples:
401400

402401
# [JavaScript](#tab/javascript)
403402

404403
```javascript
405404
let requestOptions = { enableScriptLogging: true };
406-
const { resource: result, headers: responseHeaders} await container.scripts
405+
const { resource: result, headers: responseHeaders} = await container.scripts
407406
.storedProcedure(Sproc.id)
408407
.execute(undefined, [], requestOptions);
409408
console.log(responseHeaders[Constants.HttpHeaders.ScriptLogResults]);

0 commit comments

Comments
 (0)