Skip to content

Commit b9e6dec

Browse files
authored
Merge pull request #42684 from MicrosoftDocs/repo_sync_working_branch
Confirm merge from repo_sync_working_branch to master to sync with https://github.com/Microsoft/azure-docs (branch master)
2 parents a95e2b9 + 90f6705 commit b9e6dec

File tree

3 files changed

+50
-43
lines changed

3 files changed

+50
-43
lines changed

articles/cognitive-services/video-indexer/video-indexer-use-apis.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ Once you subscribed to the Authorization API, you will be able to obtain access
5050

5151
Each call to the Operations API should be associated with an access token, matching the authorization scope of the call.
5252

53-
- User level - user level access tokens let you perform operations on the user level. For example, get associated accounts.
54-
- Account level – account level access tokens let you perform operations on the account level. for example, Upload video, list all videos, create a language model, etc.
55-
- Video level – video level access tokens let you perform operations on specific videos. for example, get video insights, download captions, get widgets, etc.
53+
- User level - user level access tokens let you perform operations on the **user** level. For example, get associated accounts.
54+
- Account level – account level access tokens let you perform operations on the **account** level or the **video** level. For example, Upload video, list all videos, get video insights, etc.
55+
- Video level – video level access tokens let you perform operations on a specific **video**. For example, get video insights, download captions, get widgets, etc.
56+
57+
You can control whether these tokens are readonly or they allow editing by specifying **allowEdit=true/false**.
58+
59+
For most server-to-server scenarios, you will probably use the same **account** token since it covers both **account** operations and **video** operations. However, if you are planning to make client side calls to Video Indexer (e.g. from javascript), you would want to use a **video** access token, to prevent clients from getting access to the entire account. That is also the reason that when embedding VideoIndexer client code in your client (e.g. using **Get Insights Widget** or **Get Player Widget**) you must provide a **video** access token.
5660

5761
To make things easier, you can use the **Authorization** API > **GetAccounts** to get your accounts without obtaining a user token first. You can also ask to get the accounts with valid tokens, enabling you to skip an additional call to get an account token.
5862

articles/cosmos-db/sql-api-nodejs-get-started.md

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ ms.author: sngun
1515

1616
---
1717
# Node.js tutorial: Use the SQL API in Azure Cosmos DB to create a Node.js console application
18+
1819
> [!div class="op_single_selector"]
1920
> * [.NET](sql-api-get-started.md)
2021
> * [.NET Core](sql-api-dotnetcore-get-started.md)
2122
> * [Node.js for MongoDB](mongodb-samples.md)
2223
> * [Node.js](sql-api-nodejs-get-started.md)
2324
> * [Java](sql-api-java-get-started.md)
2425
> * [C++](sql-api-cpp-get-started.md)
25-
>
26-
>
2726
2827
Welcome to the Node.js tutorial for the Azure Cosmos DB Node.js SDK! After following this tutorial, you'll have a console application that creates and queries Azure Cosmos DB resources.
2928

@@ -46,6 +45,7 @@ After you've completed the Node.js tutorial, please use the voting buttons at th
4645
Now let's get started!
4746

4847
## Prerequisites for the Node.js tutorial
48+
4949
Please make sure you have the following:
5050

