Can we read time_Saved property through couchbase.netClient API?

Is there any way to read time_saved property from document through .net SDK or equivalent?

@abhi.chouksey -

What do you mean by “time_saved”? Do you mean when the document was created?



Please see below an example of _sync section of document

_sync: {
rev: “2-9914edd516d36fd6996ff5ce4f3f474fa3c60da0”,
sequence: 109939,
recent_sequences: [
history: {
revs: [
parents: [
channels: [
channels: {
xxxxxx: null
cas: “0x000041815f8b4215”,
time_saved: “2018-07-18T14:54:25.5178102-04:00”

@abhi.chouksey looks like a sync gateway question? @borrrden should be able to help.


I know it can be read from sync function.I was wondering if it can be read through couchbase .net SDK. We do have some process which process documents(mostly like housekeeping stuff).

@abhi.chouksey -

You should be able to by directly fetching the document if timed_save is part of the document’s content or perhaps fetch from XATTR using the SDK. I don’t know enough about sync gateway to conclusively say for sure; perhaps @brett19 knows?


That’s private Sync Gateway metadata so of course you should be able to read it since it is just there in the document, or with mobile convergence and Server 5.0+ I think you can read the XATTR data but since this is private metadata I don’t think you can rely on it always being the same across releases, etc. @adamf will have the authoritative answer.

Since it’s Open Source and it’s visible, it’d be great if there were a list of what is intended private is in documentation. Is there such a thing by chance @adamf or @borrrden?

1 Like

run something like

SELECT id, meta(sample-bucket) as docid from sample-bucket

this is what it returns

“docid”: {
“cas”: 1528988505913688064,
“expiration”: 0,
“flags”: 33554433,
“id”: “xxxxxxxxx”,
“type”: “json”

it does not have time_saved property in first place. i doubt if it can be read.

Sync Gateway’s information is stored in an xattr. In Couchbase Server 5.0, N1QL does not query into xattrs. Starting in Couchbase Server 5.5, that is possible. It’s also possible with the SDK directly.

Though it’s possible, it may not be advisable. There are parts of the system that are intended as private interface, as they may change at any time without notice. That’s why I’d asked that question above. In my opinion, with Open Source, it’s almost more important to have an interface stability definition, since it’s all visible at some level or another.

Frequently these are documented and for the SDKs (which is where most of the programming surface area is exposed) we specifically outline the terms and taxonomy. Some other components do as well, but not all.

I got the point; however, How do i know when document was last updated by any means?

Let me put this problem in perspective.

In our system which has one centralized database(i.e. RDBMS -SQL database). This database gets data from various sources, some sources or all source could send same data with different variation. which means our data is in constant update mode.

Sub set of centralized database “Data” goes into our Couchbase database periodically again is being used for our offline mobile app (read and write both by mobile system).

In order for us to make some business decisions, It is important for us to know when data was updated in couchbase, that was whole purpose of reading the last “time_saved” property from the document.

Is there any other way to know when the document was updated last?

For some reason i have restriction not to put last modified date (as field in system).

Sync Gateway’s information is stored in an xattr 1. In Couchbase Server 5.0, N1QL does not query into xattrs. Starting in Couchbase Server 5.5, that is possible. It’s also possible with the SDK directly.

Would you please tell which function of Bucket or Doucument method I can get the xattr?

The large challenge here is that in a distributed system as you’d have with Couchbase Mobile, there can be subtle differences in date/time. If you’re building some business logic on top of this, you’ll want to consider that the time on the mobile device is not necessarily the same as the time on Sync Gateway. Since you mention “business decisions”, which could be as simple as an aggregation where the date/time need not be precise or something more complex where the order of operations is important, I’d just advise you think about which date/time is the one you’re considering.

In fact, much of the Couchbase Mobile platform is about providing a non-time based way to allow concurrent changes, identify the order of operations, and take the next steps based on your business logic.

Having said all of that, if you want to use this xattr knowing the challenges with using that date and interface, you can access it with the Sub-Document API, for which there is a section on the concepts and coverage in the .NET API reference (since you’re posting this in the .NET category).

Note that you may need to authenticate to your Couchbase cluster as a sufficiently privileged user to read this kind of system level xattr.

After carefully consideration, We are dropping the idea to read time_saved information. Instead we now maintain date and time and we also use changes feed for some tracking purpose.

Thank you @ingenthr for help.

Glad to help, let us know how it works out if you have any further questions.