Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to deploy fresh instance #81

Closed
matthew5025 opened this issue Sep 14, 2021 · 1 comment
Closed

Unable to deploy fresh instance #81

matthew5025 opened this issue Sep 14, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@matthew5025
Copy link
Contributor

matthew5025 commented Sep 14, 2021

Issue

This application fails to function when being deployed for the first time (ie MongoDB is empty)

The error is as follows

(node:15516) UnhandledPromiseRejectionWarning: MongoError: ns does not exist: ctf.challs
    at MessageStream.messageHandler (ctf_platform\api\node_modules\mongodb\lib\cmap\connection.js:272:20)
    at MessageStream.emit (events.js:375:28)
    at processIncomingData (ctf_platform\api\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
    at MessageStream._write (ctf_platform\api\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at MessageStream.Writable.write (internal/streams/writable.js:303:10)
    at Socket.ondata (internal/streams/readable.js:726:22)
    at Socket.emit (events.js:375:28)
    at addChunk (internal/streams/readable.js:290:12)
    at readableAddChunk (internal/streams/readable.js:265:9)

The issue seems to be introduced in 3ebb595

The file startupChecks.js attempts to add the validator option to three collections on line 10-12.

Although the collections were created in mongDB.js, MongoDB only attempts to create the collection when a document is inserted.
As such, the collection is not created, and when startupChecks.js attempts to apply the validator option, the referenced collection does not exist and the application fails.

Solution

Apply the validator when creating the collection (aka in mongoDB.js rather than in the startupChecks.js)?

I'll open a PR if you think this is a valid solution

@Tkaixiang
Copy link
Contributor

Tkaixiang commented Sep 15, 2021

Hi, it would be great if you could open a PR! But I think you might still need to insert a dummy document of some sorts in order to force mongoDB to create a collection. Either that or if the collection does not exist, db.createCollection() can be ran with the validators

Thanks for spotting this! I never tested it on a fresh instance b4

@Tkaixiang Tkaixiang added the bug Something isn't working label Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants