猫鼬没有方法`connect` [英] Mongoose has no method `connect`
本文介绍了猫鼬没有方法`connect`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用npm在node.js上安装了mongoose.当我尝试使用此代码连接时:
I installed mongoose on node.js using npm. When I try to connect with this code:
mongoose = require('mongoose/').Mongoose
@db = mongoose.connect("mongodb://localhost/test")
我收到此错误:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object function Mongoose() {
this.connections = [];
this.plugins = [];
this.models = {};
this.modelSchemas = {};
this.options = {};
this.createConnection(); // default connection
} has no method 'connect'
at new ChatService (/home/lolcoder/workspace/sampleApp/src/services/dbService.js:12:26)
at Object.<anonymous> (/home/lolcoder/workspace/sampleApp/src/app.js:40:17)
at Object.<anonymous> (/home/lolcoder/workspace/sampleApp/src/app.js:44:4)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
当在终端中执行mongo
时,我得到:
When do mongo
in terminal, i get:
MongoDB shell version: 2.0.2
connecting to: test
有人知道为什么猫鼬对象中没有connect()
方法吗?
Anyone knows why there is no connect()
method in the mongoose object?
推荐答案
代替
mongoose = require('mongoose/').Mongoose;
使用
mongoose = require('mongoose/');
这篇关于猫鼬没有方法`connect`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文