A review of connecting to mongodb
…
step 1: Create a new cluster
step 2: Select service + region
I tried to save data to mongodb. After double checking the password, the IP whitelist and that the connection string was correct, I still got these errors even if I succeeded in creating collections but unfortunately no data was saved to it.
save section:
1 | note.save().then(result => { |
mongodb dashboard:
Then I followed the steps on Telegram and add catch()
to catch errors
save section:
1 | note.save().then(result => { |
But still one error left and no data in mongodb dashboard:
Eventually I found the solution that successfully saved the data to collection:
Anyone else who get this warning when connecting to mongoDB cluster just change the driver version from 3.* to 2.* From connect > connect your application > version select 2.2.* or later
So the url section turned to this:
1 | const url = `mongodb://fullstack:${password}@cluster0-shard-00-00.xfjup.mongodb.net:27017,cluster0-shard-00-01.xfjup.mongodb.net:27017,cluster0-shard-00-02.xfjup.mongodb.net:27017/myFirstDatabase?ssl=true&replicaSet=atlas-rob6kd-shard-0&authSource=admin&retryWrites=true&w=majority` |
It worked!
catch()
is not a must for this case
And I noticed the INDEXES TOTAL SIZE decreased to 4KB after I tried one more time. I’m not sure if it’s a bug because the collection still said the Index Size was 20KB.
Alright, it turned out to be a bug…