2017-10-11 107 views
0

我们都知道,我们可以使用Azure功能(使用输出参数或使用返回)一次在cosmos DB中保存一个文档,如:将对象列表从Azure功能保存到cosmos DB(文档DB或mongo DB)

object outputDocument = new { id = Guid.NewGuid().ToString(), 
            customObjList= objList 
          }; 

其中objList是自定义对象的列表。 现在上面的outputDocument将返回一个json Document,并且DB中的数据将以下面的格式保存。

{ 
    "id" : "....", 
    "customObjList" :[ 
     { 
      "_id" : "81afbe1a-3da0-4143-9dc6-0b3bf5252e0d", 
      ... 
     }, 
     { 
      "_id" : "2af7e1ac-15ca-424e-8af1-d3e5a2cca8de", 
      .... 
     }, 
     ..... 
]} 

但我要的是类似下面的文件列表直接从Azure的存储功能

/* 1 */ 
    { 
    "_id" : "81afbe1a-3da0-4143-9dc6-0b3bf5252e0d", 
    ... 
    } 
    /* 2 */ 
    { 
     "_id" : "2af7e1ac-15ca-424e-8af1-d3e5a2cca8de", 
     .... 
    } 

[对我的要求是,从RSS源获取数据并保存到宇宙数据库,我第一次读取它,并将数据存储在对象列表中,但无法将这些对象列表单独保存在宇宙数据库中]

+0

为什么不只是做一个直接写(或写)到宇宙DB,从你的函数? –

回答

1

您可以使用一次保存多个文档或者如果您有异步功能,请使用IAsyncCollector

这是你将如何输出多个对象:

public static void Run(ICollector<object> myQueueItem, TraceWriter log) 
{ 
    foreach (object obj in objList) 
    { 
     var objnew = { 
         id = Guid.NewGuid().ToString(), 
         someProperty = obj.someProperty 
        }; 

     myQueueItem.Add(objnew); 
    } 
} 

来源:Azure Documentation -- Writing multiple output values