2017-08-03 87 views
-1

试图通过这段代码连接到蒙戈DB数据库:终端语法错误:之后参数列表丢失)

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); 
}); 

但是,当我试图通过

终端连接到它
MG-MC-iMacs-iMac:~ MG-MC-TJUBA$ node mongodb/PingPongDB/connection.js 

它给我这个错误:

/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 

从我看到它说我错过了一个')'已经存在和需要。

+0

使用像jsHint或JSLint的或其他棉短绒在那里的一个工具... – epascarello

+0

更换点(。)用逗号(,) –

回答

0

语法错误在打开后你的代码

mongoose.connection.once('open', function(){ 
console.log('Connection has been made');           

}).on('error', function(error){ 
console.log('Connection Error:', error); 
}); 
相关问题