我目前正在嘗試與節點和Mongo搞混了一些自學。我一直在看各種博客文章,並且一直在搞一個簡單的博客,用mongo db來編寫節點。Node.js mongodb本地驅動程序身份驗證在cloudfoundry
無論如何,我很難讓它在cloudfoundry中工作。我看了關於認證MongoDB的本地用戶組,並發現了一些節點腳本:
var Db = require('mongodb').Db;
var Connection = require('mongodb').Connection;
var Server = require('mongodb').Server;
var BSON = require('mongodb').BSON;
var ObjectID = require('mongodb').ObjectID;
ArticleProvider = function(dbname,host, port,username,password) {
this.db= new Db(dbname, new Server(host, port, {auto_reconnect: true}, {}));
this.db.open(function(){
this.db.authenticate(username, password, function(err, db) {
callback(err, db);
});
});
};
我不能爲我的生命得到這個工作。
this.db.authenticate(username, password, function() {});
^
TypeError: Cannot call method 'authenticate' of undefined
at /home/ben/NodeJS/sandbox/NodeBlog/articleprovider-mongodb.js:10:17
at /home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/db.js:81:14
at /home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/connections/server.js:76:11
at /home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/admin.js:16:12
at [object Object].<anonymous> (/home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/admin.js:124:12)
at [object Object].emit (events.js:67:17)
at [object Object].<anonymous> (/home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/connections/server.js:97:12)
at [object Object].emit (events.js:64:17)
at Socket.<anonymous> (/home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/connection.js:108:16)
at Socket.emit (events.js:64:17)
任何人都能指出我是一個完整的facepalmer將不勝感激。