.net Web Application connecting to couchbase server via sync gateway

How to connect Asp.net application to couchbase serever via Sync Gateway…

@ishan.mehta065 -

You cannot connect with sync-gateway, however you can use the Couchbase .NET SDK which is designed for server side applications: https://developer.couchbase.com/documentation/server/4.5/sdk/dotnet/releases.html

-Jeff

can we use sync gateway’s builtin rest api in our web page???

I have a mobile application that uses sync gateway how can i connect my .net application to use and update same data…

As mentioned above, you should be able to use the server-side .NET SDK pull your documents using K/V, N1QL or Views - this is the recommended API to use with ASP.NET. There is also Linq2Couchbase if you want to use Linq for your N1QL queries.

When i’m using .net sdk data store in this format:
{
“name”: “Ishan”,
“phone”: “1234568”
}

but when i’m inserting data through mobile application using sync gateway it comes in this format:
{
“_sync”: {
“rev”: “2-be92ed9b2180c23d6b0deb4f3003555f”,
“sequence”: 41,
“recent_sequences”: [
7,
41
],
“history”: {
“revs”: [
“1-7aff67a7a40cd3981be0de9100d3eda9”,
“2-be92ed9b2180c23d6b0deb4f3003555f”
],
“parents”: [
-1,
0
],
“channels”: [
null,
null
]
},
“time_saved”: “2017-01-12T15:35:10.7889511+05:30”
},
“text”: “hi i am available for itc”
}

in this only text key-pair is inserted by app rest of all is inserted by the sync gateway…
now how to manage all this data through server side code because when i’m inserting data through .net sdk it is not visible in android application…
i’m inserting snapshot of both formats…
i want my data to be visible in android app also…

@ishan.mehta065 -

All of that additional information is meta-data added by the mobile SDK/sync gateway. One suggestion would be to use N1QL or Linq2Couchbase (which uses N1QL) to only select the data you need and ignore the rest of the metadata. Additionally, you would not want to modify any of the metadata because its state needed by sync gateway to behave correctly.

Perhaps @borrrden can provide some additional insight.

The only insight I can provide is that in order for mobile apps to be aware of the data, all requests need to go through sync gateway (including the ones that are going through the .NET SDK now).

Yes. DO NOT use Couchbase Server SDKs to write to the bucket owned by Sync Gateway. Only use the Sync Gateway REST API.

(This will get better in the future, but currently, when docs get written without Sync Gateway’s knowledge it can’t maintain its metadata and things get messed up.)

Also, ignore the _sync property in documents in that bucket. It’s metadata used by Sync Gateway. (Again, in the future we hope to hid this metadata in a less obvious place in the bucket, when such places are available.)

then how to connect .net web application through sync gateway???
i’m not getting it…

Sorry @ishan.mehta065 not trying to confuse you, but you cannot connect via sync gateway to an ASP.NET application. The best you can do is use the server side Couchbase .NET SDK to read data and/or the Sync Gateway REST API to write (I am not sure if it provides read access) to the application.

I’ve a problem updating the data from my web application , how to insert that metadata through .net SDK ,which is added by sync gateway…

@ishan.mehta065 Use the Admin Rest API (Couchbase Capella for Mobile Developers)
It will add the metadata itself. Alternatively use Couchbase Server 5.0 and Couchbase Mobile 1.5 and later with shared bucket access enabled - then you can use the Couchbase .net SDK to directly with the shared bucket on Couchbase Server.