D
D
Deodatuss2015-01-13 12:18:53
JavaScript
Deodatuss, 2015-01-13 12:18:53

What is the problem with mongoDB?

In general, I decided to learn Backbone.js from the book by Eddie Osmani. One of the chapters creates a REST API based on node.js and mongoDB. So, I installed everything, drove the following code into server.js :

mongoose.connect( 'mongodb://localhost/library_database' );
var Book = new mongoose.Schema({
    title: String,
    author: String,
    releaseDate: Date
});
var BookModel = mongoose.model( 'Book', Book );

app.get( '/api/books', function( request, response ) {
    return BookModel.find( function( err, books ) {
        if( !err ) {
            return response.send( books );
        } else {
            return console.log( err );
        }
    });
});

And node started throwing errors and won't start the server:

Express server listening on port 4711 in development mode
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
at null. (C:\Users\Deo\Desktop\proj\backboneChapter2\node_modules\mongo
ose\node_modules\mongodb\lib\mongodb\connection\server.js:536:74)
at emit (events.js:106:17)
at null . (C:\Users\Deo\Desktop\proj\backboneChapter2\node_modules\mongo
ose\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:140:15)
at emit (events.js:98:17)
at Socket . (C:\Users\Deo\Desktop\proj\backboneChapter2\node_modules\mon
goose\node_modules\mongodb\lib\mongodb\connection\connection.js:478:10)
at Socket.emit(events.js:95:17)
at net.js:440:14
at process._tickCallback(node.js:419:13)

Although I did everything by the book. Suspicion falls on the line
mongoose.connect( 'mongodb://localhost/library_database' );
, because I do not understand why it connects if nothing was created. In general, such a chaotic question. If anyone has experience with this, I would appreciate any help or advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2015-01-13
@Deodatuss

Maybe you just didn't start the daemon mongod.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question