我是 Azure 新手,我正在尝试使用 Azure 函数来触发 NodeJS, 我已经在 Azure Cosmos 上拥有一个 NoSQL 数据库。 示例:
{
...
"shop":{
"fruits":[
"orange",
"strawberry",
"lemon"
],
"clothes":[
"man",
"woman",
"babies"
]
}
...
}
然后我想将一个名为apple的新水果添加到fruits数组中,或者从衣服中删除babies>。还将man更新为men, 我能怎么做 ? 我找到了context.bindings。但我还不知道怎么用 有人可以帮助我吗?
非常感谢。
最佳答案
这是一个示例函数,它递增文档的 num
字段。
function.json
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "HttpTriggerJSUpdateDocument/{docid}"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "documentDB",
"name": "inputDocument",
"databaseName": "MyDB",
"collectionName": "MyCollection",
"id": "{docid}",
"connection": "mydocdb_DOCUMENTDB",
"direction": "in"
},
{
"type": "documentDB",
"name": "outputDocument",
"databaseName": "MyDB",
"collectionName": "MyCollection",
"createIfNotExists": false,
"connection": "mydocdb_DOCUMENTDB",
"direction": "out"
}
],
"disabled": false
}
index.js
:
module.exports = function (context, req) {
let inputDocument = context.bindings.inputDocument;
context.log('JavaScript HTTP trigger, current value: ' +
(inputDocument && inputDocument.num));
inputDocument.num = inputDocument.num + 1;
context.bindings.outputDocument = inputDocument;
context.res = {
body: 'Result is ' + inputDocument.num
};
context.done();
};
关于javascript - 如何使用 Azure 函数和 HTTP 触发器 POST 更新 Cosmos Azure (NOSQL) 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44951972/