javascript - 如何在 strongloop 的结果中隐藏特定字段

标签 javascript rest strongloop

我正在尝试使用 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();
                }
            });

这里“result will give all details”我想在结果中隐藏密码

提前致谢

最佳答案

试试这个。

{ 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 https://docs.strongloop.com/display/public/LB/Remote+hooks

关于javascript - 如何在 strongloop 的结果中隐藏特定字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35839840/

相关文章:

javascript - Onclick简单的JS菜单。我需要一些建议

javascript - 从 XSD 创建 Web 表单,然后输出 xml 表单

java - REST API - DTO 与否?

node.js - 检查用户是否登录(Strongloop 和 NodeJS)

javascript - jqueryUI 可排序 : Uncaught Error: HIERARCHY_REQUEST_ERR: DOM Exception 3

javascript - JQuery - 在加载时触发通知而不是 onClick

java - Spring Batch - 如何使用从 REST API 请求收到的文件名启 Action 业

java - 在 REST Web 服务内的请求/响应场景中使用 Kafka

strongloop - 如何在环回4中加密密码?

javascript - babel/register 未在服务器上运行