参数列表后面的Terminal SyntaxError:missing)

时间:2017-08-03 14:05:08

标签: javascript mongodb syntax terminal

尝试通过以下代码连接到Mongo 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

从我所看到的情况来看,我错过了一个已经存在且需要的')'。

1 个答案:

答案 0 :(得分:0)

代码中的语法错误

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

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