YuqiHuai / SORA-SVL

Local SVL Cloud
131 stars 33 forks source link

sorasvl-server error: TypeError: Cannot read properties of undefined (reading 'startsWith') ... at connectToDatabase (/workdir/dist/services/database.service.js:39:12) #5

Closed jimaldon closed 2 years ago

jimaldon commented 2 years ago

docker logs sorasvl-server gives me the following error when trying to debug why every container but sorasvl-server is up and running. I'm using the standard .env file like in the template

> server@1.0.0 start
> node dist/index.js

TypeError: Cannot read properties of undefined (reading 'startsWith')
    at connectionStringHasValidScheme (/workdir/node_modules/mongodb-connection-string-url/lib/index.js:9:30)
    at new ConnectionString (/workdir/node_modules/mongodb-connection-string-url/lib/index.js:85:34)
    at parseOptions (/workdir/node_modules/mongodb/lib/connection_string.js:209:17)
    at new MongoClient (/workdir/node_modules/mongodb/lib/mongo_client.js:62:63)
    at /workdir/dist/services/database.service.js:40:24
    at Generator.next (<anonymous>)
    at /workdir/dist/services/database.service.js:31:71
    at new Promise (<anonymous>)
    at __awaiter (/workdir/dist/services/database.service.js:27:12)
    at connectToDatabase (/workdir/dist/services/database.service.js:39:12)
YuqiHuai commented 2 years ago

Hi, This issue is caused by the server container being unable to connect to the MongoDB container.

Can you attach your .env file here so I can check?

jimaldon commented 2 years ago

server/.env

MONGO_URL="mongodb://sorasvl-mongo:27017"
MONGO_DB_NAME="WISE"
YuqiHuai commented 2 years ago

This looks correct. I am not sure where the problem can happen. Still looks like a connection issue.

Can you take a look if you can access the mongodb url using Mongo Compass (desktop application), mongo url "mongodb://localhost:27017"

YuqiHuai commented 2 years ago

I just did some searching it is also possible that you put the ".env" file at the wrong location. https://www.mongodb.com/community/forums/t/typeerror-cannot-read-property-startswith-of-undefined/146999/4

Can you confirm your file structure looks like the following? server/ ├── src/ (… ,db.js , index.js) ├── .env └── package.json

umdreamer commented 2 years ago

Hi @YuqiHuai Yuqi, I encouter the same problem. Do you know how to fix it? My .env is:

MONGO_URL="mongodb://sorasvl-mongo:27017"
MONGO_DB_NAME="WISE"

Which is not the "mongodb://localhost:27017" in your replay. Which is correct?

umdreamer commented 2 years ago

I finally worked out the problem. Should use the "mongodb://sorasvl-mongo:27017", this works.

YuqiHuai commented 2 years ago

Hi @umdreamer I apologize for the late reply!

where does it say mongodb://localhost:27017? I need to remove this

YuqiHuai commented 2 years ago

I am going to close this issue due to inactivity. Please reopen the issue if the problem isn't solved or open a new one for other issues.

Again, thank you so much for posting issues here!