@@ -5,17 +5,17 @@ const dbUtils = require('./support/db');
5
5
const paging = require ( '../' ) ;
6
6
const driver = process . env . DRIVER ;
7
7
8
- let mongod ;
9
-
10
8
describe ( 'find' , ( ) => {
9
+ let mongod ;
10
+ let client ;
11
11
const t = { } ;
12
12
beforeAll ( async ( ) => {
13
13
mongod = dbUtils . start ( ) ;
14
- t . db = await dbUtils . db ( mongod , driver ) ;
14
+ ( { db : t . db , client } = await dbUtils . db ( mongod , driver ) ) ;
15
15
16
16
// Set up collections once for testing later.
17
17
await Promise . all ( [
18
- t . db . collection ( 'test_paging' ) . insert ( [
18
+ t . db . collection ( 'test_paging' ) . insertMany ( [
19
19
{
20
20
counter : 1 ,
21
21
} ,
@@ -46,7 +46,7 @@ describe('find', () => {
46
46
color : 'blue' ,
47
47
} ,
48
48
] ) ,
49
- t . db . collection ( 'test_duplicate_custom_fields' ) . insert ( [
49
+ t . db . collection ( 'test_duplicate_custom_fields' ) . insertMany ( [
50
50
{
51
51
_id : 6 ,
52
52
counter : 6 ,
@@ -78,7 +78,7 @@ describe('find', () => {
78
78
timestamp : 1477347772077 ,
79
79
} ,
80
80
] ) ,
81
- t . db . collection ( 'test_paging_custom_fields' ) . insert ( [
81
+ t . db . collection ( 'test_paging_custom_fields' ) . insertMany ( [
82
82
{
83
83
counter : 6 ,
84
84
timestamp : 1477347800603 ,
@@ -104,7 +104,7 @@ describe('find', () => {
104
104
timestamp : 1477347755654 ,
105
105
} ,
106
106
] ) ,
107
- t . db . collection ( 'test_paging_date' ) . insert ( [
107
+ t . db . collection ( 'test_paging_date' ) . insertMany ( [
108
108
{
109
109
counter : 2 ,
110
110
date : new Date ( 1477347763813 ) ,
@@ -122,7 +122,7 @@ describe('find', () => {
122
122
date : new Date ( 1477347755654 ) ,
123
123
} ,
124
124
] ) ,
125
- t . db . collection ( 'test_paging_date_in_object' ) . insert ( [
125
+ t . db . collection ( 'test_paging_date_in_object' ) . insertMany ( [
126
126
{
127
127
counter : 2 ,
128
128
start : { date : new Date ( 1477347763813 ) } ,
@@ -140,7 +140,7 @@ describe('find', () => {
140
140
start : { date : new Date ( 1477347755654 ) } ,
141
141
} ,
142
142
] ) ,
143
- t . db . collection ( 'test_paging_limits' ) . insert ( [
143
+ t . db . collection ( 'test_paging_limits' ) . insertMany ( [
144
144
{
145
145
counter : 6 ,
146
146
} ,
@@ -160,7 +160,7 @@ describe('find', () => {
160
160
counter : 1 ,
161
161
} ,
162
162
] ) ,
163
- t . db . collection ( 'test_sorting' ) . insert ( [
163
+ t . db . collection ( 'test_sorting' ) . insertMany ( [
164
164
{
165
165
name : 'Alpha' ,
166
166
} ,
@@ -180,7 +180,7 @@ describe('find', () => {
180
180
name : 'aleph' ,
181
181
} ,
182
182
] ) ,
183
- t . db . collection ( 'test_null_values' ) . insert (
183
+ t . db . collection ( 'test_null_values' ) . insertMany (
184
184
[
185
185
undefined ,
186
186
undefined ,
@@ -197,7 +197,10 @@ describe('find', () => {
197
197
] ) ;
198
198
} ) ;
199
199
200
- afterAll ( ( ) => mongod . stop ( ) ) ;
200
+ afterAll ( async ( ) => {
201
+ await ( client ? client . close ( ) : t . db . close ( ) ) ;
202
+ await mongod . stop ( ) ;
203
+ } ) ;
201
204
202
205
beforeEach ( ( ) => {
203
206
paging . config . COLLATION = undefined ;
@@ -520,7 +523,7 @@ describe('find', () => {
520
523
521
524
it ( 'uses the hint parameter' , async ( ) => {
522
525
const collection = t . db . collection ( 'test_paging' ) ;
523
- await t . db . collection ( 'test_paging' ) . ensureIndex ( { color : 1 } , { name : 'color_1' } ) ;
526
+ await t . db . collection ( 'test_paging' ) . createIndex ( { color : 1 } , { name : 'color_1' } ) ;
524
527
// First page.
525
528
const res = await paging . find ( collection , {
526
529
query : {
@@ -711,7 +714,7 @@ describe('find', () => {
711
714
712
715
describe ( 'when using strings as _ids' , ( ) => {
713
716
beforeEach ( async ( ) => {
714
- await t . db . collection ( 'test_paging_string_ids' ) . insert ( [
717
+ await t . db . collection ( 'test_paging_string_ids' ) . insertMany ( [
715
718
{
716
719
_id : new ObjectId ( ) . toString ( ) ,
717
720
counter : 1 ,
@@ -1073,7 +1076,7 @@ describe('find', () => {
1073
1076
const collection = t . db . collection ( 'test_paging_string_ids' ) ;
1074
1077
await t . db
1075
1078
. collection ( 'test_paging_string_ids' )
1076
- . ensureIndex ( { color : 1 } , { name : 'color_1' } ) ;
1079
+ . createIndex ( { color : 1 } , { name : 'color_1' } ) ;
1077
1080
// First page.
1078
1081
const res = await paging . find ( collection , {
1079
1082
query : {
0 commit comments