两个约束:使用node-restful和使用mongoose.createConnection创建非全局连接(因为测试目的)。
下面的代码不起作用:
var someSchema = require('./someSchema');
var restful = require('node-restful');
var model = restful.model('some', someSchema);
//far far away...
var connection = restful.mongoose.createConnection();
connection.on('connected', function() {
restful.register(app, '/somes');
}GET /somes在某个地方导致无限循环,或者不触发回调。无论如何,节点restful model.js代码不支持连接,而且模型对当前连接一无所知。有人知道如何与模特建立联系吗?我被卡住了。
发布于 2015-08-15 22:56:42
我看了看
https://github.com/baugarten/node-restful/blob/master/lib/model.js
我看到代码向猫鼬注册模型:
var result = mongoose.model.apply(mongoose, arguments)...传入猫鼬变量。
因此,节点-restful总是查找在默认的猫鼬连接上注册的模型。您通过调用:
mongoose.connect("mongodb://localhost/resources");您必须重写节点-restful代码,以允许传入连接,而不是仅仅使用mongoose实例。我不知道这会有多容易或有多难。
https://stackoverflow.com/questions/32024407
复制相似问题