Specify returned fields in Node.js / Waterline?

前端 未结 3 1536
灰色年华
灰色年华 2021-01-02 13:16

I want to make a request like:

User.find().exec(function(){});

I know I can use toJSON in the model however I don\'t like this

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-02 13:58

    Waterline does not currently support any "select" syntax; it always returns all fields for a model. It's currently in development and may make it into the next release, but for now the best way to do what you want would be to use model class methods to make custom finders. For example, User.findUser(criteria, cb) could find a user give criteria, and then check whether it was the logged-in user before deciding which data to return in the callback.

提交回复
热议问题