@@ -3,6 +3,7 @@ var test = require('./shared').assert;
33var setupDatabase = require ( './shared' ) . setupDatabase ;
44var co = require ( 'co' ) ;
55var mock = require ( 'mongodb-mock-server' ) ;
6+ const expect = require ( 'chai' ) . expect ;
67
78var defaultFields = {
89 ismaster : true ,
@@ -1102,6 +1103,33 @@ describe('Collation', function() {
11021103 }
11031104 } ) ;
11041105
1106+ it ( 'cursor count method should return the correct number when used with collation set' , {
1107+ metadata : { requires : { mongodb : '>=3.4.0' } } ,
1108+ test : function ( done ) {
1109+ const configuration = this . configuration ;
1110+ const client = configuration . newClient ( { w : 1 } , { poolSize : 1 , auto_reconnect : false } ) ;
1111+
1112+ client . connect ( function ( err , client ) {
1113+ const db = client . db ( configuration . db ) ;
1114+ const docs = [ { _id : 0 , name : 'foo' } , { _id : 1 , name : 'Foo' } ] ;
1115+ const collation = { locale : 'en_US' , strength : 2 } ;
1116+ let collection , cursor ;
1117+ const close = e => cursor . close ( ( ) => client . close ( ( ) => done ( e ) ) ) ;
1118+
1119+ Promise . resolve ( )
1120+ . then ( ( ) => db . createCollection ( 'cursor_collation_count' ) )
1121+ . then ( ( ) => ( collection = db . collection ( 'cursor_collation_count' ) ) )
1122+ . then ( ( ) => collection . insertMany ( docs ) )
1123+ . then ( ( ) => collection . find ( { name : 'foo' } ) . collation ( collation ) )
1124+ . then ( _cursor => ( cursor = _cursor ) )
1125+ . then ( ( ) => cursor . count ( ) )
1126+ . then ( val => expect ( val ) . to . equal ( 2 ) )
1127+ . then ( ( ) => close ( ) )
1128+ . catch ( e => close ( e ) ) ;
1129+ } ) ;
1130+ }
1131+ } ) ;
1132+
11051133 /******************************************************************************
11061134 .___ __ __ .__
11071135 | | _____/ |_ ____ ________________ _/ |_|__| ____ ____
@@ -1125,7 +1153,13 @@ describe('Collation', function() {
11251153 var col = db . collection ( 'collation_test' ) ;
11261154 // Create collation index
11271155 col . createIndexes (
1128- [ { key : { a : 1 } , collation : { locale : 'nn' } , name : 'collation_test' } ] ,
1156+ [
1157+ {
1158+ key : { a : 1 } ,
1159+ collation : { locale : 'nn' } ,
1160+ name : 'collation_test'
1161+ }
1162+ ] ,
11291163 function ( err ) {
11301164 test . equal ( null , err ) ;
11311165
0 commit comments