I\'m trying to connect to my mongodb using nodejs and socket.io. I am able to connect to the database because I get \'connection accepted\' in my console bu
For me this error started popping up when i had to force shut down my pc as it became unresponsive. Next time i started my express server this error popped up. I solved it by running npm install mongoose@4.0 --save
in the terminal.
May be this error pops up when your server or database is force closed and some code is not save in mongod behind the scenes.
Shouldn't you specify the full path and have an export module?
...something like:
mongoose.connection.db.collectionNames(function (err, names)
{
console.log(names); // [{ name: 'dbname.myCollection' }]
module.exports.Collection = names;
}
If I'm wrong it's because I don't fancy moongodb :)
From the provided information, it looks like you are using mongodb 2.0 driver. The db.collectionNames method was dropped. Check out the "Db Object" section of this page - https://github.com/mongodb/node-mongodb-native/blob/0642f18fd85037522acf2e7560148a8bc5429a8a/docs/content/tutorials/changes-from-1.0.md#L38
They've replaced it with listCollections. You should get the same effect with:
mongoose.connection.db.listCollections().toArray(function(err, names) {
if (err) {
console.log(err);
}
else {
names.forEach(function(e,i,a) {
mongoose.connection.db.dropCollection(e.name);
console.log("--->>", e.name);
});
}
});