Closed shivam-880 closed 3 months ago
I think you are using it correctly and you found a bug. Please make a PR with a test case to reproduce the problem.
Found a work around for now!
The idea is to initialize the collection only if database creation on the couchdb instance passes. If it fails, that would mean the database was already created and already initialize.
console.log('DatabaseService: sync');
await Promise.all(
Object.values(db.collections).map(async (col) => {
try {
// create the CouchDB database
await fetch(
syncURL + col.name + '/',
{
method: 'PUT'
}
).then(response => {
if (!response.ok) {
throw new Error(`Failed to create database: ${response.status}`);
}
});
// Init contribution graphs
if (col.name === 'contribution_graph') {
const graphCollection = db.contribution_graph;
const graphDocuments = await graphCollection.find().exec();
if (graphDocuments.length == 0) {
await graphCollection.bulkInsert([
{ index: 1, activity: 'Study', streaks: [] },
{ index: 2, activity: 'Gym', streaks: [] },
]);
};
}
} catch (err) { }
})
);
This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon. If you still have a problem, make a PR with a test case or to prove that you have tried to fix the problem. Notice that only bugs in the rxdb premium plugins are ensured to be fixed by the maintainer. Everything else is expected to be fixed by the community, likely you must fix it by yourself.
Issues are autoclosed after some time. If you still have a problem, make a PR with a test case or to prove that you have tried to fix the problem.
I am trying to initialise the rxdb database with a seed data if not already found in the database.
Create Database This is pretty much straight out of documentation besides initialising the database with seed data.
Problem Statement When I try to start the app fresh i.e., when there is no collection in the database it all works just fine. The documents are created in the local storage and then replicated to the pouch db server. But it becomes issue if there are collections/documents already in the pouchdb server.
Steps To Reproduce
Start fresh with no collection in pouchdb server
Clear local storage in the app browser. This step allows to check the behaviour when the app is launched in a browser for the first time.
Refresh app page gives error:
The issue seems to be that rxdb local storage is getting initialised before it is synced with the pouchdb server!
How do we initialise the db instance?? Please suggest!