Skip to content

Commit e759550

Browse files
committed
feat: add count method based on a query to MongoDBDocumentManager
Implemented a new count method that allows counting documents based on a SelectQuery, enhancing query capabilities for MongoDB collections. Signed-off-by: Maximillian Arruda <[email protected]>
1 parent d6ea53d commit e759550

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/MongoDBDocumentManager.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,12 @@ public void delete(DeleteQuery query) {
149149
collection.deleteMany(mongoDBQuery);
150150
}
151151

152-
153152
@Override
154153
public Stream<CommunicationEntity> select(SelectQuery query) {
155154
Objects.requireNonNull(query, "query is required");
156155
String collectionName = query.name();
157156
MongoCollection<Document> collection = mongoDatabase.getCollection(collectionName);
158157
Bson mongoDBQuery = query.condition().map(DocumentQueryConversor::convert).orElse(EMPTY);
159-
160158
FindIterable<Document> documents = collection.find(mongoDBQuery);
161159
documents.projection(Projections.include(query.columns()));
162160

@@ -177,6 +175,14 @@ public Stream<CommunicationEntity> select(SelectQuery query) {
177175

178176
}
179177

178+
@Override
179+
public long count(SelectQuery query) {
180+
Objects.requireNonNull(query, "query is required");
181+
String collectionName = query.name();
182+
Bson mongoDBQuery = query.condition().map(DocumentQueryConversor::convert).orElse(EMPTY);
183+
return count(collectionName, mongoDBQuery);
184+
}
185+
180186
@Override
181187
public long count(String documentCollection) {
182188
Objects.requireNonNull(documentCollection, "documentCollection is required");
@@ -214,7 +220,7 @@ public long delete(String collectionName, Bson filter) {
214220
* Aggregates documents according to the specified aggregation pipeline.
215221
*
216222
* @param collectionName the collection name
217-
* @param pipeline the aggregation pipeline
223+
* @param pipeline the aggregation pipeline
218224
* @return the stream of BSON Documents
219225
* @throws NullPointerException when filter or collectionName is null
220226
*/
@@ -230,7 +236,7 @@ public Stream<Map<String, BsonValue>> aggregate(String collectionName, Bson... p
230236
* Aggregates documents according to the specified aggregation pipeline.
231237
*
232238
* @param collectionName the collection name
233-
* @param pipeline the aggregation pipeline
239+
* @param pipeline the aggregation pipeline
234240
* @return the stream result
235241
* @throws NullPointerException when pipeline or collectionName is null
236242
*/

0 commit comments

Comments
 (0)