Answer the question
In order to leave comments, you need to log in
How to use PouchDB in mobile projects?
At first glance, this technology seemed very cool to me - the records themselves can be synchronized between the client and the server, while there is no Internet, the data is buffered and when the network appears, it merges into the central database and vice versa.
But imagine that you are working with calendar data, which each user has their own and they are secure, i.e. on idea PouchDB will do a copy of all data on all clients?! Yes, you can apply filtering to replication, but it's the same on the client!
Is it possible to filter a replica (server -> client) for a specific user outside of the client?
Answer the question
In order to leave comments, you need to log in
Judging by the documentation, only the ad-hoc filter function is created on the client.
I myself have not used PouchDB / CouchDB in this way, but it seems to me that it is possible to build a filtering that will be based on user authorization. In this case, you will have to create a user in CouchDB, for each user of your application.
https://pouchdb.com/2015/04/05/filtered-replicatio...
Also, the same documentation suggests a way with a separate database for each client, if that suits you.
You should also beware trying to use filtered replication to enforce security, eg to partition a database per user. A better strategy is the “one database per user” method.
1. You can filter what the server returns with a design document:
remoteDb = new PouchDB('http://remote.com/db')
remoteDb.put({
"_id": "_desing/my_filter_doc_name",
"filters": {
"my_filter_name": "function(doc, req) { return doc.user_id === req.query.user_id }"
}
})
localDb = new PouchDB('local_db')
localDb.replicate.from(remoteDb, {
filter: "my_filter_doc_name/my_filter_name",
query_params: {
user_id: "xxx"
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question