Repository navigation
Set the MongoDB server version of the MongoDB sample, and start its web apps without the database - #152
Merged
Conversation
… CLI ignores deploy.sh of web-app-cosmosdb-mongodb-api (Python and .NET) creates the account with az cosmosdb create --server-version 7.0. Since azure-cli 2.90.0 the CLI sends that value as a ServerVersion property, which the service ignores, so the account runs MongoDB server version 3.6, and the MongoDB drivers of both web apps refuse it. On Azure, the Python app failed with "reports wire version 6, but this version of PyMongo requires at least 9 (MongoDB 4.4)" and answered HTTP 503. When the account reports a server version other than MONGODB_API_VERSION, the scripts now set serverVersion with az rest and wait until the account reports it, which takes about a minute. An account that already existed, such as one an earlier run left at 3.6, can hold data, and the MongoDB endpoint of such an account went on serving 3.6 for minutes after the account reported 7.0, so the web app deployed in the meantime failed to start. After upgrading such an account, the scripts wait with mongosh until the endpoint serves at least MongoDB 4.4, and only then deploy the web app. They check for mongosh before they change the account, and both READMEs list it for that case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FvNuJLfY2KkMwaymfFnz7R
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Both deployment scripts can skip endpoint readiness checks on rerun after an interrupted upgrade, allowing deployment against MongoDB 3.6 even when the account reports 7.0.
1 open issue
What changed in this PR
This PR works around Azure CLI’s ignored MongoDB server-version setting in the Python and .NET Cosmos DB samples, preventing driver incompatibility with the default MongoDB 3.6 version.
Changes:
- Set
serverVersionthrough a REST PATCH and wait for the account update to succeed. - Add a mongosh endpoint-readiness check after upgrading an existing account.
- Document the conditional mongosh prerequisite in both READMEs.
| File | Description |
|---|---|
samples/web-app-cosmosdb-mongodb-api/python/scripts/deploy.sh |
Adds version correction and endpoint-readiness checks for Python deployments. |
samples/web-app-cosmosdb-mongodb-api/python/README.md |
Documents when Python deployments require mongosh. |
samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/deploy.sh |
Adds version correction and endpoint-readiness checks for .NET deployments. |
samples/web-app-cosmosdb-mongodb-api/dotnet/README.md |
Documents when .NET deployments require mongosh. |
Review effort: Balanced
bryansan-local
approved these changes
Nov 11, 2026
…e mongosh check The mongosh check that deploy.sh ran after upgrading an existing account reached the account's public MongoDB endpoint from the deploying machine. On Azure, that endpoint answered "Request blocked by network firewall" for more than 30 minutes after an upgrade, while the web app, which reaches the account through the private endpoint, was already serving pages, so the check stopped a deployment that would have worked. The check and its mongosh prerequisite are removed. Both web apps now start without the database instead. The Python app creates its MongoDB client on the first request that needs it, under a lock, closes the client when the database setup fails, and shows "The database is not available. Try again in a minute." until the database answers; a missing connection string still stops it at startup. The .NET app initializes the store in a background service that retries every 15 seconds, and its pages show the same message instead of an error page; /health answers 503 until the database answers. A web app deployed while the MongoDB endpoint still serves the old server version therefore starts, and works as soon as the endpoint does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FvNuJLfY2KkMwaymfFnz7R
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation
samples/web-app-cosmosdb-mongodb-api/python/scripts/deploy.shandsamples/web-app-cosmosdb-mongodb-api/dotnet/scripts/deploy.shcreate the Cosmos DB account withaz cosmosdb create --kind MongoDB --server-version 7.0. Since azure-cli 2.90.0, the Azure CLI sends that value as aServerVersionproperty (api_properties['ServerVersion']incli_cosmosdb_createandcli_cosmosdb_updateofsrc/azure-cli/azure/cli/command_modules/cosmosdb/custom.py), and the service ignores it, so the account runs MongoDB server version 3.6. It is still so in azure-cli 2.92.0.The MongoDB drivers of both web apps refuse a 3.6 server. On Azure, the Python app failed with
ConfigurationError: Server at <account>-francecentral.mongo.cosmos.azure.com:10255 reports wire version 6, but this version of PyMongo requires at least 9 (MongoDB 4.4)and answered HTTP 503; the .NET app's MongoDB.Driver 3.x needs MongoDB 4.0 or later. The Bicep and Terraform deployments are not affected: they sendserverVersion.Fixes SMF-1140
Changes
deploy.shread the account'sapiProperties.serverVersion. When it differs fromMONGODB_API_VERSION, they setserverVersionwithaz rest(PATCH, with API version 2026-03-15, the one the Azure CLI uses) and wait until the account reports the new version withprovisioningStateSucceeded, which takes about a minute.StoreInitializerruns as a background service that retries every 15 seconds instead of stopping the app after one failure, and ends quietly when the app stops; the pages show the same message instead of an error page, and/healthanswers 503 until the database answers.Tests
On Azure (francecentral):
GET /200,POST /302, the new activity listed) and a fresh .NET deployment (the same,/healthok,POST /with the antiforgery token). Over a deployment of the script from main, the account reported 7.0, but the endpoint still served wire version 6 two minutes later, the Python app exited at startup, App Service waited 10 minutes before starting it again, andaz webapp deployreported "Deployment failed because the site failed to start within 10 mins" about 40 seconds before the app came up healthy.GET /answered 200 with the database message. The finaldeploy.shthen upgraded the account to 7.0 and redeployed ("Site started successfully", 80 s); 90 seconds later the page showed no error,POST /answered 302, and the new activity was listed.deploy.sh, fresh deployment: 3.6 upgraded to 7.0, the site started at the first try (227 s),/healthok,GET /200 with no database message,POST /302 with the antiforgery token, the new activity listed.Locally, against MongoDB 8.0 in Docker:
GET /answers 200 with the database message, andPOST /302. After mongod starts, without restarting the app,GET /shows no error,POST /adds the activity and lists it, and the delete removes it./healthanswers 503 andGET /200 with the database message. After mongod starts,/healthanswers 200 within a second andGET /shows no error; after mongod stops again,GET /still answers 200 with the message and/health503. SIGTERM ends the app with exit code 0 and no host error in the log.On the emulator, this PR's CI runs every deployment method of both languages. The deploy script without the mongosh check is the one that passed on the emulator (
localstack/localstack-azure2026.11.0.dev842) in fresh and repeated runs before 0e5e58e.Related
🤖 Generated with Claude Code
https://claude.ai/code/session_01FvNuJLfY2KkMwaymfFnz7R