how replicate only the user's documents - couchdb

I need to sync some document from Cloudant server to my iOS in swift language.
For that I use this official library
https://github.com/cloudant/CDTDatastore#overview
I need to understand how replicate only user documents.
I need to figure out the correct road.
Imagine you a ticket assistance system of a company.
All users can create the ticket and this is save in cloudant/couchdb server.
When the user uses a mobile platform, I would just like to synchronize him ticket
how can I do it?
Thank all

CDTDatastore is designed to sync the whole database, and cloudant/ couchdb doesn't provide a per document ACL. In order to only sync a specific users data you either need to use a filter function, which will significantly hit the performance of the replication, or use the one database per user model.

Related

Partial syncing in pouchdb / couchdb with a particular scenario

I have been reading docs and articles on pouchdb/couchdb/cloudant. I am not able to create this simple architecture in my head. I need help!
So there are many users on the app. Each user has a separate database (which I read is the approach in pouch/couch/cloudant setup).
Now lets just focus on a single user. This user has some remote data already present on our server(couchdb). He has 3 separate docs stored.
He accesses docs 1 and docs 2 from browser 1. And docs 2 and docs 3 from browser 2.
Content in both the browsers must be in sync.
Should I be using Sync api of pouchdb? But as I read, it sync's the whole database. How can I use this api to sync only a subset of the central database. Is filtered replication answer here?
And also I don't want to push both the docs in a single call. He can access docs as he needs.
What is the correct approach to implement this logic with pouch/couch databases. If you can explain with a little code, that will be great. I just need basic ideas.
Is this kind of problem easily solvable in upcoming releases of CouchDB 2.0 and PouchDB-find.
Thanks a lot!
If you take a look at the PouchDB documentation, you should see the options.doc_ids. This parameter let you setup a replication on certain document ids. In your scenario, this would be solving your problem.

Limit records synchronized in PouchDB/CouchDB

I have a news base that needs to work online and offline. I'm using CouchDB (IBM Cloudant ) and PouchDB to make this sync with the APP.
The problem is that the news is relatively "heavy" for having photos and am having sync problems because the size of the "docs", and does not see any need to synchronize all the news base, will only fill the user's mobile phone with unnecessary records.
I need to sync only some news, approx. five registers. I wonder how can I do this in CouchDB or PouchDB.
I looked in sync + filters documentation but does not answer me the question of the amount of sync docs (or at least did not see if it is possible).
I'm using a view to pull the news.
Since you're using a view to pull the news, you can use limit to limit the number of documents you fetch. You can also use since to determine when you need to fetch the next batch of documents (this will have to be executed periodically to check for the existence of new documents)
If you go down this route and if your app doesn't need need client -> server replication then you could use something lighter than PouchDB do store the documents and other info on the client.
Yes you can, use filtered replication for this: https://pouchdb.com/api.html#filtered-replication
Credits: Nolan Lawson (PouchDB core team).

Per document user access control for PouchDB / CouchDB

I wish to use PouchDB - CouchDB for saving user data for my web application, but cannot find a way to control the access per user basis. My DB would simply consists of documents using user id as the key. I know there are some solutions:
One database per user - however it requires to monitor whenever a new user wants to save data in order to create a new DB, and may create a lot of DBs;
Proxy between client and CouchDB - however I don't want PouchDB to sync changes for the whole DB including documents of other users in those _all_docs, _revs_diff request.
Is there any suggestion for user access control for pouchDB for a user base of around 1 million (active users around 10 thousand only)?
The topic of a million or more databases has come up on the mailing list in the past. The conclusion was that it depends on how your operating system deals with that many files. CouchDB is just accessing parts of the .couch file when requested. Performance is related to how quickly it can find, open, access, and close that file.
There are tricks for some file systems like putting / delimiters in the database name--which will cause CouchDB to store them in matching directory structures such as groupA/userA.couch or using email-style database names com/bigbluehat/byoung.couch (or some similar).
If that's not sufficient, Apache CouchDB 2.0 brings in BigCouch code (which IBM Cloudant uses) to provide a fully auto-sharded CouchDB. It's not done yet, but it will provide scalability across multiple nodes using an Amazon Dynamo style sharding system.
Another option is to do your own username-based partitioning between multiple CouchDB servers or use IBM Cloudant (which is built for this level of scale).
All these options provide the same Apache CouchDB replication protocol and will work just fine with PouchDB sitting on the user's computer, phone, or tablet.
The user's device would then have their own database +/- any share databases. The apps on those million user devices would only have the scalability of their own content (aka hard drive space) to be concerned about. The app would replicate directly to the "cloud"-side user database for backup, web use, etc.
Hopefully something in there sounds promising. :)

