3

I'm getting the error "Sun Jun 12 15:27:12 SyntaxError: missing ; before statement (shell):1" in the mongodb logs when I execute the following code using NodeJS/Express/Mongoose. I do not get an error returned from the function. Any guidance would be much 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);
0

2 Answers 2

17

DB name should not contain a '.' . Just remove the . and it will work fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, would have never found that. Thanks.
0

@matty shouldn t we remove the "throw err;"

because there is 2 callback on the error if we kke it there

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.