I've built an Android app based on Couchbase Lite which talks to a Couchbase Database via Sync Gateway. I've now tried to get Couchbase Lite to replicate with a CouchDB 2.0 database, but I am getting the following error:
W/RemoteRequest: com.couchbase.lite.replicator.RemoteRequest {POST,
http://192.168.1.5:5984/_revs_diff}: Got error status: 404 for
http://192.168.1.5:5984/_revs_diff. Reason: Object Not Found
W/Sync: PusherInternal{http://192.168.1.5:5984, push, 12ff9}: Progress:
set error =com.couchbase.lite.replicator.RemoteRequestResponseException:
Object Not Found
Note that for this I am not going through Sync Gateway but rather point Couchbase Lite directly to the CouchDB Url.
I don't know whether I need to go through Sync Gateway or not, but my impression after reading the Couchbase docs on Couchbase lite is that I do not when connecting to a CouchDb database and this post seems to back that up. https://github.com/couchbase/sync_gateway/issues/312
Can someone please confirm whether it is possible for couchbase lite to replicate directly with a CouchDb 2.0 database and if so what is the correct way to set it up?
Also, the app will be used by many sites, a site can be made up of one or more users. The reason I was thinking switching to CouchDb is so that I can have one database per site, something which doesn't seem to be easily doable in Couchbase. However, I have now discovered Channels in Couchbase which allow me to use one database but keep access to documents restricted by site (i.e. a site could have many users and all users should have access to all documents for that site).
What would be the pros and cons of using either separate databases in CouchDb or channels in Couchbase?
Thanks.
As #Hod said different buckets is equivalent to different databases in Couch DB so you can go for that.
Secondly it is definitely encouraged to use sync_gateway's channels property if you can because creating single bucket is preferred over multiple buckets and I have used sync_gateway with couch Lite and Couch server, it works perfectly fine and also with accuracy so I think you should go with sync_gateway and channels instead of creating multiple buckets
A few points in response:
The main thing is I think you can do what you want easily in Couchbase. Buckets in Couchbase Server are somewhat equivalent to separate databases. So you could split your sites that way. Channels in Sync Gateway give you more control for separating data and controlling access, as you've seen.
Couchbase Lite should be able to sync with CouchDB, but this isn't heavily tested. It's hard to tell from your snippet what's going wrong. You might check this post for some ideas: CouchDB: how to use _revs_diff to get document revision ID
Sync Gateway exposes a sort of superset of the CouchDB replication endpoints, so you'll have more flexibility using Couchbase Lite with Sync Gateway.
Related
I want Couchbase to first temporary store the data, and then automatically sync it with Server. How do I achieve this ?
For example, In note-making app, I add a note and Couchbase should automatically add it to the Server.
You're in luck! The requirement you've described is exactly how Couchbase Mobile works.
Couchbase Mobile is comprised of two parts:
Couchbase Lite: A stand-alone embedded database that you can use directly within your mobile app.
Sync Gateway: a synchronization mechanism that securely syncs data between mobile clients and server.
So, back to your question. In order to achieve what you're looking for you would first create an instance of your Couchbase Lite database. From there, as you would expect, you can perform basic CRUD operations, query data, etc. You can find more information on the built-in capabilities here:
iOS (Swift)
iOS (Obj-C)
Android (Java)
Xamarin (C#)
Once you've created an embedded database you can start replication (synchronization) on it by using the Sync Gateway integration that comes with the Couchbase.Lite and Couchbase.Lite.Enterprise SDK component for iOS, Android, or Xamarin.
I recommend checking out the following tutorials for using Couchbase Lite and Sync Gateway:
iOS: Data Sync Fundamentals
Android: Data Sync Fundamentals
Xamarin: Data Sync Fundamentals
You are looking for the Couchbase Sync Gateway: https://docs.couchbase.com/sync-gateway/2.1/index.html
How can I create an android app that uses a mongoDB database locally i.e. Clients can make CRUD operations without connecting to a server. Sort of how SQLite is used, except this time I wanna use mongoDB.
I have checked around and what seems to be my most suitable option is using mongodb java driver, but the problem is how and what am I connecting the mongoClient to? Do I have to sort of start a server or something?
I would suggest using firebase or realm or something that comes with better native mobile support. Couchbase Mobile might be of interest too, but I have not used it. https://developer.couchbase.com/mobile
It's possible to connect an Android application directly to a Couchbase server database?.
It's possible to get a Document from Couchbase's bucket and use it from an Android application?.
Thank you.
tl;dr: Use Sync Gateway.
Couchbase Sync Gateway is designed to be a web edge service that you use to access data. In the most typical scenario Sync Gateway connects to a back end Couchbase Server cluster.
You could in theory use one of the client libraries to access Couchbase Server directly. You really don't want to do this for several reasons.
The client libraries have different expectations around network latency and availability.
They don't currently (as of Couchbase Mobile 1.4) support the meta data needed for syncing.
You'd need to expose your server which raises your security risk profile
The system architecture has all this in mind, which is why it's designed the way it is.
I have the following usecase:
I want to use Couchbase on a server to store data, and use Couchbase for Android on mobile devices. I would like to use the Couchbase synchronisation to be able to work online and offline with the data and have it synced up eventually. But I don't want the different clients to sync all the data onto the device, just a specific subset. What subset a client should sync, should be controlled by the client, and should be changed dynamically.
Is Couchbase able to handle such a scenario? And if, could you give me some hints to the matching documentations.
Couchbase can not do this. More importantly I can't think of any solution that would. Couchbase is a clustered nosql solution. Others are caching solutions or databases. They store data. The logic of syncing the data between different stores and the syncing of sub-sets of data would have to be done within your application.
Sync Gateway now handles the logic permitting users access to channels, which then contain subsets of data based on which channel(s) each document belongs to.
http://docs.couchbase.com/sync-gateway/#channels
Solely looking at it from a mobile database point of view which is going to synchronize with a remote server,assuming it doesn't really matter if it is relational db or NoSQL,
what would be the better option to go along with?
Client platform is android
My vote would be for CouchDB.. The reason being, as NoSQL, it has good number of advantages. More than anything, you can make the user's data available offline.
Just in case you want further info on usage of CouchDB, I would like to request/suggest you to go through this, this and this.
I want to point out that Oracle Database Mobile Server also makes the data available offline, that's what it's designed to do. In addition to syncing your mobile database, it also offers device mgmt. For more info:
http://www.oracle.com/technetwork/products/database-mobile-server/overview/index.html
I've not used the Couchbase solution, but I do know some of the team over there, and they seem like very smart people.
What it comes down to: if you want/need an Oracle backend, then you should use Oracle Database Mobile Server. If you want to experiment with NoSQL, then Couchbase would be the way to go.
Eric Jensen,
Oracle PM