根据 feathersJs 中的自定义 ID 名称从 mongo 数据库中获取模型数据 api

Get model data from monogo database basing on custom ID name in featherJs api

我想根据 URL 中提到的 id 属性获取用户数据:(/user/488/all) 使用 FratherJS 框架

   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 
            }));
    ...

我不想使用这个 url : /user/488

Feathers 标准 URL 是有意围绕 REST URL best practises so, although not impossible, I would only break with it if there is a very good reason. To be compatible with existing clients you can create aliases using a 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());