Conversation
The Scorpio step of this repo's own CI failed on 2026-09-19 with
MongoServerError: Collection iotagentjson.devices already exists.
##[error]Process completed with exit code 1.
`addIoTDatabaseIndex` drops every collection in `iotagentjson` and then
re-creates `devices` and `groups`. The IoT Agent container is already up and
connected by then - it is started by the same `docker compose up` - so it can
create `devices` itself in the window between the drop loop and the
`createCollection` call.
On mongo 6.0, which is what `MONGO_DB_VERSION` pins, `db.createCollection` on
an existing collection throws `NamespaceExists` and `mongosh` exits 1. The
script runs under `set -e`, so the whole `services` invocation dies - after
the stack is up, before the tutorial has done anything.
The two `createCollection` calls are redundant: `createIndex` creates the
collection implicitly if it is missing. Removing them makes the block
idempotent and removes the window entirely, with no other change - verified on
mongo 6.0 that the resulting index sets are identical:
devices: {_id}, {_id.service,_id.id,_id.type}, {_id.type}, {_id.id}
groups: {_id}, {_id.resource,_id.apikey,_id.service}, {_id.type}
and that the amended block exits 0 when run twice in a row and when the
collection has been created concurrently in between - the two cases that make
the current version exit 1.
Note this is intermittent: the same commit passed on re-run. The eight other
tutorials carrying the same function are equally exposed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 19, 2026
Closed
Member
|
Fixed with a420da1 |
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.
This repo's own CI hit it on 2026-09-19, in the Run Scorpio step of the PR check for #16:
It is intermittent — the identical commit passed on re-run — so it shows up as a mystery red rather than as a bug.
The window
addIoTDatabaseIndexdoes:By the time it runs, the IoT Agent container is already up and connected to the same database — it is started by the same
docker compose up. If the agent createsdevicesbetween the drop loop and thecreateCollectioncall, the call fails.On mongo 6.0, which is what
MONGO_DB_VERSIONpins,db.createCollectionon an existing collection throwsNamespaceExists;mongoshthen exits 1; andservicesruns underset -e, so the whole invocation dies — after the stack is up, before the tutorial has run a single request.(Worth knowing for later: mongo 8 made
createCollectionreturn{ok:1}in this case, so bumpingMONGO_DB_VERSIONwould hide this rather than fix it.)The fix
The two
createCollectioncalls are redundant —createIndexcreates the collection implicitly when it is missing. Dropping them closes the window with no other change.Verified on mongo 6.0:
and the resulting indexes are identical either way:
Scope
Eight other tutorials carry the same function verbatim and are equally exposed:
Big-Data-Spark,Concise-Format,IoT-Agent,IoT-Agent-JSON,IoT-Sensors,Short-Term-History,Subscriptions,Time-Series-Data. Happy to send the same one-hunk change to each if you would rather not sync it by hand — just say.Independent of #16 — different file.
🤖 Generated with Claude Code