我试图关注a tutorial,但在为mongodb连接创建新文件后,我在mongoConnection
文件中包含了此代码:
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(host, port) {
this.db= new Db('node-mongo-blog', new Server(host, port, {auto_reconnect: true}, {}));
this.db.open(function(){});
};
在另一个文件中,我尝试使用此代码定义新的ArticleProvider
来设置host
和port
:
var express = require('express');
var ArticleProvider = require('./mongoConnection').ArticleProvider;
var app = express();
var server = require('http').createServer(app);
var io = require('../')(server);
var connect = require('connect');
app.use(connect.logger('dev'));
app.use(connect.json());
app.use(connect.urlencoded());
var articleProvider = new ArticleProvider('localhost', 27017);
使用nodejs启动应用程序后,出现此错误:
var articleProvider = new ArticleProvider('localhost', 27017);
^
TypeError: undefined is not a function