javascript – 如何在strong循环中隐藏结果中的特定字段

我正在尝试使用strongloop创建一个项目,我正在为用户登录创建一个Web服务,我的代码运行良好&得到所需的输出,除了它不隐藏密码的事实

我得到了结果

{
    "result": [{
        "_id": 2,"address": "abc","created_by": 1,"created_date": "2016-03-04T00:00:00.000Z","firstname": "Anup","isdeleted": 0,"lastname": "Deshpande","mobile_number": "9700128907","oldpassword": "string","profile_picturename": "anup.jpeg","role_id": 1,"user_email_id": "anupd@ideaentity.com","user_password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8","user_status": 1
    }]
}

我想要隐藏或删除“user_password”:“5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8”,字段.

任何人都可以告诉我如何在strongloop的远程方法中做到这一点

我的renote方法代码如下

db.collection('users').find({
                user_email_id : par,user_password : sha256(par2)
            }).toArray(function(err,result) {

                // var passwordHash = hashPassword(user_password);
                // console.log(passwordHash);
                if (err) {
                    throw err;
                }
                if (result.length > 0) {
                    self.callback(null,result);
                    // db.disconnect();
                } else {
                    self.callback(null,response);
                    // db.disconnect();
                }
            });

这里“结果将提供所有细节”我想隐藏结果中的密码

提前致谢

解决方法

试试这个.

{ fields: {propertyName: <true|false>,propertyName: <true|false>,... } }

propertyName is the name of the property (field) to include or
exclude. signifies either true or false Boolean literal.
Use true to include the property or false to exclude it from results.
You can also use 1 for true and 0 for false. By default,queries
return all model properties in results. However,if you specify at
least one fields filter with a value of true,then by default the
query will include only those you specifically include with filters.

请参阅此链接
https://docs.strongloop.com/display/public/LB/Fields+filter

Example:
var query = { fields: {password: false} }
Model.find(query,function()
{
});

Otherwise you can manually remove in afterremotemethod(),in ctx.result. refer this link 07001

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...