-
Notifications
You must be signed in to change notification settings - Fork 0
Operations Group
OperationsGroup<M> is the main way you interact with your models in MongoHelper. It groups CRUD and related operations for a specific model class M.
Simplified definition:
public class OperationsGroup<M> {
public MongoCollection<M> getCollection();
public CountOperationsImpl<M> count();
public CreateOperationsImpl<M> create();
public DeleteOperationsImpl<M> delete();
public FindOperationsImpl<M> find();
public UpdateOperationsImpl<M> update();
public UpsertOperationsImpl<M> upsert();
}You do not construct OperationsGroup directly. Instead, once a schematic is registered, you call:
OperationsGroup<Post> posts = mongoHelper.get(Post.class);MongoHelper mongoHelper = MongoHelper.create(client);
// after registering the schematic that contains Post
OperationsGroup<Post> posts = mongoHelper.get(Post.class);If there is no OperationsGroup for a given class, an exception will be thrown indicating that no operations group is found for that class.
Note: The exact methods on
CreateOperationsImpl,FindOperationsImpl, etc. depend on your implementation. The examples below show typical usage patterns.
Post newPost = new Post();
// set fields...
posts.create()
// e.g. .one(newPost) or .many(List.of(newPost1, newPost2))
;posts.find()
// e.g. .byId(id) or .where(filter)
;posts.update()
// e.g. .where(filter).set("title", "New Title")
;posts.delete()
// e.g. .where(filter).one() or .many()
;long count = posts.count()
// e.g. .where(filter).execute()
;posts.upsert()
// e.g. .filter(filter).set("field", value).execute()
;If you need to drop down to the raw MongoDB driver API, you can access the underlying MongoCollection<M>:
MongoCollection<Post> collection = posts.getCollection();
collection.insertOne(newPost); // direct driver usageThis gives you full flexibility while still benefiting from MongoHelper's metadata and grouped operations.