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!
function()in both of your method calls. What iscallback()that you have put in there twice? Possibly too literal a translation from the documentation or is it intended to be something else?