We already have two CRUD API implementations, and may soon add a third, that proxy to instances of ReadOperation/WriteOperation or AsyncReadOperation/AsyncWriteOperation. Two problem that causes:
- There is duplicated code in the two implementations (for example, in converting from WriteModel to WriteRequest)
- There is unnecessary exposure to the concrete implementations of the operation interfaces (e.g. FindOperation, MixedBulkWriteOperation)
Address this technical debt by:
- Creating in core a SyncOperations and an AsyncOperations class, whose methods take the same parameters as the CRUD API but return instances, respectively of ReadOperation/WriteOperation and AsyncReadOperation/AsyncWriteOperation. These are both implemented in terms of a package-private Operations class that has the same methods, but which return instances of the concrete operation types. SyncOperations and AsyncOperations are in com.mongodb.internal currently, so are not considered part of the public API.
- Re-implementing the sync and async CRUD API (MongoCollection and MongoIterable subclasses) in terms of SyncOperations (for the sync API) and AsyncOperations (for the async API).