@@ -790,57 +790,6 @@ mongoc_collection_count_with_opts (
790
790
RETURN (ret );
791
791
}
792
792
793
- /* --------------------------------------------------------------------------
794
- *
795
- * _make_aggregate_for_edc --
796
- *
797
- * Construct an aggregate pipeline with the following form:
798
- *
799
- *
800
- * { pipeline: [
801
- * { $collStats: { count: {} } },
802
- * { $group: { _id: 1, n: { $sum: $count } } },
803
- * ]
804
- * }
805
- *
806
- *--------------------------------------------------------------------------
807
- */
808
- static void
809
- _make_aggregate_for_edc (const mongoc_collection_t * coll , bson_t * out )
810
- {
811
- bson_t pipeline ;
812
- bson_t coll_stats_stage ;
813
- bson_t coll_stats_stage_doc ;
814
- bson_t group_stage ;
815
- bson_t group_stage_doc ;
816
- bson_t sum ;
817
- bson_t cursor_empty ;
818
- bson_t empty ;
819
-
820
- BSON_APPEND_UTF8 (out , "aggregate" , coll -> collection );
821
- BSON_APPEND_DOCUMENT_BEGIN (out , "cursor" , & cursor_empty );
822
- bson_append_document_end (out , & cursor_empty );
823
- BSON_APPEND_ARRAY_BEGIN (out , "pipeline" , & pipeline );
824
-
825
- BSON_APPEND_DOCUMENT_BEGIN (& pipeline , "0" , & coll_stats_stage );
826
- BSON_APPEND_DOCUMENT_BEGIN (
827
- & coll_stats_stage , "$collStats" , & coll_stats_stage_doc );
828
- BSON_APPEND_DOCUMENT_BEGIN (& coll_stats_stage_doc , "count" , & empty );
829
- bson_append_document_end (& coll_stats_stage_doc , & empty );
830
- bson_append_document_end (& coll_stats_stage , & coll_stats_stage_doc );
831
- bson_append_document_end (& pipeline , & coll_stats_stage );
832
-
833
- BSON_APPEND_DOCUMENT_BEGIN (& pipeline , "1" , & group_stage );
834
- BSON_APPEND_DOCUMENT_BEGIN (& group_stage , "$group" , & group_stage_doc );
835
- BSON_APPEND_INT32 (& group_stage_doc , "_id" , 1 );
836
- BSON_APPEND_DOCUMENT_BEGIN (& group_stage_doc , "n" , & sum );
837
- BSON_APPEND_UTF8 (& sum , "$sum" , "$count" );
838
- bson_append_document_end (& group_stage_doc , & sum );
839
- bson_append_document_end (& group_stage , & group_stage_doc );
840
- bson_append_document_end (& pipeline , & group_stage );
841
- bson_append_array_end (out , & pipeline );
842
- }
843
-
844
793
int64_t
845
794
mongoc_collection_estimated_document_count (
846
795
mongoc_collection_t * coll ,
@@ -878,48 +827,23 @@ mongoc_collection_estimated_document_count (
878
827
}
879
828
880
829
reply_ptr = reply ? reply : & reply_local ;
881
- if (server_stream -> sd -> max_wire_version < WIRE_VERSION_4_9 ) {
882
- /* On < 4.9, use actual count command for estimatedDocumentCount */
883
- BSON_APPEND_UTF8 (& cmd , "count" , coll -> collection );
884
- ret = _mongoc_client_command_with_opts (coll -> client ,
885
- coll -> db ,
886
- & cmd ,
887
- MONGOC_CMD_READ ,
888
- opts ,
889
- MONGOC_QUERY_NONE ,
890
- read_prefs ,
891
- coll -> read_prefs ,
892
- coll -> read_concern ,
893
- coll -> write_concern ,
894
- reply_ptr ,
895
- error );
896
- if (ret ) {
897
- if (bson_iter_init_find (& iter , reply_ptr , "n" )) {
898
- count = bson_iter_as_int64 (& iter );
899
- }
900
- }
901
- } else {
902
- /* On >= 4.9, use aggregate with collStats for estimatedDocumentCount */
903
- _make_aggregate_for_edc (coll , & cmd );
904
- ret = mongoc_collection_read_command_with_opts (
905
- coll , & cmd , read_prefs , opts , reply_ptr , error );
906
-
907
- if (!ret && error -> code == MONGOC_ERROR_COLLECTION_DOES_NOT_EXIST ) {
908
- /* Collection does not exist. From spec: return 0 but no err:
909
- * https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#estimateddocumentcount
910
- */
911
- if (reply ) {
912
- bson_reinit (reply );
913
- }
914
- memset (error , 0 , sizeof * error );
915
- count = 0 ;
916
- GOTO (done );
917
- }
918
- if (ret && bson_iter_init (& iter , reply_ptr )) {
919
- if (bson_iter_find_descendant (
920
- & iter , "cursor.firstBatch.0.n" , & iter )) {
921
- count = bson_iter_as_int64 (& iter );
922
- }
830
+
831
+ BSON_APPEND_UTF8 (& cmd , "count" , coll -> collection );
832
+ ret = _mongoc_client_command_with_opts (coll -> client ,
833
+ coll -> db ,
834
+ & cmd ,
835
+ MONGOC_CMD_READ ,
836
+ opts ,
837
+ MONGOC_QUERY_NONE ,
838
+ read_prefs ,
839
+ coll -> read_prefs ,
840
+ coll -> read_concern ,
841
+ coll -> write_concern ,
842
+ reply_ptr ,
843
+ error );
844
+ if (ret ) {
845
+ if (bson_iter_init_find (& iter , reply_ptr , "n" )) {
846
+ count = bson_iter_as_int64 (& iter );
923
847
}
924
848
}
925
849
0 commit comments