exam questions

Exam AZ-204 All Questions

View all questions & answers for the AZ-204 exam

Exam AZ-204 topic 3 question 19 discussion

Actual exam question from Microsoft's AZ-204
Question #: 19
Topic #: 3
[All AZ-204 Questions]

HOTSPOT -
You are developing an Azure-hosted e-commerce web application. The application will use Azure Cosmos DB to store sales orders. You are using the latest SDK to manage the sales orders in the database.
You create a new Azure Cosmos DB instance. You include a valid endpoint and valid authorization key to an appSettings.json file in the code project.
You are evaluating the following application code: (Line number are included for reference only.)

For each of the following statements, select Yes if the statement is true. Otherwise, select No.
NOTE: Each correct selection is worth one point.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:
Box 1: Yes -
The createDatabaseIfNotExistsAsync method checks if a database exists, and if it doesn't, create it.
The Database.CreateContainerAsync method creates a container as an asynchronous operation in the Azure Cosmos service.

Box 2: Yes -
The CosmosContainer.CreateItemAsync method creates an item as an asynchronous operation in the Azure Cosmos service.

Box 3: Yes -
Reference:
https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmos.cosmosclient.createdatabaseifnotexistsasync https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmos.database.createcontainerasync https://docs.microsoft.com/en-us/dotnet/api/azure.cosmos.cosmoscontainer.createitemasync

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
mlantonis
Highly Voted 3 years, 11 months ago
Box 1: Yes The createDatabaseIfNotExistsAsync method checks if a database exists, and if it doesn't, create it. (Line 22) The Database.CreateContainerAsync method creates a container as an asynchronous operation in the Azure Cosmos service. (Line 23 and 24) Box 2: Yes The CosmosContainer.CreateItemAsync method creates an item as an asynchronous operation in the Azure Cosmos service. (Line 26 and 28) Box 3: Yes The CosmosContainer.CreateItemAsync method creates an item as an asynchronous operation in the Azure Cosmos service. (Line 30)
upvoted 91 times
Esward
2 years, 3 months ago
Agreed
upvoted 1 times
...
chettir01
2 years, 4 months ago
The first box is not correct, the name of database is database and not salesOrder !
upvoted 1 times
chettir01
2 years, 4 months ago
SalesOrders is the databaseID, not the name !
upvoted 1 times
chettir01
2 years, 4 months ago
// New instance of Database class referencing the server-side database // The name of instance is database2, and we need an ID to create it ! Database database2 = await client.CreateDatabaseIfNotExistsAsync( id: "adventureworks-2" );
upvoted 1 times
...
...
Vladimir_Gajinov
1 year, 7 months ago
You are right but in Azure Cosmos DB, the database name is typically the same as the database ID, but spaces in the ID are replaced with hyphens ("-").
upvoted 1 times
...
Vladimir_Gajinov
1 year, 7 months ago
So, this answer is correct one.
upvoted 1 times
...
...
mlantonis
3 years, 11 months ago
Reference: https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmos.cosmosclient.createdatabaseifnotexistsasync https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmos.database.createcontainerasync https://docs.microsoft.com/en-us/dotnet/api/azure.cosmos.cosmoscontainer.createitemasync
upvoted 7 times
...
...
AOE
Highly Voted 3 years, 8 months ago
Line 21 is tricky, it assumes the database is already created as it calls DeleteStreamAsync. I'm confused.
upvoted 7 times
warchoon
2 years, 2 months ago
It returns ResponseMessage which is IDisposable
upvoted 1 times
...
Knightie
2 years, 8 months ago
// Delete a Database resource where database_id is the ID property of the Database resource you wish to delete. Database database = this.cosmosClient.GetDatabase(database_id); await database.DeleteStreamAsync(); That is deleted so the create if not exist will surely create the DB
upvoted 1 times
...
coffecold
2 years, 7 months ago
"using" is equal to a "try-finaly" with noting in finaly so the null exeption is already been taken care of . https://stackoverflow.com/questions/2522822/will-dispose-be-called-in-a-using-statement-with-a-null-object
upvoted 2 times
...
...
ReyPirata
Most Recent 1 year, 8 months ago
On my exam 2023-08-20. Scored 925 Yes Yes Yes
upvoted 4 times
...
ks321
1 year, 9 months ago
Box 1: Yes Box 2: Yes Box 3: No - container2.Create is called only once
upvoted 1 times
macobuzi
1 year, 8 months ago
I think you are confused! It said container2 has 1 item. So box3 - Yes is correct
upvoted 3 times
Christian_garcia_martin
9 months, 2 weeks ago
exactly
upvoted 2 times
...
...
...
Videira
2 years, 2 months ago
On my exam 2023-02-25
upvoted 1 times
...
Lucifer14
2 years, 4 months ago
In 28-12-2022 exam
upvoted 3 times
...
TheExamMaster2020
2 years, 5 months ago
Did my exam on 15th November 2022. This question was on it.
upvoted 2 times
...
sam5678
2 years, 7 months ago
yes yes yes
upvoted 1 times
chettir01
2 years, 4 months ago
No, it's not correct, The first box is not correct, the name of database on the code is database and not salesOrder !
upvoted 1 times
chettir01
2 years, 4 months ago
SalesOrders is the databaseID, not the name !
upvoted 1 times
...
...
...
Eltooth
2 years, 11 months ago
Answer is correct: Yes Yes Yes
upvoted 1 times
chettir01
2 years, 4 months ago
No, it's not correct, The first box is not correct, the name of database on the code is database and not salesOrders ! SalesOrders is the ID of the database not it's name !
upvoted 1 times
AymanAkk
2 years, 4 months ago
there is no name of database, that s a variable called database of type Databse and it will receive the newly created database with name salesOrder !
upvoted 4 times
...
...
...
nargzul
3 years, 10 months ago
I'm just curious, how do you know that Container 1 contains 2 items and container2 contains 1 item and not the opposite? I see that we are partitionning on the account number, but not sure to understand how the partition is made?
upvoted 2 times
BroGood
3 years, 10 months ago
see Lines 26 & 28 contain items for Container 1 Only Line 30 containers an item for Container 2
upvoted 5 times
...
ariel_dev
3 years, 10 months ago
container1 is called two times adding the items, container2 just one.
upvoted 6 times
...
Knightie
2 years, 8 months ago
container 1 will have 2 partitions, container 2 only 1 partition because partition key is the account number. But container 1 will still have 2 items, 1 item per partition. Hope this help.
upvoted 1 times
...
...
AlokSingh
3 years, 10 months ago
Correct Answer
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago