【发布时间】:2021-06-16 13:13:38
【问题描述】:
几天以来一直在尝试,似乎是 Azure Functions 中的一个错误。我正在尝试使用计时器触发器,从 Cosmos DB(输入绑定)读取文档并更新每个文档的一些属性(Cosmos DB 输出绑定)。不管我尝试什么,新属性都不会推送到 Cosmos DB。我确保 id 保持不变。
下面是我的function.json:
{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */10 * * * *"
},
{
"name": "DocumentInput",
"type": "cosmosDB",
"databaseName": "MyDB1",
"collectionName": "MyCC1",
"sqlQuery": "SELECT * FROM c",
"partitionKey": "/key",
"connectionStringSetting": "CosmosDBConnectionExp",
"direction": "in"
},
{
"name": "DocumentOutput",
"type": "cosmosDB",
"databaseName": "MyDB1",
"collectionName": "MyCC1",
"createIfNotExists": false,
"partitionKey": "/key",
"connectionStringSetting": "CosmosDBConnectionExp",
"direction": "out"
}
]
}
我的功能如下:
const PushDataChanges = async (context) => {
var cosmosOutput = context.bindings.DocumentOutput;
var cosmosInput = context.bindings.DocumentInput;
cosmosOutput = cosmosInput;
for(var i = 0; i < cosmosOutput.length; i++) {
var document = cosmosOutput[i];
var docid = cosmosOutput[i].id;
var now = new Date().toISOString();
document.id = docid; //Making sure the id key is same so upsert or update happens.
document.experiment.lastProcessedTime = "now";
document.experiment.updateStatus = "This is now updated";
}
context.done();
}
module.exports = function (context, Timer) {
context.log('Starting Delta Data Extraction and Sentiment Analysis');
PushDataChanges(context);
};
任何帮助将不胜感激。
【问题讨论】:
-
你不应该把
await换成PushDataChanges(context);吗? -
这不相关!!!添加 await 并不能解决我的问题!它可以捕获错误。我原来的问题仍然存在......请提供任何帮助
标签: javascript azure azure-functions azure-cosmosdb azure-cosmosdb-sqlapi