5151
* An active Azure account. If you don't have one, you can sign up for a [Free Azure Trial](https://azure.microsoft.com/pricing/free-trial/).
@@ -55,11 +55,13 @@ Please make sure you have the following:
5555
* [Node.js](https://nodejs.org/) version v0.10.29 or higher.
5656

5757
## Step 1: Create an Azure Cosmos DB account
58+
5859
Let's create an Azure Cosmos DB account. If you already have an account you want to use, you can skip ahead to [Set up your Node.js application](#SetupNode). If you are using the Azure Cosmos DB Emulator, please follow the steps at [Azure Cosmos DB Emulator](local-emulator.md) to setup the emulator and skip ahead to [Set up your Node.js application](#SetupNode).
5960

6061
[!INCLUDE [cosmos-db-create-dbaccount](../../includes/cosmos-db-create-dbaccount.md)]
6162

6263
## <a id="SetupNode"></a>Step 2: Set up your Node.js application
64+
6365
1. Open your favorite terminal.
6466
2. Locate the folder or directory where you'd like to save your Node.js application.
6567
3. Create two empty JavaScript files with the following commands:
@@ -75,6 +77,7 @@ Let's create an Azure Cosmos DB account. If you already have an account you want
7577
Great! Now that you've finished setting up, let's start writing some code.
7678

7779
## <a id="Config"></a>Step 3: Set your app's configurations
80+
7881
Open ```config.js``` in your favorite text editor.
7982

8083
Then, copy and paste the code snippet below and set properties ```config.endpoint``` and ```config.primaryKey``` to your Azure Cosmos DB endpoint uri and primary key. Both these configurations can be found in the [Azure portal](https://portal.azure.com).
@@ -158,7 +161,6 @@ Copy and paste the ```database id```, ```collection id```, and ```JSON documents
158161
}
159162
};
160163

161-
162164
The database, collection, and document definitions will act as your Azure Cosmos DB ```database id```, ```collection id```, and documents' data.
163165

164166
Finally, export your ```config``` object, so that you can reference it within the ```app.js``` file.
@@ -172,50 +174,49 @@ Finally, export your ```config``` object, so that you can reference it within th
172174
module.exports = config;
173175

174176
## <a id="Connect"></a> Step 4: Connect to an Azure Cosmos DB account
177+
175178
Open your empty ```app.js``` file in the text editor. Copy and paste the code below to import the ```documentdb``` module and your newly created ```config``` module.
176179

177180
// ADD THIS PART TO YOUR CODE
178181
"use strict";
179182

180183
var documentClient = require("documentdb").DocumentClient;
184+
const uriFactory = require('documentdb').UriFactory;
181185
var config = require("./config");
182-
var url = require('url');
183186

184187
Copy and paste the code to use the previously saved ```config.endpoint``` and ```config.primaryKey``` to create a new DocumentClient.
185188

186189
var config = require("./config");
187-
var url = require('url');
188190

189191
// ADD THIS PART TO YOUR CODE
190192
var client = new documentClient(config.endpoint, { "masterKey": config.primaryKey });
191193

192194
Now that you have the code to initialize the Azure Cosmos DB client, let's take a look at working with Azure Cosmos DB resources.
193195

194196
## Step 5: Create a Node database
195-
Copy and paste the code below to set the HTTP status for Not Found, the database url, and the collection url. These urls are how the Azure Cosmos DB client will find the right database and collection.
197+
198+
Copy and paste the code below to set the HTTP status for Not Found, the database id, and the collection id. These ids are how the Azure Cosmos DB client will find the right database and collection.
196199

197200
var client = new documentClient(config.endpoint, { "masterKey": config.primaryKey });
198201

199202
// ADD THIS PART TO YOUR CODE
200203
var HttpStatusCodes = { NOTFOUND: 404 };
201-
var databaseUrl = `dbs/${config.database.id}`;
202-
var collectionUrl = `${databaseUrl}/colls/${config.collection.id}`;
204+
var databaseId = config.database.id;
205+
var collectionId = config.collection.id;
203206

204207
A [database](sql-api-resources.md#databases) can be created by using the [createDatabase](https://azure.github.io/azure-documentdb-node/DocumentClient.html) function of the **DocumentClient** class. A database is the logical container of document storage partitioned across collections.
205208

206-
Copy and paste the **getDatabase** function for creating your new database in the app.js file with the ```id``` specified in the ```config``` object. The function will check if the database with the same ```FamilyRegistry``` id does not already exist. If it does exist, we'll return that database instead of creating a new one.
207-
208-
var collectionUrl = `${databaseUrl}/colls/${config.collection.id}`;
209+
Copy and paste the **getDatabase** function for creating your new database in the app.js file with the ```databaseId``` specified from the ```config``` object. The function will check if the database with the same ```FamilyRegistry``` id does not already exist. If it does exist, we'll return that database instead of creating a new one.
209210

210211
// ADD THIS PART TO YOUR CODE
211212
function getDatabase() {
212-
console.log(`Getting database:\n${config.database.id}\n`);
213-
213+
console.log(`Getting database:\n${databaseId}\n`);
214+
let databaseUrl = uriFactory.createDatabaseUri(databaseId);
214215
return new Promise((resolve, reject) => {
215216
client.readDatabase(databaseUrl, (err, result) => {
216217
if (err) {
217218
if (err.code == HttpStatusCodes.NOTFOUND) {
218-
client.createDatabase(config.database, (err, created) => {
219+
client.createDatabase({ id: databaseId }, (err, created) => {
219220
if (err) reject(err)
220221
else resolve(created);
221222
});
@@ -227,7 +228,7 @@ Copy and paste the **getDatabase** function for creating your new database in th
227228
}
228229
});
229230
});
230-
}
231+
};
231232

232233
Copy and paste the code below where you set the **getDatabase** function to add the helper function **exit** that will print the exit message and the call to **getDatabase** function.
233234

@@ -245,7 +246,7 @@ Copy and paste the code below where you set the **getDatabase** function to add
245246
process.stdin.setRawMode(true);
246247
process.stdin.resume();
247248
process.stdin.on('data', process.exit.bind(process, 0));
248-
}
249+
};
249250

250251
getDatabase()
251252
.then(() => { exit(`Completed successfully`); })
@@ -256,31 +257,31 @@ In your terminal, locate your ```app.js``` file and run the command: ```node app
256257
Congratulations! You have successfully created an Azure Cosmos DB database.
257258

258259
## <a id="CreateColl"></a>Step 6: Create a collection
260+
259261
> [!WARNING]
260262
> **createCollection** will create a new collection, which has pricing implications. For more details, please visit our [pricing page](https://azure.microsoft.com/pricing/details/cosmos-db/).
261-
>
262-
>
263263
264264
A [collection](sql-api-resources.md#collections) can be created by using the [createCollection](https://azure.github.io/azure-documentdb-node/DocumentClient.html) function of the **DocumentClient** class. A collection is a container of JSON documents and associated JavaScript application logic.
265265

266-
Copy and paste the **getCollection** function underneath the **getDatabase** function in the app.js file to create your new collection with the ```id``` specified in the ```config``` object. Again, we'll check to make sure a collection with the same ```FamilyCollection``` id does not already exist. If it does exist, we'll return that collection instead of creating a new one.
266+
Copy and paste the **getCollection** function underneath the **getDatabase** function in the app.js file to create your new collection with the ```collectionId``` specified from the ```config``` object. Again, we'll check to make sure a collection with the same ```FamilyCollection``` id does not already exist. If it does exist, we'll return that collection instead of creating a new one.
267267

268268
} else {
269269
resolve(result);
270270
}
271271
});
272272
});
273-
}
273+
};
274274

