0
我的代碼如下所示:爲什麼我的nodejs腳本沒有退出到shell?
當我運行該腳本,它表明:
$ node test.js
null null
但劇本沒有放棄。我需要「CTRL + C」退出它。任何機構知道如何解決它?
[更新]
我發現,如果我使用本機的MongoDB代替mongojs,沒有任何問題:
#!/bin/env node
var client = require('mongodb');
client.connect('mongodb://127.0.0.1:27017/hatch', function(err, db) {
if (err) throw err;
var collection = db.collection('documents');
collection.find().toArray(function(err, results) {
console.dir(results);
db.close();
});
});
因此,它是一個mongojs問題?
見我的答案,你必須關閉連接。 – user568109