3
votes

I have an Azure DocumentDB collection that I'm writing time-stamped documents to via an Event Hub triggered function. The timestamp that I'm writing to the document (my_timestamp) originates from the function that processes the event, and I've confirmed that it is accurate.

The problem that I'm encountering is that the _ts metadata timestamp that's created by DocumentDB itself is showing a unix timestamp value that's a number of seconds previous to the timestamp I'm creating, i.e., it's actually applying a timestamp that's earlier than the beginning of the function execution that creates the document...

It appears that this may be a quirk in the underlying DocumentDB mechanics.

Anyway, I wanted to see if anyone else is encountering this discrepancy. Here are the timestamps as they appear in my document:

"my_timestamp": 1499301915, // here's my timestamp that originates from the Azure Function
"_ts":          1499301899  // and here's the timestamp created by DocDB?

And the code used to derive my_timestamp in the Azure Function:

var timeStamp = + Math.floor(new Date().getTime() / 1000);
1
Can you also share the function code so we can see how my_timestamp is calculated? - Jesse Carter

1 Answers

3
votes

AFAIK, The _ts field is a unix-style epoch timestamp representing the date and time and it would be updated every time when a document is modified.

Anyway, I wanted to see if anyone else is encountering this discrepancy.

According to your description, I checked this issue and I encountered the same issue for some times. But when I check this issue today, I could not reproduce this issue, Here is my code for testing:

Javascript

var doc={
    timestamp:Math.floor(new Date().getTime() / 1000)
    };

context.bindings.outputDocument = doc;

setTimeout( function() { 
    context.res={
        status:200,
        body:JSON.stringify(doc)
    };
    context.done();
}, 10*1000);

Query result via Query Explorer from azure portal:

enter image description here

Also, I have checked with azure function C# template and DocumentDB client SDK for adding new document. If this issue persists on your side, I assumed that you could add your feedback here.