Class CollectionQuery
java.lang.Object
com.github.darksoulq.abyssallib.common.database.nosql.mongodb.CollectionQuery
A fluent builder for executing CRUD operations on a single MongoDB collection.
-
Constructor Summary
ConstructorsConstructorDescriptionCollectionQuery(Database database, String collectionName) Constructs a new CollectionQuery. -
Method Summary
Modifier and TypeMethodDescriptionbatch()Transitions into a batch operation for bulk writes.longcount()Counts documents matching the filter.delete()Sets operation type to DELETE.longexecute()Executes the configured operation synchronously.Executes the configured operation asynchronously.booleanexists()Checks if any documents match the filter.Adds a filter criterion.filter(org.bson.Document doc) Adds multiple filter criteria.<R> Rfirst(DocumentMapper<R> mapper) Retrieves the first matching document and maps it.insert()Sets operation type to INSERT.limit(int limit) Sets the result limit.replace()Sets operation type to REPLACE.<R> List<R> select(DocumentMapper<R> mapper) Retrieves all matching documents and maps them to a list.<R> CompletableFuture<List<R>> selectAsync(DocumentMapper<R> mapper) Retrieves all matching documents asynchronously.skip(int skip) Sets the result skip count.Sets the sort order.update()Sets operation type to UPDATE.upsert(boolean upsert) Sets the upsert flag.Adds a key-value pair to the write payload.values(org.bson.Document doc) Adds all fields from a document to the write payload.
-
Constructor Details
-
CollectionQuery
-
-
Method Details
-
insert
Sets operation type to INSERT. @return this. -
replace
Sets operation type to REPLACE. @return this. -
update
Sets operation type to UPDATE. @return this. -
delete
Sets operation type to DELETE. @return this. -
value
Adds a key-value pair to the write payload. @return this. -
values
Adds all fields from a document to the write payload. @return this. -
filter
Adds a filter criterion. @return this. -
filter
Adds multiple filter criteria. @return this. -
sort
Sets the sort order.- Parameters:
key- The field to sort by.ascending- True for 1, false for -1.- Returns:
- this.
-
limit
Sets the result limit. @return this. -
skip
Sets the result skip count. @return this. -
upsert
Sets the upsert flag. @return this. -
batch
Transitions into a batch operation for bulk writes.- Returns:
- A new
BatchQueryinstance.
-
execute
public long execute()Executes the configured operation synchronously.- Returns:
- The count of affected documents.
-
executeAsync
Executes the configured operation asynchronously.- Returns:
- A future containing the affected document count.
-
count
public long count()Counts documents matching the filter.- Returns:
- Total count.
-
exists
public boolean exists()Checks if any documents match the filter.- Returns:
- True if count > 0.
-
first
Retrieves the first matching document and maps it.- Type Parameters:
R- Result type.- Parameters:
mapper- The mapper logic.- Returns:
- The mapped object or null.
-
select
Retrieves all matching documents and maps them to a list.- Type Parameters:
R- Result type.- Parameters:
mapper- The mapper logic.- Returns:
- A list of mapped results.
-
selectAsync
Retrieves all matching documents asynchronously.- Type Parameters:
R- Result type.- Parameters:
mapper- The mapper logic.- Returns:
- A future containing the result list.
-