Skip to content

MongoDb: Add index used when querying for all events for an aggregate type #65

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

Merged

Conversation

HCanber
Copy link
Contributor

@HCanber HCanber commented Apr 6, 2016

Reason
The index is needed when using this api call:

store.getEvents({aggregate:'my-aggregate', skip, limit, cb)

(the values of skip and limit don't matter)

The query above is handled by this call to mongodb client:

this.events.find(findStatement, { sort: [
   ['commitStamp', 'asc'],
   ['streamRevision', 'asc'],
   ['commitSequence', 'asc']] }).toArray(function (err, res) {

https://github.com/adrai/node-eventstore/blob/v1.7.3/lib/databases/mongodb.js#L327

Without the index, MongoDb has to sort in memory, which works fine for few events, but with enough events you'll hit the ceiling and get an error, like this:

Plan executor error during find: Overflow sort stage buffered data usage of 33554808 bytes exceeds internal limit of 33554432 bytes

Reason:
The index is needed when using this api call:

    store.getEvents({aggregate:'my-aggregate', skip, limit, cb)

(the values of skip and limit don't matter)

The query above is handled by this call to mongodb client:

     this.events.find(findStatement, { sort: [
       ['commitStamp', 'asc'],
       ['streamRevision', 'asc'],
       ['commitSequence', 'asc']] }).toArray(function (err, res) {

https://github.com/adrai/node-eventstore/blob/v1.7.3/lib/databases/mongodb.js#L327

Without the index, MongoDb has to sort in memory, which works fine for
few events, but with enough events you'll hit the ceiling and get this
error:

> Plan executor error during find: Overflow sort stage buffered data
> usage of 33554808 bytes exceeds internal limit of 33554432 bytes
@adrai adrai merged commit 51eaf71 into thenativeweb:master Apr 6, 2016
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

Successfully merging this pull request may close these issues.

2 participants