Skip to content

Commit 24686ce

Browse files
committed
Added proper queryCount support
1 parent 3f4991d commit 24686ce

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

src/main/java/picoded/dstack/mongodb/MongoDB_DataObjectMap.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -441,18 +441,27 @@ public String[] query_id(Query queryClause, String orderByStr, int offset, int l
441441
return GenericConvert.toStringArray(ret);
442442
}
443443

444-
// /**
445-
// * Performs a search query, and returns the respective DataObjects
446-
// *
447-
// * @param where query statement
448-
// * @param where clause values array
449-
// *
450-
// * @returns The total count for the query
451-
// */
452-
// @Override
453-
// public long queryCount(String whereClause, Object[] whereValues) {
454-
// return queryBuilder.dataObjectMapCount(whereClause, whereValues, null, -1, -1);
455-
// }
444+
/**
445+
* Performs a search query, and returns the respective DataObjects
446+
*
447+
* @param where query statement
448+
* @param where clause values array
449+
*
450+
* @returns The total count for the query
451+
*/
452+
@Override
453+
public long queryCount(String whereClause, Object[] whereValues) {
454+
// return collection count, if there is no where clause
455+
if( whereClause == null ) {
456+
return collection.countDocuments();
457+
}
458+
459+
// The query filter to use, use "all" if queryClause is null
460+
Bson bsonFilter = queryObjToBsonFilter(Query.build(whereClause, whereValues));
461+
462+
// Perform the query and count
463+
return collection.countDocuments(bsonFilter);
464+
}
456465

457466
//--------------------------------------------------------------------------
458467
//

0 commit comments

Comments
 (0)