graylog2-server
graylog2-server copied to clipboard
Add utility methods for MongoDB collections
Adds basic utility methods for interacting with MongoDB collections to ease the transition to the new API.
Functionality added by this PR for:
- Pagination
- Extracting inserted IDs from a MongoDB
InsertOneResult
- Getting/Deleting documents by ID
- Streaming documents from a
FindIterable
- A
MongoEntity
interface that at the moment only enforces an_id
field of typeObjectId
but serves as a marker interface to be extended in the future.
I have deliberately not implemented #save(MongoEntity entity)
. IMO, a caller should explicitly call create or update operations, and in most cases, e.g., when called from a REST resource, we know which path to choose anyway.
If it turns out that #save(MongoEntity entity)
would be desirable, we could add that. E.g., by defining MongoEntity#withId(String id)
to return a copy of the entity with the given ID and use that in our implementation of #save(MongoEntity entity)
to construct the return value.
/prd https://github.com/Graylog2/graylog-plugin-enterprise/pull/7198 /nocl not user-facing
I think these utility methods are nice! I took a stab at rewriting TDIR's largest DB service using them and it was straightforward and (to me) cleaned things up a bit. Nice work!
@kingzacko1: awesome, thanks for checking it out!