SailsMVC Setup and mLab MongoDB Atlas Sessions
Fullstack Social iOS NodeJS REST
The first task we'll take care of in this course is to set up a SailsMVC Web App that comes with a couple of extras that are super useful. The most important aspect of this web app is that it comes with User Authentication so that we don't have to write that code ourselves. Once we set up our project, I'll also go over configuring Sessions with mLab and MongoDB Atlas. Getting sessions working properly will make our lives much easier in terms of restarting our application server.

Comments (17)
pboabang@gmail.com
4 years ago
Just purchase the course, I am having trouble with async and await as a result it causing sail mvc from running can you please help
Brian Voong
4 years ago
pboabang@gmail.com
4 years ago
Hey Brian thanks for the quick response, This is the error I am getting: error: A hook (`userconfig`) failed to load! error: error: Attempted to `require('/Users/philipboabang/Desktop/SAILS/web-social/config/bootstrap.js')`, but an error occurred: -- /Users/philipboabang/Desktop/SAILS/web-social/config/bootstrap.js:12 module.exports.bootstrap = async function() { ^^^^^^^^ SyntaxError: Unexpected token function at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at /Users/philipboabang/Desktop/SAILS/web-social/node_modules/include-all/lib/help-include-all-sync.js:293:33 at Array.forEach (native) at _recursivelyIncludeAll (/Users/philipboabang/Desktop/SAILS/web-social/node_modules/include-all/lib/help-include-all-sync.js:178:11) at includeAll (/Users/philipboabang/Desktop/SAILS/web-social/node_modules/include-all/lib/help-include-all-sync.js:317:5) at helpBuildDictionary (/Users/philipboabang/Desktop/SAILS/web-social/node_modules/include-all/lib/help-build-dictionary.js:46:13) at Function.module.exports.aggregate (/Users/philipboabang/Desktop/SAILS/web-social/node_modules/include-all/index.js:101:10) at loadOtherConfigFiles (/Users/philipboabang/Desktop/SAILS/web-social/node_modules/sails/lib/hooks/moduleloader/index.js:162:22) at runTask (/Users/philipboabang/Desktop/SAILS/web-social/node_modules/sails/node_modules/async/dist/async.js:1621:13) at /Users/philipboabang/Desktop/SAILS/web-social/node_modules/sails/node_modules/async/dist/async.js:1559:13 at processQueue (/Users/philipboabang/Desktop/SAILS/web-social/node_modules/sails/node_modules/async/dist/async.js:1569:13) at Object.auto (/Users/philipboabang/Desktop/SAILS/web-social/node_modules/sails/node_modules/async/dist/async.js:1555:5) at Hook.loadUserConfig (/Users/philipboabang/Desktop/SAILS/web-social/node_modules/sails/lib/hooks/moduleloader/index.js:160:13) at Hook.wrapper [as loadUserConfig] (/Users/philipboabang/Desktop/SAILS/web-social/node_modules/@sailshq/lodash/lib/index.js:3275:19) --
pboabang@gmail.com
4 years ago
i have not written a code yet but I have that issues with async and await function, I am running node v 10.16 and I am using visual code studio as the ide.
Brian Voong
4 years ago
pboabang@gmail.com
4 years ago
Hey Good Morning Brian I just send you the zip file thank you
Christopher J. Roura
2 years ago
Check to make sure you are white listing your IP address. In mongodb go to network access under the security panel and then add your IP address there.
shubhamsaurav
4 years ago
Thanks for the course!
Ohad Yaniv
4 years ago
Hi Brian, Followed everything step by step but cannot get the site back to life after the mLab setup. keep getting the error below: debug: Environment : development debug: Port : 1337 debug: ------------------------------------------------------- /Users/ohadyaniv/Library/CloudStorage/iCloud Drive/Documents/YMS/MyGarden/web_social/node_modules/mongodb/lib/mongo_client.js:421 throw err ^ MongoError: failed to connect to server [ds149947.mlab.com:49947] on first connect [MongoError: connection 0 to ds149947.mlab.com:49947 timed out] at Pool.<anonymous> (/Users/ohadyaniv/Library/CloudStorage/iCloud Drive/Documents/YMS/MyGarden/web_social/node_modules/mongodb-core/lib/topologies/server.js:336:35) at Pool.emit (events.js:198:13) at Connection.<anonymous> (/Users/ohadyaniv/Library/CloudStorage/iCloud Drive/Documents/YMS/MyGarden/web_social/node_modules/mongodb-core/lib/connection/pool.js:280:12) at Object.onceWrapper (events.js:286:20) at Connection.emit (events.js:198:13) at Socket.<anonymous> (/Users/ohadyaniv/Library/CloudStorage/iCloud Drive/Documents/YMS/MyGarden/web_social/node_modules/mongodb-core/lib/connection/connection.js:199:10) at Object.onceWrapper (events.js:286:20) at Socket.emit (events.js:198:13) at Socket._onTimeout (net.js:442:8) at ontimeout (timers.js:436:11) at tryOnTimeout (timers.js:300:5) at listOnTimeout (timers.js:263:5) at Timer.processTimers (timers.js:223:10) [nodemon] app crashed - waiting for file changes before starting... Can you give it a look? Many Thanks, Ohad
Brian Voong
4 years ago
Ohad Yaniv
4 years ago
Hey Brian, Well.. this is not going so well: debug: Environment : development debug: Port : 1337 debug: ------------------------------------------------------- /Users/ohadyaniv/Library/CloudStorage/iCloud Drive/Documents/YMS/MyGarden/web_social/node_modules/mongodb/lib/mongo_client.js:421 throw err ^ MongoError: failed to connect to server [cluster0-shard-00-02-j4xfk.mongodb.net:27017] on first connect [MongoError: connection 5 to cluster0-shard-00-02-j4xfk.mongodb.net:27017 timed out] at Pool.<anonymous> (/Users/ohadyaniv/Library/CloudStorage/iCloud Drive/Documents/YMS/MyGarden/web_social/node_modules/mongodb-core/lib/topologies/server.js:336:35) at Pool.emit (events.js:198:13) at Connection.<anonymous> (/Users/ohadyaniv/Library/CloudStorage/iCloud Drive/Documents/YMS/MyGarden/web_social/node_modules/mongodb-core/lib/connection/pool.js:280:12) at Object.onceWrapper (events.js:286:20) at Connection.emit (events.js:198:13) at TLSSocket.<anonymous> (/Users/ohadyaniv/Library/CloudStorage/iCloud Drive/Documents/YMS/MyGarden/web_social/node_modules/mongodb-core/lib/connection/connection.js:199:10) at Object.onceWrapper (events.js:286:20) at TLSSocket.emit (events.js:198:13) at TLSSocket.Socket._onTimeout (net.js:442:8) at ontimeout (timers.js:436:11) at tryOnTimeout (timers.js:300:5) at listOnTimeout (timers.js:263:5) at Timer.processTimers (timers.js:223:10) [nodemon] app crashed - waiting for file changes before starting...
Ohad Yaniv
4 years ago
^ Mongo Atlas
julioest
3 years ago
Hey Brian! So I'm getting this error through using mLab way … "Error occurred in session middleware :: 'Error: secret option required for sessions\n …" It's like the 'secret' is not valid, or is required somewhere else in the project. But I'm not sure where. Big bummer, I bought this months ago and finally had time to get into it! Any thoughts on this?
Brian Voong
3 years ago
julioest
3 years ago
julioest
3 years ago
TY - Worked perfectly! Not sure what I did on my end to make it error out
David EJ
3 years ago
hi bryan can i use de mongoDB 3.1.2 ?
omari
3 years ago
Hey Brian, why we should use the latest version of 1. ?
turtle0001
3 years ago
Hi Bryan, I'm getting an error after I included the "url: '<my MongoDB URI>'," I also tried to use MonggoDB atlas but still having the same error. Before that, I can still run my project but after that even I try to remove the url and run it again, I can't run it anymore. I also check below. I believe I'm have the same problem. please help.
georrgee
3 years ago
To anyone having trouble with setting up Atlas, I downloaded the project that Brian included and replaced all the files in my Sails Project Folder. After that, just go to your Cluster and copy YOUR url and then provide the password and it works as it should be!
sancjose
3 years ago
If anyone is still seeing an 'error: Error occurred in session middleware :: 'Error: secret option required for sessions\n' +' message-- In Mongodb Atlas, use Node.js version 2.2.12 or later in the version dropdown to get the correct connection string along with mongo-connect version found in project download.
Kimleng Hor
3 years ago
Hello Brian, I am using mlab, and I got this error message: Error occurred in session middleware :: 'Error: secret option required for sessions\n' + ' at session (/Users/kimlenghor/Documents/Web Dev Learning /web-social/node_modules/express-session/index.js:199:12)\n' + ' at app._privateSessionMiddleware (/Users/kimlenghor/Documents/Web Dev Learning /web-social/node_modules/sails/lib/hooks/session/in.....
Brian Voong
3 years ago
Kimleng Hor
3 years ago
Thanks Brian for replying me. I tried to install lower version of connect-mango, but I got authentication failed issue. The post does not have any other solutions.
Kimleng Hor
3 years ago
JMan
2 years ago
mLab MongoDB is not showing up in my add-ons in heroku. What should I do?
Brian Voong
2 years ago
JMan
2 years ago
Ha, thanks. Thought it might of been something on my end. Great course!
indra
2 years ago
Could you give us video tutorial how to setup use MLab mongo db (heroku mlab mongodb add on is discontinued) ?
Lazaro Ambrosio
2 years ago
Hi Brian, I was looking for add ons for the Heroku application. I don't find either MLAb and MongoDB Atlas. What should I do to be able to continue?
Brian Voong
2 years ago
Lazaro Ambrosio
2 years ago
Thank you for clarifying! Was able to set it up!
JMan
2 years ago
For my url in Mongo DB atlas there is a part where it asks for my dbname in the url, would that just be Cluster0?
MaxApp
2 years ago
you can put anything you want i.e. test, table whatever works for you!
JMan
2 years ago
Cool, thanks!
MaxApp
2 years ago
Hey Brian, I am getting this error while setting up my connect-mongo even tho its set up as "^1.3.2". /Users/user/Desktop/FullstackSocial/API/web_social/node_modules/mongodb/lib/server.js:231 process.nextTick(function() { throw err; }) ^ Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: Host: cluster0-shard-00-01.jjwij.mongodb.net. is not in the cert's altnames: DNS:*.mongodb.net, DNS:mongodb.net at Object.checkServerIdentity (tls.js:297:12) at TLSSocket.onConnectSecure (_tls_wrap.js:1507:27) at TLSSocket.emit (events.js:315:20) at TLSSocket._finishInit (_tls_wrap.js:932:8) at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:706:12) { name: 'MongoError' } [nodemon] app crashed - waiting for file changes before starting...
Mahmoud Youssef
2 years ago
Yup same here.. getting the same exact error. mongo ^1.3.2 node js latest update. used the connection url recommended by mongodb atlas, but everything leads to that error.
jasonbq
2 years ago
I'm having the same issue. Have you solved it?
Christopher J. Roura
2 years ago
Check to make sure you are allowing access on your network. To check in mongo db go to network access under security and while there add your current IP address. This bug tripped me up for a bit and will crash your app even if everything else is correct.
calm_wiz
2 years ago
Hey did you find a solution for this? I am having the same issue. I try allowing network access from everywhere but that didn't work.
Christopher J. Roura
2 years ago
I figured this out from trial and error and a bit of my own research into mongodb. It took me about 2 hours to diagnose. It was a while of just researching the error messages
calm_wiz
2 years ago
You wouldn't happen to remember what you did? or can point me in the right direction
calm_wiz
2 years ago
Ok, I managed to solve it as well.... I had to do a lot of googling as well lol. Not fully sure if all the steps I took were needed but if anyone is still experiencing the issues they can give these steps a try/ 1) Ensure that the database is created on the MongoDB Atlas site and replace the 'myFirstDatabase' (or 'test') in your collection string with the database name. 2) Ensure that mongodb-core is up to date... run 'npm install mongodb-core' 3) Ensure that sails-mango is up to date... run 'npm install sails-mongo --save' 4) Add ' ssl: true, stringify: false, ' In the session.js file P.S the 'stringify:false' was used to fix and another error that came up after I update the mongodb-core package Reference: https://stackoverflow.com/questions/42716874/mongodb-atlas-%EF%B8%8E-sailsjs-waterline-sails-mongo-adapter Hope these can help anyone who is experiencing the issue
MaxApp
2 years ago
Hey Brian, I think if you update nodejs and sailsjs you will get this error if you follow the same steps that you gave in this video. also heroku does not allow you to signup for mLab. They have updated there website! If you can please check if you can update your nodejs and sailsjs and see if this would work.
MaxApp
2 years ago
I have done a lot of research on how to fix this but still with no progress so far :( what I did is setup a new web app then go to Mongodb and create a project + a cluster + a username and allowed my IP address. then I went back to the project ran this npm install connect-mongo@1.1.0 --save --save-exact added the ^ symbol then ran this npm install connect-mongo lastly went to the session file and put this adapter: 'connect-mongo', url: 'mongodb://***', collection: 'sessions',
MaxApp
2 years ago
I have the url setup correctly because I took it and put it into the MyJournal project which I made before updating nodejs and sailsjs. And it worked correctly but after updating everything went down for me :(
MaxApp
2 years ago
?
Brian Voong
2 years ago
MaxApp
2 years ago
for me it does not work. I tried everything possible for it to work. this problem happened after updating my nodejs and sailsjs. Could you please update yours and see if it works for you? I tired and followed the steps in the video for 4 times but with no progress!
sync__
2 years ago
Im having this issue also
sync__
2 years ago
I solved my issue by doing a clean install `npm ci`. it worked then.
Christopher J. Roura
2 years ago
For all those having trouble and getting unknown errors in mongodb, the most likely culprit is lack of network access through mongodb. To enable access in mongodb to your local network go to your cluster and then under the security tab click on network access. there add your current IP address to the list of IP addresses (will just have 0.0.0.0 to start).
HELP & SUPPORT