MongoDB nodejs从函数创建新实例

时间:2015-03-13 11:40:48

标签: node.js mongodb

我试图关注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来设置hostport

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

0 个答案:

没有答案