Azure Function CosmosDB触发器返回编码后的数据吗? [英] Azure Function CosmosDB Trigger returned encoded data?

查看:51
本文介绍了Azure Function CosmosDB触发器返回编码后的数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简短的azure函数,以简单地从CosmosDB更改提要触发器中获取数据.

但是,看起来它返回了某种形式的编码数据.

例如

  {"_id":ObjectId("5ad8db107dfa95101430ab94"),"id":"task123","type":"genera123l",信息":某些任务"} 

如果上述文档是在我的cosmos数据库中创建的,

  public static void Run(IReadOnlyList< Document>文档,TraceWriter日志){if(documents!= null&& documents.Count> 0){log.Info(文档已修改" + document.Count);log.Info(第一个文档ID" + documents [0] .Id);}} 

以上代码将打印

  2018-04-19T19:28:23.899 [Info]文档已修改12018-04-19T19:28:23.899 [Info]第一个文档ID NWFkOGRiMTA3ZGZhOTUxMDE0MzBhYjk0 

代替

  2018-04-19T19:28:23.899 [Info]文档已修改12018-04-19T19:28:23.899 [Info]第一个文档ID task123 

这是预期的输出.我在这里缺少某种配置吗?

看起来像没有CosmosDB或Azure Function App的文档解决这个问题:(

谢谢

解决方案

我假定您使用 Azure CosmosDB MongoDb API进行输入绑定.

请尝试使用 Azure CosmosDB SQL API .您可以参考此

I wrote a short azure function to simply take data in from CosmosDB change feed Trigger.

However, looks like it returns some form of encoded data.

For example

{
    "_id" : ObjectId("5ad8db107dfa95101430ab94"),
    "id" : "task123",
    "type" : "genera123l",
    "information" : "some task"
}

If above document is created in my cosmos db,

public static void Run(IReadOnlyList<Document> documents, TraceWriter log)
{
    if (documents != null && documents.Count > 0)
    {
        log.Info("Documents modified " + documents.Count);
        log.Info("First document Id " + documents[0].Id);
    }
}

above code will print

2018-04-19T19:28:23.899 [Info] Documents modified 1
2018-04-19T19:28:23.899 [Info] First document Id NWFkOGRiMTA3ZGZhOTUxMDE0MzBhYjk0

instead of

2018-04-19T19:28:23.899 [Info] Documents modified 1
2018-04-19T19:28:23.899 [Info] First document Id task123

which is the expected output. Is there some sort of configuration that I'm missing here?

Looks like none of the documentations for CosmosDB or Azure Function App addresses this issuse :(

Thanks

解决方案

I assume that you use the Azure CosmosDB MongoDb API for input bindings.

Please hava a try to use the Azure CosmosDB SQL API. Detail steps you could refer to this guide. Then you could get the expected answer. For more information, please refer to this link.

Don't use Azure Cosmos DB input or output bindings if you're using MongoDB API on a Cosmos DB account. Data corruption is possible.

这篇关于Azure Function CosmosDB触发器返回编码后的数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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