Open gingobaum opened 5 years ago
Is it reproducable in a sample repo?
Here is one.
Using:
Running it for the first time works as expected. A second time ends up in mentioned error.
const eventStore = require('eventstore');
const customPublisher = function (event) {
console.log('customPublisher:', event);
};
const options = {
type: 'tingodb',
dbPath: './data',
eventsCollectionName: 'events',
snapshotsCollectionName: 'snapshots',
transactionsCollectionName: 'transactions'
};
const es = eventStore(options);
es.useEventPublisher(function (event) {
customPublisher(event);
});
const add = function (event) {
es.getEventStream(event.id, function (err, stream) {
if(err) {
console.error(err);
return;
}
stream.addEvent(event);
stream.commit( function (err) {
if(err) {
console.log(err);
return;
}
console.log('committed event: ', event);
});
});
};
es.init( function (err) {
if(err) {
console.log(err);
return;
}
const events = [];
const numbers = 2;
for(let i=0; i<numbers; i++) {
events.push({
id: String(i),
name: 'event ' + i
});
}
events.forEach(add);
});
And I just noticed, that in the case of running the script, increasing the number of events and running it again, will cause an error for the number of events saved before. Every additional will be added as usual.
It's all the same, if I dynamicly generate the ids of my events.
Can you try with v1.15.2 ?
It seems to work as expected with v1.15.2. Thank you very much.
Hi,
I wanted to use eventstore with tingodb, since it's the only why for using eventstore with the local filesystem.
When I start my app for the first time, everything works fine. But when I start it again, it does not commit and publish the events. It seems there is an error when committing.
Error: duplicate key error index
The options I pass to eventstore are:
When I delete the .tingo file and start again, it's all fine.
Any clues what is going wrong?