Hello team
wanted to inquire on the way to make changes and update data from the back end after it has been upload in the DB
Hi @cliff
Can you provide more details? I’m not sure I understand.
Are you asking about how you can edit documents after they have been synced to the server?
yes @diana sure ![]()
I’m not sure I understand
Can you please provide more details into what your desired outcome is?
@diana Sure i will …
we are getting wrong next appointment dates in the 2wT DB, which are eventually synced to the postgres DB and we would like to find a way to change these dates if possible
A common practice for this is to write a script using the CouchDB API to make the change directly in the data.
This is dangerous. You need to be very careful when doing this. Take a backup before you run the script and test your scripts outside production first.
Here is a script similar to what you might need:
import axios from 'axios';
const username = 'username';
const password = 'password';
const axiosInstance = axios.create({
baseURL: 'https://myinstance.echis.go.ke',
auth: {
username,
password
},
});
async function updateReportsWithType() {
const readResponse = await axiosInstance.get('/medic/_design/medic-client/_view/reports_by_form', {
params: {
keys: JSON.stringify([
['form_name1'],
['form_name2']
]),
include_docs: true,
reduce: false
}
});
const docs = readResponse.data.rows.map((row: any) => row.doc);
docs.forEach(doc => {
doc.fields.make_a = 'change';
});
await axiosInstance.post('/medic/_bulk_docs', {
docs: docs,
});
}
updateReportsWithType();
Run via npx ts-node script.ts
sorry for the late response @kenn,
thanks for this