与mongoose.createConnection一起使用node-restful

两个约束:使用node-restful和创build非全局连接(由于testing目的)使用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导致无限循环某处或不触发callback。 无论如何, 节点restful model.js代码显示不支持连接和模型不知道任何关于当前连接。 有人知道如何提供连接模型? 我被困住了。

我看了一下

https://github.com/baugarten/node-restful/blob/master/lib/model.js

我看到代码向mongoose注册模型:

 var result = mongoose.model.apply(mongoose, arguments)... 

传入mongoosevariables。

所以node-restful总是寻找在默认mongoose连接上注册的模型。 你通过调用创build的那个:

 mongoose.connect("mongodb://localhost/resources"); 

您将不得不重写节点代码,以允许传递连接而不是仅使用mongoose实例。 我不确定这将是多么容易或困难。