Best practices for pouchDB / couchDB replication from a mobile app
Asked Answered
S

0

6

I am using pouchDB in my hybrid (Ionic) app to send and retrieve data from my Cloudant databases.

I have used continuous replication until now, but there are too many transactions and the server's bill is going up !

Can you help me rewrite my code with "best practices" to avoid this ?

Is it the best pratice to declare the remote url like this, or should I have a local copy of the database ?

As you can see, I am new to pouchDB/couchDB, and I don't understand how to manage replication correctly.

Thanks for your help!

.factory('usersDatabase', [
    'pouchDB',
    function (pouchDB) {
        'use strict';

        var usersDatabase = pouchDB('boaine_users'),
            remote = 'https://ididi:[email protected]/boaine_users',
            opts = {
                live: true,
                retry: true
            };
        usersDatabase.replicate.to(remote, opts);
        usersDatabase.replicate.from(remote, opts);

        return usersDatabase;
    }
])
Supinator answered 8/6, 2016 at 12:54 Comment(12)
@nlawson Hey, do you think you can help me here?Supinator
Looks like someone wants an answer badly :pAmadou
@Amadou yeah I need help on this, can you provide ?Supinator
Well, to help you, we would need more detailed information about your application. For what purpose is the database used? Does the application rely on "live information"? Could caching lower the amount of request?Rhyolite
Hey @AlexisCôté (are you french, your name sounds french ! like mine...) actually it's a user database. The user logs in my app then I need to store the user's information (email, name, age, and other parameter he inputs in the app). But in this instance of the app I don't need to be aware of all the DB, just to store the new user in the remote DB. I am not sure about caching, what do you have in mind ?Supinator
Yup, I'm french hehe The best solution according to what you described me, would be to use "filtered replication". Filtered replication would allow you to only replicate certain documents (the current user for example). At first, connect to your localDB. Then, add the new user to this database. Once the user is added, retrieve his id and do a continuous replication filtered on his id with the remote database. Sounds good for you ? :)Rhyolite
Waouw yes it sounds good ! Can you help me write some code ?Supinator
You're asking for a example or help on your project?Rhyolite
Yes an example... But if you're willing to help we can hire you to check this.Supinator
@Supinator Before taking too much time on your example, I would need more information. Does your application rely on "offline capabilities"? What are the documents that you will maintain ( only a document for the users, many documents linked to the users, etc) ? I thinking chatting would be a better way to give you the most appropriate answer.Rhyolite
Join me on this chat room chat.stackoverflow.com/rooms/118270/…Rhyolite
yes you are right. I am answering in the chat room !Supinator

© 2022 - 2024 — McMap. All rights reserved.