Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using tingodb, no more events are published after restarting app #154

Open
gingobaum opened this issue Sep 30, 2019 · 4 comments
Open

Comments

@gingobaum
Copy link

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:

{
	"type": "tingodb",
	"dbPath": "./data/store",
	"eventsCollectionName": "events",
	"snapshotsCollectionName": "snapshots",
	"transactionsCollectionName": "transactions"
}

When I delete the .tingo file and start again, it's all fine.

Any clues what is going wrong?

@adrai
Copy link
Contributor

adrai commented Sep 30, 2019

Is it reproducable in a sample repo?

@gingobaum
Copy link
Author

Here is one.

Using:

  • tingodb: 0.6.1
  • eventstore: 1.15.1

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.

@adrai
Copy link
Contributor

adrai commented Oct 1, 2019

Can you try with v1.15.2 ?

@gingobaum
Copy link
Author

It seems to work as expected with v1.15.2.
Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants