Encountering an issue while attempting to establish a connection with a Mongo DB database using the following code:
const mongoose = require('mongoose');
//Connect to mongodb
mongoose.connect('mongodb://localhost/testaroo');
mongoose.connection.once('open'.function(){
console.log('Connection has been made');
}).on('error', function(error){
console.log('Connection Error:', error);
});
However, when trying to connect through Terminal
MG-MC-iMacs-iMac:~ MG-MC-TJUBA$ node mongodb/PingPongDB/connection.js
An error is displayed:
/Users/MG-MC-TJUBA/mongodb/PingPongDB/connection.js:6
mongoose.connection.once('open'.function(){
^
SyntaxError: missing ) after argument list
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
The error message suggests a missing ')' that seems to be already present and necessary based on my analysis.