Domanda

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!

È stato utile?

Soluzione

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)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top