Error entering NodeJS + Express + Mongoose database (MongoDB)

I get the error message "Sun Jun 12 15:27:12 SyntaxError: missing; before statement (shell): 1" in mongodb logs when I execute the following code using NodeJS / Express / Mongoose. I do not receive the error message returned by the function. Any guidance would be greatly appreciated.

// Launch express and server
var express = require('express');
var app = express.createServer();

//connect to DB
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://127.0.0.1/napkin_0.1');

// Define Model
var Schema = mongoose.Schema;

var UserSchema = new Schema({
    name : String,
    age : String
});

mongoose.model('Document', UserSchema);
var User = mongoose.model('Document');

var user = new User();

user.name = 'Jim';
user.age = '27';
user.save(function(err, user_Saved){
    if(err){
        throw err;
        console.log(err);
    }else{
        console.log('saved!');
    }
});

//Launch Server
app.listen(3002);
+3
source share
2 answers

The database name must not contain the symbol "."., Just delete. and it will work fine.

+18
source

@matty should not remove "throw err;"

because there are 2 callback errors if we kke it there

0
source

All Articles