0

I'm trying to insert into collection but I get error not sure why. here is what I tried to do

db.collection("book", function(err, collection){

    if(err){
        console.log(err);
    }

    collection.insert({"name":req.query.file.split(".")[0],"length":response}, function(err,book) {
        if(err){
            console.log(err);
        }

        return callback(null);
        console.log(book);
    });

    return callback(null);

});

I'm trying to insert a "book" into book collection... as I saw in mongo document .collection and .insert requires callback. and my error is

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:900:11)
    at Server._listen2 (net.js:1038:14)
    at listen (net.js:1060:10)
    at net.js:1134:9
    at dns.js:72:18
    at process._tickCallback (node.js:415:13)

and I'm not sure what I'm doing wrong, thanks!

2
  • 1
    The "callback" is the argument you have specified as a function() in both of your method calls. What is callback() that you have put in there twice? Possibly too literal a translation from the documentation or is it intended to be something else? Commented May 13, 2014 at 8:03
  • well, I throwed the callbacks, I have it like this now: pastebin.com/M86GM08B still same error Commented May 13, 2014 at 8:35

1 Answer 1

1

Are you sure that it is because of insert? It is typical unhandled exception in case you try to start node.js process that listens for the same port as other process( or the same copy of this node.js process)

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

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.