我試圖使用nodejs和socket.io連接到我的mongodb。我能,因爲我得到儘快連接到數據庫,在我的控制檯,但上的NodeJS側「接受的連接」,因爲我 - 事實上 - 取得'process.nextTick(function(){throw err;})' - 未定義不是函數(mongodb/mongoose)
Connection to mongodb://localhost:27017 established through mongoose
立即與
下次故障process.nextTick(function() { throw err; }) ^TypeError: undefined is not a function at showCollections**
而且這裏去showCollections:
var showCollections = function(db, callback) {
mongoose.connection.db.collectionNames(function(error, names) {
if (error) {
throw new Error(error);
} else {
console.log("=>Listening mongo collections:");
names.map(function(cname) {
mongoose.connection.db.dropCollection(cname.name);
console.log("--»"+cname.name);
});
}
});
}
這裏是我的數據庫文件夾的內容:
_tmp (empty folder)
local.0
local.ns
mongod.lock
我運行mongodb,輸入mongod --dbpath文件夾併成功'等待端口27017上的連接'。
此外,從的package.json(NPM)我node_modules
"dependencies": {
"express": "^4.9.6",
"socket.io": "latest",
"mongodb": "~2.0",
"mongoose": "*"
}
非常感謝您的幫助...
堆棧跟蹤:
> TypeError: undefined is not a function
> at showCollections (/usr/share/nginx/www/index.js:77:25)
> at NativeConnection.callback (/usr/share/nginx/www/index.js:46:3)
> at NativeConnection.g (events.js:199:16)
> at NativeConnection.emit (events.js:104:17)
> at open (/usr/share/nginx/www/node_modules/mongoose/lib/connection.js:485:10)
> at NativeConnection.Connection.onOpen (/usr/share/nginx/www/node_modules/mongoose/lib/connection.js:494:5)
> at /usr/share/nginx/www/node_modules/mongoose/lib/connection.js:453:10
> at /usr/share/nginx/www/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:59:5
> at /usr/share/nginx/www/node_modules/mongoose/node_modules/mongodb/lib/db.js:200:5
> at connectHandler (/usr/share/nginx/www/node_modules/mongoose/node_modules/mongodb/lib/server.js:272:7)
編輯:
我試圖運行實例的NodeJS時以及有這些問題:
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
我試圖修復他們其他的問題在這裏要告訴但是毫無效果要麼...
你可以發佈打印出來的實際堆棧軌跡嗎?這應該告訴你* showCollections()中的錯誤來自哪裏。 – mscdex 2015-04-04 17:33:22
@mscdex如何打印堆棧跟蹤?它應該默認打印? – Fane 2015-04-04 17:39:10
是的,它應該在你得到的TypeError下顯示。 – mscdex 2015-04-04 17:42:30