使Azure DocumentDB不返回服务字段 [英] Make Azure DocumentDB do not return service fields

查看:50
本文介绍了使Azure DocumentDB不返回服务字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对节点应用程序中的Azure DocumentDB使用类似SQL的语法.这是方法代码

I'm using SQL-like sytax for Azure DocumentDB in node app. Here is method code

client.queryDocuments(collection._self, "SELECT * FROM root").toArray(function(err, results) {
    if (err) {
        callback(err);
    } else {
        callback(null, results);
    }
});

和响应

[
{
    "id": "test1",
    "name": "Kate",
    "email": "test@mail.com",
    "brands": [
        "AAAA",
        "BBB",
        "CCCi"
    ],
    "_rid": "WedNAN3lZgABAAAAAAAAAA==",
    "_self": "dbs/WedNAA==/colls/WedNAN3lZgA=/docs/WedNAN3lZgABAAAAAAAAAA==/",
    "_etag": "\"00001b00-0000-0000-0000-56fff6c60000\"",
    "_ts": 1459615430,
    "_attachments": "attachments/"
}

]

有什么方法可以使DocumentDb不重新运行服务字段(_rid,_self,_etag,_ts,_attachments),而不是在select子句中写入所有非服务字段?

Is there any way to make DocumentDb don't retrun service fields (_rid, _self, _etag, _ts, _attachments), but not writing all non-service fields in select clause?

推荐答案

已更新

仅使用查询,就无法使用查询取回除系统字段以外的所有字段,但无法在SELECT子句中列出每个非系统字段.但是,您可以使用存储过程来执行此操作,该存储过程会在返回之前或使用UDF执行相同操作之前对其进行过滤(请参见下文).

Just using a query, there is no way to get back all fields except system fields using a query but without listing each non-system field in the SELECT clause. However, you can do it with a stored procedure that filters them before returning or using a UDF to do the same thing (see below).

更新

其他人建议在列表返回后将其删除,但经过进一步考虑之后,可以通过查询和简单的用户定义函数(UDF)来做到这一点:

Others have suggested removing them after the list returns, but after thinking about this some more, it is possible to do this with a query and a simple user defined function (UDF):

function stripUnderscoreFields (o) { 
  output = {};

  for (key in o) {
    value = o[key];
    if (key.indexOf('_') !== 0) {
      output[key] = value;
    }
  }
  return output 
}

然后在这样的查询中使用UDF:

Then use the UDF in a query like this:

SELECT VALUE udf.stripUnderscoreFields(c) FROM collection c

这篇关于使Azure DocumentDB不返回服务字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