NetSuite - do users and/or consultants/developers have access to the database?

I am new to Netsuite, and am wondering if there is ever the situation where either the user, or a 3rd party developer/consultant requires direct access to the backend database (where the application data is stored)?
Or is the database, hosted by NetSuite, hidden away from the user, and only accessible via a set of services in front on it?
I come from a background (of other ERP solutions) where consultants and users are quite used to working with the solution at database level (be it reporting off it, adding custom views, tables, stored procedures etc.), so I would like to understand how this works with NetSuite.
Questions are:
Does a user/consultant have direct read/write access to the
database?
Can a user/consultant make changes to the database in
terms of the schema?
Many thanks
For #1, the answer is No, you do not have direct access to DB. You can use the SuiteScript APIs/ SuiteTalk APIs to read/write from the Database.
For #2, You can extend Standard NetSuite Record Types (DB Schema Objects) by defining your own custom fields (Schema Object Attributes), you can also define an entire new custom record with its own custom fields. This can be done through the NetSuite's User Interface.
For #1:
You can sort of get DB access if you pony up for their ODBC access option. I think they call it SuiteAnalytics Connections now. I didn't find it particularly useful overall as it left me with even more questions than I started with.
For #1, the answer is No, you do not have direct access to DB.
You can use the SuiteScript APIs/ SuiteTalk APIs to read/write from the Database but it is very very inefficient,slow and very hard.
There are word limit for your code, it is really very in-effective

Restricting resource access in CouchDB to exactly 2 users

Currently I'm in the process of evaluating CouchDB for a new project.
Key constraint for this project is strong privacy. There need to be resources that are readable by exactly two users.
One usecase may be something similar to Direct Messages (DMs) on Twitter. Another usecase would be User / SuperUser access level.
I currently don't have any ideas about how to solve these kind of problems with CouchDB other than creating one Database that is accessable only by these 2 users. I wonder how I would then build views aggregating data from several databases?
Do you have any hints / suggestions for me?
I've asked this question several times on couchdb mailing lists, and never got an answer.
There are a number of things that couchdb is missing.
One of them is the document level security which would :
allow only certain users to view a doc
filter the documents indexed in a view on a user level permission base
I don't think that there is a solution to the permission considerations with the current couchdb implementation.
One solution would be to use an external indexing tool like lucene, and tag your documents with user rights, then issue a lucene query with user right definition in order to get the docs. It also implies extra load on your server(s) (lucene requires a JVM) and an extra delay for the data to be available (lucene indexing time ... )
As for the several databases solution, there are language framework implementations that simply don't allow to use more then one databases ( for instance couch_potato for Ruby ).
Having several databases also means that you'll have several replication processes if your databases are replicated.
Also, this means that the views will be updated for each of the database. In some cases this is better then have huge views indexed in a single database, but it also means that distinct users might not be up to date for a single source of information ( i.e some will have their views updated, other won't). So you cannot guarantee that the data is consistent for all users.
So unless something is implemented in the couch core in order to manage document level authorizations, CouchDB does not seem appropriate for managing data with privacy constraints.
There are a bunch of details missing about what you are trying to accomplish, what the data looks like, so it's hard to make a specific recommendation. You may be able to create a database per user and copy items into each users database (for the DM use case you described). Each user would only be able to access their own database, and then you could have an admin user that could access all databases. If you need to later update those records copying them to multiple databases might not be a good idea, and then you might consider whether you want to control permissions at a different level from storage.
For views that aggregate data from several databases, I recommend looking at lounge and bigcouch, which take different approaches.
http://tilgovi.github.com/couchdb-lounge/
http://support.cloudant.com/faqs/views/chained-mapreduce-views

Resources