Reputation: 1475
I've created a react-native project with pouchDB set up. Have installed couchDB. Trying out the same in react native using "pouchdb-react-native". The replication is not happening. I'm getting the error 'message: "getCheckpoint rejected with", name: "unknown"'. Here is following code: import React, { Component, } from 'react';
import {
View,
Image,
StyleSheet,
Text
} from 'react-native';
import PouchDB from 'pouchdb-react-native'
const localDB = new PouchDB('todo');
const remoteDB = new PouchDB('http://username:[email protected]:5984/todo');
export default class Example extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
// Get records
localDB.allDocs({include_docs: true})
.then(results => {
results.rows.map(row => {
console.log(row.doc);
})
}).catch(err => alert('Err in fetching all records'));
localDB.sync(remoteDB,
function(err, response) {
if (err) {
return console.log(err);
} else {
console.log(response);
}
});
localDB.changes({
live: true,
include_docs: true
}).on('change', () => {
console.log("Event changed in localDB");
this.getAllRecords();
})
.on('complete', () => {
console.log("Event complete in localDB");
this.getAllRecords();
})
.on('error', () => alert("Error"))
}
render() {
return (
<View style={styles.container}>
<Text>Example screen</Text>
</View>
);
}
}
Please help on this. The package.json looks something like this:
"pouchdb": "^6.3.4",
"pouchdb-react-native": "^6.3.4",
"react": "16.0.0-alpha.12",
"react-native": "0.47.2",
What is wrong here? and how can this be debugged?
Also tried replacing the sync portion with below code:
const sync = localDB.sync(remoteDB, {
live: true,
retry: true,
direction: 'from'
});
sync
.on('change', pay_load => {
console.log(" changed!: ");
}).on('paused', info => {
console.log("paused");
}).on('denied', info => {
console.log("paused");
}).on('complete', info => {
console.log("paused");
}).on('active', info => {
console.log("Active");
}).on('error', err => {
console.log("error", err);
}).catch( err => {
console.log("Error: ",err)
});
sync goes only into "paused" state.
Upvotes: 1
Views: 450
Reputation: 755
I get this same error when I disconnect from the internet. Everything works fine when I reconnect. Maybe troubleshoot your connection ? I am using react native. Also, you may not need pouchdb in your package.json. I just have pouchdb-react-native which drags in the correct pouchDB.
Plus your url has 127.0.0.1 in it. I assume you just used that address to mask the real address or does that address suppose to correspond with a couchDB server you have running on your dev machine. You may need to change that address to the actual address of your couchDB server such as 192.168.1.whatever. I think 127.0.0.1 on your device or simulator will look for a server on the device or simulator not on your dev machine. Hope this helps.
Warren Bell
Upvotes: 1