I am using pouchdb at client side(ionic mobile app) couchdb at server side.
I need to perform operation after pouchdb successfully created and sync with couchdb.
so how can I wait till pouchdb complete initial activity.then after only my client side execution should start.
currently pouch is working on asynchronous manner so sometime before pouch initialize my application starts execution and I am getting error for pouchdb.
When working with asynchronous functions such as waiting for a respone from a server in JavaScript you use promises or callbacks to wait for an answer.
from the pouchdb docs we can read that they provide a fully asynchronous API.
Callback version:
db.get('mittens', function (error, doc) {
if (error) {
// oh noes! we got an error
} else {
// okay, doc contains our document
}
});
Promise version:
db.get('mittens').then(function (doc) {
// okay, doc contains our document
}).catch(function (err) {
// oh noes! we got an error
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With