@@ -38,75 +38,6 @@ describe('Ignore Undefined', function () {
38
38
}
39
39
} ) ;
40
40
41
- it ( 'Should correctly inherit ignore undefined field from collection during insert' , {
42
- metadata : { requires : { topology : [ 'single' ] } } ,
43
-
44
- test : function ( done ) {
45
- var configuration = this . configuration ;
46
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
47
- poolSize : 1 ,
48
- ignoreUndefined : false
49
- } ) ;
50
-
51
- client . connect ( function ( err , client ) {
52
- var db = client . db ( configuration . db ) ;
53
- var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue' , {
54
- ignoreUndefined : true
55
- } ) ;
56
-
57
- // Ignore the undefined field
58
- collection . insert ( { a : 1 , b : undefined } , configuration . writeConcernMax ( ) , function ( err ) {
59
- expect ( err ) . to . not . exist ;
60
-
61
- // Locate the doument
62
- collection . findOne ( function ( err , item ) {
63
- test . equal ( 1 , item . a ) ;
64
- test . ok ( item . b === undefined ) ;
65
- client . close ( done ) ;
66
- } ) ;
67
- } ) ;
68
- } ) ;
69
- }
70
- } ) ;
71
-
72
- it ( 'Should correctly inherit ignore undefined field from operation during findOneAndReplace' , {
73
- metadata : { requires : { topology : [ 'single' ] } } ,
74
-
75
- test : function ( done ) {
76
- var configuration = this . configuration ;
77
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
78
- poolSize : 1 ,
79
- ignoreUndefined : false
80
- } ) ;
81
-
82
- client . connect ( function ( err , client ) {
83
- var db = client . db ( configuration . db ) ;
84
- var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue' ) ;
85
-
86
- collection . insert ( { a : 1 , b : 2 } , configuration . writeConcernMax ( ) , function ( err ) {
87
- expect ( err ) . to . not . exist ;
88
-
89
- // Replace the doument, ignoring undefined fields
90
- collection . findOneAndReplace (
91
- { } ,
92
- { a : 1 , b : undefined } ,
93
- { ignoreUndefined : true } ,
94
- function ( err ) {
95
- expect ( err ) . to . not . exist ;
96
-
97
- // Locate the doument
98
- collection . findOne ( function ( err , item ) {
99
- test . equal ( 1 , item . a ) ;
100
- test . ok ( item . b === undefined ) ;
101
- client . close ( done ) ;
102
- } ) ;
103
- }
104
- ) ;
105
- } ) ;
106
- } ) ;
107
- }
108
- } ) ;
109
-
110
41
it (
111
42
'Should correctly connect using MongoClient and perform insert document ignoring undefined field' ,
112
43
{
@@ -217,4 +148,164 @@ describe('Ignore Undefined', function () {
217
148
} ) ;
218
149
}
219
150
} ) ;
151
+
152
+ it ( 'Should correctly inherit ignore undefined field from db during insert' , {
153
+ metadata : { requires : { topology : [ 'single' ] } } ,
154
+
155
+ test : function ( done ) {
156
+ var configuration = this . configuration ;
157
+ var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
158
+ poolSize : 1 ,
159
+ ignoreUndefined : false
160
+ } ) ;
161
+
162
+ client . connect ( function ( err , client ) {
163
+ var db = client . db ( configuration . db , { ignoreUndefined : true } ) ;
164
+ var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue3' ) ;
165
+
166
+ // Ignore the undefined field
167
+ collection . insert ( { a : 1 , b : undefined } , configuration . writeConcernMax ( ) , function ( err ) {
168
+ expect ( err ) . to . not . exist ;
169
+
170
+ // Locate the doument
171
+ collection . findOne ( function ( err , item ) {
172
+ test . equal ( 1 , item . a ) ;
173
+ test . ok ( item . b === undefined ) ;
174
+ client . close ( done ) ;
175
+ } ) ;
176
+ } ) ;
177
+ } ) ;
178
+ }
179
+ } ) ;
180
+
181
+ it ( 'Should correctly inherit ignore undefined field from collection during insert' , {
182
+ metadata : { requires : { topology : [ 'single' ] } } ,
183
+
184
+ test : function ( done ) {
185
+ var configuration = this . configuration ;
186
+ var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
187
+ poolSize : 1
188
+ } ) ;
189
+
190
+ client . connect ( function ( err , client ) {
191
+ var db = client . db ( configuration . db , { ignoreUndefined : false } ) ;
192
+ var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue4' , {
193
+ ignoreUndefined : true
194
+ } ) ;
195
+
196
+ // Ignore the undefined field
197
+ collection . insert ( { a : 1 , b : undefined } , configuration . writeConcernMax ( ) , function ( err ) {
198
+ expect ( err ) . to . not . exist ;
199
+
200
+ // Locate the doument
201
+ collection . findOne ( function ( err , item ) {
202
+ test . equal ( 1 , item . a ) ;
203
+ test . ok ( item . b === undefined ) ;
204
+ client . close ( done ) ;
205
+ } ) ;
206
+ } ) ;
207
+ } ) ;
208
+ }
209
+ } ) ;
210
+
211
+ it ( 'Should correctly inherit ignore undefined field from operation during insert' , {
212
+ metadata : { requires : { topology : [ 'single' ] } } ,
213
+
214
+ test : function ( done ) {
215
+ var configuration = this . configuration ;
216
+ var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
217
+ poolSize : 1
218
+ } ) ;
219
+
220
+ client . connect ( function ( err , client ) {
221
+ var db = client . db ( configuration . db ) ;
222
+ var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue5' , {
223
+ ignoreUndefined : false
224
+ } ) ;
225
+
226
+ // Ignore the undefined field
227
+ collection . insert ( { a : 1 , b : undefined } , { ignoreUndefined : true } , function ( err ) {
228
+ expect ( err ) . to . not . exist ;
229
+
230
+ // Locate the doument
231
+ collection . findOne ( { } , function ( err , item ) {
232
+ expect ( err ) . to . not . exist ;
233
+ test . equal ( 1 , item . a ) ;
234
+ test . ok ( item . b === undefined ) ;
235
+ client . close ( done ) ;
236
+ } ) ;
237
+ } ) ;
238
+ } ) ;
239
+ }
240
+ } ) ;
241
+
242
+ it ( 'Should correctly inherit ignore undefined field from operation during findOneAndReplace' , {
243
+ metadata : { requires : { topology : [ 'single' ] } } ,
244
+
245
+ test : function ( done ) {
246
+ var configuration = this . configuration ;
247
+ var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
248
+ poolSize : 1 ,
249
+ ignoreUndefined : false
250
+ } ) ;
251
+
252
+ client . connect ( function ( err , client ) {
253
+ var db = client . db ( configuration . db ) ;
254
+ var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue6' ) ;
255
+
256
+ collection . insert ( { a : 1 , b : 2 } , configuration . writeConcernMax ( ) , function ( err ) {
257
+ expect ( err ) . to . not . exist ;
258
+
259
+ // Replace the doument, ignoring undefined fields
260
+ collection . findOneAndReplace (
261
+ { } ,
262
+ { a : 1 , b : undefined } ,
263
+ { ignoreUndefined : true } ,
264
+ function ( err ) {
265
+ expect ( err ) . to . not . exist ;
266
+
267
+ // Locate the doument
268
+ collection . findOne ( function ( err , item ) {
269
+ test . equal ( 1 , item . a ) ;
270
+ test . ok ( item . b === undefined ) ;
271
+ client . close ( done ) ;
272
+ } ) ;
273
+ }
274
+ ) ;
275
+ } ) ;
276
+ } ) ;
277
+ }
278
+ } ) ;
279
+
280
+ it ( 'Should correctly ignore undefined field during bulk write' , {
281
+ metadata : { requires : { topology : [ 'single' ] } } ,
282
+
283
+ test : function ( done ) {
284
+ var configuration = this . configuration ;
285
+ var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
286
+ poolSize : 1
287
+ } ) ;
288
+
289
+ client . connect ( function ( err , client ) {
290
+ var db = client . db ( configuration . db ) ;
291
+ var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue7' ) ;
292
+
293
+ // Ignore the undefined field
294
+ collection . bulkWrite (
295
+ [ { insertOne : { a : 0 , b : undefined } } ] ,
296
+ { ignoreUndefined : true } ,
297
+ function ( err ) {
298
+ expect ( err ) . to . not . exist ;
299
+
300
+ // Locate the doument
301
+ collection . findOne ( function ( err , item ) {
302
+ test . equal ( 0 , item . a ) ;
303
+ test . ok ( item . b === undefined ) ;
304
+ client . close ( done ) ;
305
+ } ) ;
306
+ }
307
+ ) ;
308
+ } ) ;
309
+ }
310
+ } ) ;
220
311
} ) ;
0 commit comments