我有一个名为 customer_devices 的集合,我无法更改名称。我可以通过部署为 /devices 来公开它吗?如何?
问问题
114 次
2 回答
1
我能想到几种方法。如果您真的只想重命名集合,可以从仪表板进行,正如@thomasb 在他的回答中提到的那样。
或者,您可以创建“代理”事件资源devices
并将所有查询转发到customer_devices
. 例如,在devices/get.js
你会说
dpd.customer_devices.get(query, function(res, err) {
if (err) cancel(err);
setResult(res);
});
更新
最后,这是一个“hack”,将所有请求从一个资源路径重定向到不同的路径。这是经过不良测试的,因此使用风险自负。这要求您按照此处的说明设置自己的服务器。完成后,您可以使用以下代码段修改路由行为:
server.on('listening', function() {
var customer_devices = server.router.resources.filter(function (res) {
return res.path === '/customer_devices';
})[0];
// Make a copy of the Object's prototype
var devices = Object.create(customer_devices);
// Shallow copy the properties
devices = extend(devices, customer_devices);
// Change the routing path
devices.path = "/devices";
// Add back to routing cache
server.router.resources.push(devices);
});
这将获取您的customer_devices
资源,复制它,更改路径,然后将其重新插入到缓存的路由表中。我对其进行了测试并且它有效,但我不能保证它是安全的或一个好主意......
于 2015-11-11T15:24:36.597 回答
0
你不能通过仪表板更改名称吗?
- 将鼠标悬停在您的收藏 customer_devices
- 单击向下箭头
- 选择“重命名”
- 输入新名称,然后单击“重命名”
于 2015-11-12T15:45:42.720 回答