How update collections using Azure functions


I want to create the azure Function which is bind to cosmos DB.

<ul><li>Whenever some insertion happens in "A" collection I want to update "B" collection.</li> <li>"B" collection has stored procedure which I want to call after the insertion in collection "A".</li> </ul>

I am new to Azure and cosmos-DB.

Suggest me what need to be done to accomplish the requirement.

So far I have created Azure Function <a href="https://i.stack.imgur.com/9OuyW.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/9OuyW.png" data-original="https://i.stack.imgur.com/9OuyW.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Also Updated the function.json with below code.

{ "bindings": [ { "type": "cosmosDBTrigger", "name": "input", "direction": "in", "leaseCollectionName": "leases", "connectionStringSetting": "cdb-swm-dev-001_DOCUMENTDB", "databaseName": "admin", "collectionName": "aomsorders", "createLeaseCollectionIfNotExists": true }, { "type": "documentDB", "name": "inputDocument", "databaseName": "admin", "collectionName": "aomsorders", "connection": "cdb-swm-dev-001_DOCUMENTDB", "direction": "in" }, { "type": "documentDB", "name": "outputDocument", "databaseName": "admin", "collectionName": "test", "createIfNotExists": true, "connection": "cdb-swm-dev-001_DOCUMENTDB", "direction": "out" } ], "disabled": false }

Also Updated the Integrate Part as below

<a href="https://i.stack.imgur.com/qDH8p.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/qDH8p.png" data-original="https://i.stack.imgur.com/qDH8p.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Any Suggestion will be appreciable.


I find your question not very specific, but broadly you have at least two options:


Insert to both collections from the same Azure Function

</li> <li>

Insert to the collection 1 from the first Azure Function, then have a second Azure Function with <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-documentdb" rel="nofollow">Cosmos DB trigger</a> listening to the changes of collection 1 and updating collection 2

</li> </ul>

I'm sure there are other options too.


Here is an example of an Azure Function that gets triggered by a CosmosDBTrigger and then it uses a DocumentDB Output Binding to write to a second collection:


{ "bindings": [ { "type": "cosmosDBTrigger", "name": "input", "direction": "in", "databaseName": "your-database", "collectionName": "your-collection1", "connectionStringSetting": "name-of-connectionstring-setting-for-collection1", "leaseCollectionName": "your-lease-collection" }, { "type": "documentDB", "direction": "out", "name": "docsToSave", "databaseName": "your-database2", "collectionName": "your-collection2", "connection": "name-of-connectionstring-setting-for-collection2", "createIfNotExists": false } ] }

<strong>run.csx (C#)</strong>

#r "Microsoft.Azure.Documents.Client" using Microsoft.Azure.Documents; using System.Collections.Generic; using System; public static async Task Run(IReadOnlyList<Document> input, IAsyncCollector<Document> docsToSave) { foreach(var doc in input){ // Do something here, process the document or do your compute // Here I am saving the same document to the second collection but you could send a new document created within the processing logic or send the same document modified by some logic await docsToSave.AddAsync(doc); } }

<strong>index.js (NodeJS)</strong>

module.exports = function(context, input) { if(!!input && input.length > 0){ context.bindings.docsToSave = []; for(var i = 0, len=input.length; i<len;i++){ var doc = input[i]; // Do something here with the doc or create a new one context.bindings.docsToSave.push(doc); } } context.done(); }


  • Azure Lake Store : missing Access-Control-Allow-Origin from response header
  • what is the supported Model for multi-level Document search?
  • Cosmos DB Newtonsoft Deserialization Issue
  • In Azure DocumentDB, how can I get a list of all properties in a collection?
  • Why Azure Documentdb creates index on each path by default
  • How can I perform an UPSERT using Azure DocumentDB?
  • Cosmos DB succeeds and fails on randomly on the same query, saying they are cross partition when the
  • JSON - slashes not escaping
  • php is_file always return false
  • Loading fixtures in sails tests
  • Removing Duplicate Geometries
  • How to assert that an input element is empty in Ruby on Rails tests
  • Is it possible to use arbitrary image sizes in caffe?
  • Unable to connect to OnVif enabled camera using C#
  • Use sed with regex and (
  • Correct implementation of List Iterator methods
  • Configure nginx to return different files to different authenticated users with the same URI
  • Time out Error in send mail
  • How to log in to an HTTPS website with Jsoup?
  • PDO error when wrong host name
  • Is there a way to dynamically embed PDF Files in a JSP pulled from the file system?
  • Switch to popup in python using selenium
  • Who propagate bugfixes across branches (corporate development)?
  • Web.config system.webserver errors
  • ADO and msqli connections very slow
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • Problems compiling files using JOGL
  • HTTP/2 streams vs HTTP/1.1 connections
  • Python urlparse: small issue
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • JSON with duplicate key names losing information when parsed
  • Jquery - Jquery Wysiwyg return html as a string
  • How to disable jQuery.jplayer autoplay?
  • How to stop GridView from loading again when I press back button?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?