Sync 1 objet and only 1 for each client on mobile application

Here a simple mobile application : each user give personal informations store in a json object.
The application return to the client only hers informations and this json.
On their mobile, for privacy and security, there is only theirs informations in couchbase-lite, so only 1 json.

How to implement that with sync ?

It’s mostly a server-side configuration: you’d want to define a channel for each user (probably named after their user ID for simplicity). Then you could have a sync function that maps a document to a channel based on its docID, so for example document “userInfo-jens” maps to channel “jens”, so I and only I have access to it.

Then on the client side you simply create/update the document with that ID and store whatever you want onto it.

Thanks for the reply.

I don"t see how to create automatism for create a channel for each user ID. When I look the sync documentation, i found this:

Here users of couchbase is not my list of users, which can be thousands of users.
The connection to sync is limited by the configuration.
And my users don’t connect to Couchbase but to the mobile application.

How the fonction sync knows the application users, not the couchbase users, who ask for a document ?
I don’t see anywhere a clear answer or a example with android application.

Please help me

How the fonction sync knows the application users, not the couchbase users, who ask for a document ?

There’s no way server can do access control of documents if it doesn’t know who’s accessing those documents. If you don’t want these user documents to be effectively public, you will need to have individual user accounts on Sync Gateway.

So it’s exactly what I understood without believe it !
After several years working with couchbase, I am very disappointed !!

What kind of mobile application this conception can offer a personnal experience for each user ??
Take GMAIL for example, how can that work with couchbase-lite and sync ?

I had read a sample of chat application ? So it’s works for only 2 users or with everyone in one chat ???

I think the documentation is not properly done since this information it is not write in capital !!

I’m really think to stop with couchbase at all !

I think you’re misunderstanding what I wrote. I’m not sure why you’re angry…

If you want access control of documents, then each user of the app needs to have a user account on Sync Gateway. How can the server know whether a client has access to a document, if it doesn’t know what user that client is?

I had read a sample of chat application ? So it’s works for only 2 users or with everyone in one chat ???

No, every user of the chat app needs to have an account and authenticate with it when replicating. Your server-side code would create these SG accounts during user registration.

No need to repeat yourself, I clearly understand the behavior of sync and that’s not what I imagined how it’s work.

How can you conceive an application whith thousands of users, with a lots of data and assets like pictures, documents store in the database, and all of this have to synchronise in all users mobiles ?

How can the server know …

What I need is clearly that the fonction sync is to be more intelligent, and can execute rich requests for each mobile !
Take example in the real world, Pokemon Go, if you want to work offline with couchbase-lite and sync, does the mobile have to store all data of everyone ?
Maybe that can take form as a specific program of synchronisation write by the developpers team. I don’t have a solution for this mistake in the conception.

Couchbase can manage terabytes of json documents, how can that work with couchbase-lite on mobile ?

So, the list of type of application that can run with sync is very few ! And again, what I read in the main page of couchbase never talk about this very very big limitation !

So tell me that sync will evolve in the good way and I can wait for the new version, or don’t, and I’m looking for an another technology with a great disappointment and a lot of annoyance because I worked a lot on my application and everything must be changed.

Is it possible to have a french contact ? Like mrs Cécile Le Pape ?

It is absolutely possible to achieve what you describe (large numbers of users, small sets of documents per-user replicated to devices)

Couchbase Lite can connect to Sync Gateway using individual user accounts logged into the app, and those user accounts can have access to a restricted set of documents based on channels.

That user might not have access to any channels initially, but they can be granted dynamically via the sync function:

  • You can grant users access to channels dynamically in the sync function using access(username, channelname)
  • You can assign documents to channels dynamically using channel(channelname)

Using both of these, you’re able to write a sync function that handles channel assignments for documents and users without having to specify these for all of your users via the REST API or in the config file, which seems to be your concern.

You can find more information in the documentation at these links:

I read all the documentation, and nothing help me to understand how I can make it work. :weary:
You already said that the server cannot know the user of the application !!! :face_with_monocle:

The function look like

function (doc, oldDoc) {

access(username, channelname)


:weary: So username don’t come from the call and not from the application, but from the authentification to connect to sync !
Do I have to have a specific authentification for each users of the application ? :rage:
Once again, there is something wrong about the documentations where users of couchbase is not users of the mobile application !

And I read that doc must contains doc.members, so any members, like new member have to be in the list to read the doc !

I want a complete sample that show how everything work with :
. a database
. a unique authentification to connect to the database ( to sync )
. multiple users in 4 categories : admin, shop, buyers
. A list of products, and orders
Grant :
. admin can access to all
. shop : create an account, create products, access to their commands
. product : read by buyers, complete access from shop owner
. buyers : access to product, and create orders
. orders : create by one buyers, for one shop
The process : someone open the application, fill a form, and chose to be a shop or a buyer.
If it’s a shop, he can create product, he can’t see products and orders from other shop, neither buyers
If it’s a buyer, he can create order, he can see only products and his own orders

This is an example that is almost my project, and you can see that the rules of synchronisation have to be very intelligent. The user of the application do not have authentification in couchbase server, he can’t have “role” so he can’t be affect to a channel… :roll_eyes:

Show me a real project that show me that working, and I will be happy :grinning:.

Yes, this is entirely where your problem lies. The buyer needs to be a registered mobile user in order to have authorization to documents that aren’t public!
It may be that your backend creates those users on the fly via Sync Gateway’s REST API when they place an order.

There are plenty of example and real-world apps using Couchbase Mobile that do not have this problem.
I’m sorry they don’t meet the exact requirements of your own shop project.

I did not say that. I said “There’s no way server can do access control of documents if it doesn’t know who’s accessing those documents.” Explaining why you would need to set up user accounts on the server to get access control. Perhaps it would have been clearer to say “… unless it knows who’s accessing those documents.”

I understand that you’re not a native English speaker, and there’s a language barrier between us. That’s fine. But it means you should avoid getting angry about your (mis)interpretation of something I said. Instead, if it seems surprising, how about stating it in your own words and asking us to confirm?

Obviously that would involve significant work. Our sales department can talk with you about a quote for helping you out with such a proof of concept.

1 Like

After reading again and again betweens lines, I think I succeed to put pieces together and I see how that work . I will do tests with that …

Thanks for all your replies.