Global timestamp on all new documents (and Sync Server)

Hi Everyone

I’m faily new to this world of NoSQL, so maybe the question is not logical.

I looking for a database for a new IOT project. The project will contain a (distributed) database, collecting data from gateways all over the world. The data just someting like:

“gw”: “09854352254”,
“sid”: “68237428735”,
“v”: 21.2

Now I would like the document enriched with a global timestamp, so that the gateway does not have to stamp it with it’s own local time (thats maybe out of sync) and - well - local.

So my question is: Is it possible to have Couchbase to add a global timestamp to every created document automatcally.
In any SQL server, this is (almost) just a checkbox on a field.

Also - if I use “Sync Server” (and the .Net client), would it be possible to get the correct timestamp if the client is offline to a while?

I need this timestamp when selecting the documents again if I want to show a time graph of the data. Or is there a better way, then using NoSQL?

Since you mention ‘offline’ and SyncGateway (I believe you’re referring to that), that leads me to believe that the best approach here is to have that application add the timestamp locally. I know this comes with a time synchronization problem that you may need to resolve in whatever’s appropriate for your overall logic, but that seems to be the best way. One idea might be to reject at SyncGateway timestamps that seem implausible.

Beyond that, Couchbase does have a type of a logical clock for Timestamp Based Conflict Resolution (see the details on the Hybrid Logical Clock in there). I’m not sure that’s what you’re looking for here though. It sounds like you’re looking for creation time, versus mutation time? If these aren’t ever to be mutated, there is a virtual xattr that gives you the cluster node’s perception of when the item was last modified.

Also, note there are some projects* for bringing your own HLC to your distributed devices.

It may be better to think more about how you plan to use this and what constraints you can loosen. I know this is different than a traditional database where most everything is serialized, but that of course gives you advantages too.

* like and

1 Like

Thanks for the answer.

Giving this a little more thought, I might not need a super precise timestamp, as long as the individual gateway has the actual time ± a few seconds. The data analyse is per gateway anyway. Also - I might look into this “virtual xattr”…
What I’m looking at is the creation time as there will never ever be any updates on a document.