我想使用 FratherJS 框架根据 URL 中提到的 id 属性获取用户数据:(/user/488/all
)
var mongooseService = require('feathers-mongoose');
...
app.use('user/:id/all', mongooseService({
name: 'agency',
Model: require('models/user') //user.id is the ID of user model
}));
...
我不想使用此网址:/user/488
最佳答案
Feathers 标准 URL 是特意围绕 REST 构建的URL 最佳实践,尽管并非不可能,但只有在有充分理由的情况下我才会打破它。为了与现有客户端兼容,您可以使用custom service创建别名。 :
const mongooseService = require('feathers-mongoose');
app.use('/users', mongooseService({
name: 'agency',
Model: require('models/user') //user.id is the ID of user model
}));
class UserAliases {
async find(params) {
const { id } = params.route;
return this.app.service('users').get(id, params);
}
setup(app) {
this.app = app;
}
}
app.use('/user/:id/all', new UserAliases());
关于javascript - 根据feathersJs api中自定义ID名称从mongo数据库获取模型数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48826742/