275275
// ADD THIS PART TO YOUR CODE
276276
function getCollection() {
277-
console.log(`Getting collection:\n${config.collection.id}\n`);
278-
277+
console.log(`Getting collection:\n${collectionId}\n`);
278+
let collectionUrl = uriFactory.createDocumentCollectionUri(databaseId, collectionId);
279279
return new Promise((resolve, reject) => {
280280
client.readCollection(collectionUrl, (err, result) => {
281281
if (err) {
282282
if (err.code == HttpStatusCodes.NOTFOUND) {
283-
client.createCollection(databaseUrl, config.collection, { offerThroughput: 400 }, (err, created) => {
283+
let databaseUrl = uriFactory.createDatabaseUri(databaseId);
284+
client.createCollection(databaseUrl, { id: collectionId }, { offerThroughput: 400 }, (err, created) => {
284285
if (err) reject(err)
285286
else resolve(created);
286287
});
@@ -292,7 +293,7 @@ Copy and paste the **getCollection** function underneath the **getDatabase** fun
292293
}
293294
});
294295
});
295-
}
296+
};
296297

297298
Copy and paste the code below the call to **getDatabase** to execute the **getCollection** function.
298299

@@ -310,6 +311,7 @@ In your terminal, locate your ```app.js``` file and run the command: ```node app
310311
Congratulations! You have successfully created an Azure Cosmos DB collection.
311312

312313
## <a id="CreateDoc"></a>Step 7: Create a document
314+
313315
A [document](sql-api-resources.md#documents) can be created by using the [createDocument](https://azure.github.io/azure-documentdb-node/DocumentClient.html) function of the **DocumentClient** class. Documents are user defined (arbitrary) JSON content. You can now insert a document into Azure Cosmos DB.
314316

315317
Copy and paste the **getFamilyDocument** function underneath the **getCollection** function for creating the documents containing the JSON data saved in the ```config``` object. Again, we'll check to make sure a document with the same id does not already exist.
@@ -319,17 +321,17 @@ Copy and paste the **getFamilyDocument** function underneath the **getCollection
319321
}
320322
});
321323
});
322-
}
324+
};
323325

324326
// ADD THIS PART TO YOUR CODE
325327
function getFamilyDocument(document) {
326-
let documentUrl = `${collectionUrl}/docs/${document.id}`;
327328
console.log(`Getting document:\n${document.id}\n`);
328-
329+
let documentUrl = uriFactory.createDocumentUri(databaseId, collectionId, document.id);
329330
return new Promise((resolve, reject) => {
330331
client.readDocument(documentUrl, (err, result) => {
331332
if (err) {
332333
if (err.code == HttpStatusCodes.NOTFOUND) {
334+
let collectionUrl = uriFactory.createDocumentCollectionUri(databaseId, collectionId);
333335
client.createDocument(collectionUrl, document, (err, created) => {
334336
if (err) reject(err)
335337
else resolve(created);
@@ -373,12 +375,12 @@ Copy and paste the **queryCollection** function underneath the **getFamilyDocume
373375
}
374376
});
375377
});
376-
}
378+
};
377379

378380
// ADD THIS PART TO YOUR CODE
379381
function queryCollection() {
380-
console.log(`Querying collection through index:\n${config.collection.id}`);
381-
382+
console.log(`Querying collection through index:\n${collectionId}`);
383+
let collectionUrl = uriFactory.createDocumentCollectionUri(databaseId, collectionId);
382384
return new Promise((resolve, reject) => {
383385
client.queryDocuments(
384386
collectionUrl,
@@ -397,7 +399,6 @@ Copy and paste the **queryCollection** function underneath the **getFamilyDocume
397399
});
398400
};
399401

400-
401402
The following diagram illustrates how the Azure Cosmos DB SQL query syntax is called against the collection you created.
402403

403404
![Node.js tutorial - Diagram illustrating the scope and meaning of the query - Node database](./media/sql-api-nodejs-get-started/node-js-tutorial-collection-documents.png)
@@ -431,14 +432,13 @@ Copy and paste the **replaceFamilyDocument** function underneath the **queryColl
431432
}
432433
});
433434
});
434-
}
435+
};
435436

436437
// ADD THIS PART TO YOUR CODE
437438
function replaceFamilyDocument(document) {
438-
let documentUrl = `${collectionUrl}/docs/${document.id}`;
439439
console.log(`Replacing document:\n${document.id}\n`);
440+
let documentUrl = uriFactory.createDocumentUri(databaseId, collectionId, document.id);
440441
document.children[0].grade = 6;
441-
442442
return new Promise((resolve, reject) => {
443443
client.replaceDocument(documentUrl, document, (err, result) => {
444444
if (err) reject(err);
@@ -468,6 +468,7 @@ In your terminal, locate your ```app.js``` file and run the command: ```node app
468468
Congratulations! You have successfully replaced an Azure Cosmos DB document.
469469

470470
## <a id="DeleteDocument"></a>Step 10: Delete a document
471+
471472
Azure Cosmos DB supports deleting JSON documents.
472473

473474
Copy and paste the **deleteFamilyDocument** function underneath the **replaceFamilyDocument** function.
@@ -481,9 +482,8 @@ Copy and paste the **deleteFamilyDocument** function underneath the **replaceFam
481482

482483
// ADD THIS PART TO YOUR CODE
483484
function deleteFamilyDocument(document) {
484-
let documentUrl = `${collectionUrl}/docs/${document.id}`;
485485
console.log(`Deleting document:\n${document.id}\n`);
486-
486+
let documentUrl = uriFactory.createDocumentUri(databaseId, collectionId, document.id);
487487
return new Promise((resolve, reject) => {
488488
client.deleteDocument(documentUrl, (err, result) => {
489489
if (err) reject(err);
@@ -512,6 +512,7 @@ In your terminal, locate your ```app.js``` file and run the command: ```node app
512512
Congratulations! You have successfully deleted an Azure Cosmos DB document.
513513

514514
## <a id="DeleteDatabase"></a>Step 11: Delete the Node database
515+
515516
Deleting the created database will remove the database and all children resources (collections, documents, etc.).
516517

517518
Copy and paste the **cleanup** function underneath the **deleteFamilyDocument** function to remove the database and all the children resources.
@@ -525,15 +526,15 @@ Copy and paste the **cleanup** function underneath the **deleteFamilyDocument**
525526

526527
// ADD THIS PART TO YOUR CODE
527528
function cleanup() {
528-
console.log(`Cleaning up by deleting database ${config.database.id}`);
529-
529+
console.log(`Cleaning up by deleting database ${databaseId}`);
530+
let databaseUrl = uriFactory.createDatabaseUri(databaseId);
530531
return new Promise((resolve, reject) => {
531532
client.deleteDatabase(databaseUrl, (err) => {
532533
if (err) reject(err)
533534
else resolve(null);
534535
});
535536
});
536-
}
537+
};
537538

538539
Copy and paste the code below the call to **deleteFamilyDocument** to execute the **cleanup** function.
539540

@@ -547,6 +548,7 @@ Copy and paste the code below the call to **deleteFamilyDocument** to execute th
547548
.catch((error) => { exit(`Completed with error ${JSON.stringify(error)}`) });
548549

549550
## <a id="Run"></a>Step 12: Run your Node.js application all together!
551+
550552
Altogether, the sequence for calling your functions should look like this:
551553

552554
getDatabase()
@@ -598,6 +600,7 @@ You should see the output of your get started app. The output should match the e
598600
Congratulations! You've created you've completed the Node.js tutorial and have your first Azure Cosmos DB console application!
599601

600602
## <a id="GetSolution"></a>Get the complete Node.js tutorial solution
603+
601604
If you didn't have time to complete the steps in this tutorial, or just want to download the code, you can get it from [GitHub](https://github.com/Azure-Samples/documentdb-node-getting-started).
602605

603606
To run the GetStarted solution that contains all the samples in this article, you will need the following:

articles/event-hubs/event-hubs-availability-and-consistency.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ms.author: sethm
2323
## Overview
2424
Azure Event Hubs uses a [partitioning model](event-hubs-features.md#partitions) to improve availability and parallelization within a single event hub. For example, if an event hub has four partitions, and one of those partitions is moved from one server to another in a load balancing operation, you can still send and receive from three other partitions. Additionally, having more partitions enables you to have more concurrent readers processing your data, improving your aggregate throughput. Understanding the implications of partitioning and ordering in a distributed system is a critical aspect of solution design.
2525

26-
To help explain the trade-off between ordering and availability, see the [CAP theorem](https://en.wikipedia.org/wiki/CAP_theorem), also known as Brewer's theorem. This theorem discusses the choice between consistency, availability, and partition tolerance.
26+
To help explain the trade-off between ordering and availability, see the [CAP theorem](https://en.wikipedia.org/wiki/CAP_theorem), also known as Brewer's theorem. This theorem discusses the choice between consistency, availability, and partition tolerance. It states that for the systems partitioned by network there is always tradeoff between consistency and availability.
2727

2828
Brewer's theorem defines consistency and availability as follows:
2929
* Partition tolerance: the ability of a data processing system to continue processing data even if a partition failure occurs.

0 commit comments

Comments
 (0)