Recently I saw a question posted asking if DocumentDB supported Notifications for modified resources.

I have worked with BizTalk for many years and this is a common scenario using the WCF LOB Adapters SDK.

I have added Notifications to my To Do list.

I have started a new project to demonstrate how you can Poll for modified documents in DocumentDB.  

First I am going to explain how to do it and then in a follow-up post or two,  I will show how it is done.

To start off with, I am going to create a new Document and name it “PollingController”.

The PollingController  document source is:

{
  "id" : "string",
  "isController" : "TRUE",
    "PollingStatus" :
    {
      "DocId" : "string",
      "timestamp" : "date_time",
      "status" : 
      [
        "new",
        "modified",
        "inprocess",
        "completed"

      ]
    }
}

This document is very similar to a table in SQL Server. The document will contain an array of “documents”,  described in the following table.

Item Description
DocId This is the ID of the new or modified document
timeStamp Date Time the document was created, modified, or picked up
status This is the status of the document as it is being Processed.

New = default

Modified = document has been modified

inprocess = the document is in the processing state

completed = the document has been processed.

Next I am going to create a new Trigger.

The .isController default value of true, is used to identify the PollingController Document from  the Trigger.

The Trigger would add a new “PollingStatus”  document to the array in the PollingController Document

Once I have the Trigger in place and tested, I will create a new API App using Swagger. There would be two operations to start off with

I could also add it to the DocumentDBRestAPI App I created.

One operation would be to query the “PollingStatus” document, looking for a Status = new or Status = modified.

If found,  I would Get the DocId value.  Since I don’t want to get these values more than once, I will need to change the Status = inprocess,  and update the timeStamp.

Since I need to run the Query Operation on a schedule, I will use a Logic App to handle this.

This should give you an idea of how the process will work.

Please check back for an update on the project.