Sto provando a connettermi al mio mongodb utilizzando nodejs e socket.io. Sono in grado di connettersi al database perché ricevo 'connessione accettato' nella mia console, ma sul lato nodejs, non appena ho - anzi - ottenere'process.nextTick (function() {throw err;})' - Undefined non è una funzione (mongodb/mangusta)
Connection to mongodb://localhost:27017 established through mongoose
non riesce immediatamente successivo con
process.nextTick(function() { throw err; }) ^TypeError: undefined is not a function at showCollections**
E qui vale 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);
});
}
});
}
E qui è il contenuto della mia cartella di database:
_tmp (empty folder)
local.0
local.ns
mongod.lock
Eseguo il file mongodb digitando mongod --dbpath folder e "attende con successo le connessioni sulla porta 27017".
Inoltre, i miei node_modules da package.json (NPM)
"dependencies": {
"express": "^4.9.6",
"socket.io": "latest",
"mongodb": "~2.0",
"mongoose": "*"
}
La ringrazio molto per il vostro aiuto ...
StackTrace:
> 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)
EDIT:
che sto così avere questi problemi quando si cerca di eseguire l'istanza nodejs:
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
Ho provato fissandole come altre domande qui avrebbero detto, ma niente ha funzionato o ...
È possibile pubblicare la traccia di stack effettiva che viene stampata? Questo dovrebbe dirti * dove * in 'showCollections()' ha origine l'errore. – mscdex
@mscdex come posso stampare la traccia dello stack? dovrebbe essere stampato di default? – Fane
Sì, avrebbe dovuto essere visualizzato sotto l'errore TypeError che hai ottenuto. – mscdex