我想使用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

最佳答案

羽毛标准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 - 根据羽毛中的自定义ID名称从mongo数据库获取模型数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48826742/

10-12 00:00
查看更多