Hi Borrrden,
I have installed sync gateway and couchbase server. Its running in browser
for Eg : if i hit http://localhost:4984/dhaya/ am getting following as output
{“committed_update_seq”:1,“compact_running”:false,“db_name”:“dhaya”,“disk_format_version”:0,“instance_start_time”:1557294861780948,“purge_seq”:0,“state”:“Online”,“update_seq”:1}
Also am using following lines of code in android ,it’s showing above error .
// Get the database (and create it if it doesn’t exist).
DatabaseConfiguration config = new DatabaseConfiguration(getApplicationContext());
Database database = null;
try {
database = new Database(“dhaya”, config);
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
// Create a new document (i.e. a record) in the database.
MutableDocument mutableDoc = new MutableDocument()
.setFloat(“version”, 2.0F)
.setString(“type”, “SDK”);
// Save it to the database.
try {
database.save(mutableDoc);
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
// Update a document.
mutableDoc = database.getDocument(mutableDoc.getId()).toMutable();
mutableDoc.setString(“language”, “Java”);
try {
database.save(mutableDoc);
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
Document document = database.getDocument(mutableDoc.getId());
// Log the document ID (generated by the database) and properties
Log.i(TAG, "Document ID :: " + document.getId());
Log.i(TAG, "Learning " + document.getString(“language”));
// Create a query to fetch documents of type SDK.
Query query = QueryBuilder.select(SelectResult.all())
.from(DataSource.database(database))
.where(Expression.property(“type”).equalTo(Expression.string(“SDK”)));
ResultSet result = null;
try {
result = query.execute();
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
Log.i(TAG, "Number of rows :: " + result.allResults().size());
// Create replicators to push and pull changes to and from the cloud.
Endpoint targetEndpoint = null;
try {
targetEndpoint = new URLEndpoint(new URI(“ws://127.0.0.1:8091/dhaya”));
} catch (URISyntaxException e) {
e.printStackTrace();
}
ReplicatorConfiguration replConfig = new ReplicatorConfiguration(database, targetEndpoint);
replConfig.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PUSH_AND_PULL);
// Add authentication.
replConfig.setAuthenticator(new BasicAuthenticator(“dhaya”, “dhaya123”));
// Create replicator.
Replicator replicator = new Replicator(replConfig);
// Listen to replicator change events.
replicator.addChangeListener(new ReplicatorChangeListener() {
@Override
public void changed(ReplicatorChange change) {
if (change.getStatus().getError() != null)
Log.i(TAG, "Error code :: " + change.getStatus().getError().getCode());
}
});
// Start replication.
replicator.start();
}