@@ -168,12 +168,12 @@ function schemaAPITypeToMongoFieldType(type) {
168
168
// '_metadata' is ignored for now
169
169
// Everything else is expected to be a userspace field.
170
170
class Schema {
171
- collection ;
171
+ _collection ;
172
172
data ;
173
173
perms ;
174
174
175
175
constructor ( collection ) {
176
- this . collection = collection ;
176
+ this . _collection = collection ;
177
177
178
178
// this.data[className][fieldName] tells you the type of that field
179
179
this . data = { } ;
@@ -184,8 +184,8 @@ class Schema {
184
184
reloadData ( ) {
185
185
this . data = { } ;
186
186
this . perms = { } ;
187
- return this . collection . find ( { } , { } ) . toArray ( ) . then ( mongoSchema => {
188
- for ( let obj of mongoSchema ) {
187
+ return this . _collection . find ( { } ) . then ( results => {
188
+ for ( let obj of results ) {
189
189
let className = null ;
190
190
let classData = { } ;
191
191
let permsData = null ;
@@ -231,7 +231,7 @@ class Schema {
231
231
return Promise . reject ( mongoObject ) ;
232
232
}
233
233
234
- return this . collection . insertOne ( mongoObject . result )
234
+ return this . _collection . insertOne ( mongoObject . result )
235
235
. then ( result => result . ops [ 0 ] )
236
236
. catch ( error => {
237
237
if ( error . code === 11000 ) { //Mongo's duplicate key error
@@ -268,7 +268,7 @@ class Schema {
268
268
'schema is frozen, cannot add: ' + className ) ;
269
269
}
270
270
// We don't have this class. Update the schema
271
- return this . collection . insert ( [ { _id : className } ] ) . then ( ( ) => {
271
+ return this . _collection . insertOne ( { _id : className } ) . then ( ( ) => {
272
272
// The schema update succeeded. Reload the schema
273
273
return this . reloadData ( ) ;
274
274
} , ( ) => {
@@ -280,10 +280,9 @@ class Schema {
280
280
} ) . then ( ( ) => {
281
281
// Ensure that the schema now validates
282
282
return this . validateClassName ( className , true ) ;
283
- } , ( error ) => {
283
+ } , ( ) => {
284
284
// The schema still doesn't validate. Give up
285
- throw new Parse . Error ( Parse . Error . INVALID_JSON ,
286
- 'schema class name does not revalidate' ) ;
285
+ throw new Parse . Error ( Parse . Error . INVALID_JSON , 'schema class name does not revalidate' ) ;
287
286
} ) ;
288
287
}
289
288
@@ -296,7 +295,7 @@ class Schema {
296
295
}
297
296
} ;
298
297
update = { '$set' : update } ;
299
- return this . collection . findAndModify ( query , { } , update , { } ) . then ( ( ) => {
298
+ return this . _collection . updateOne ( query , update ) . then ( ( ) => {
300
299
// The update succeeded. Reload the schema
301
300
return this . reloadData ( ) ;
302
301
} ) ;
@@ -354,12 +353,12 @@ class Schema {
354
353
// We don't have this field. Update the schema.
355
354
// Note that we use the $exists guard and $set to avoid race
356
355
// conditions in the database. This is important!
357
- var query = { _id : className } ;
358
- query [ key ] = { '$exists' : false } ;
356
+ var query = { _id : className } ;
357
+ query [ key ] = { '$exists' : false } ;
359
358
var update = { } ;
360
359
update [ key ] = type ;
361
360
update = { '$set' : update } ;
362
- return this . collection . findAndModify ( query , { } , update , { } ) . then ( ( ) => {
361
+ return this . _collection . upsertOne ( query , update ) . then ( ( ) => {
363
362
// The update succeeded. Reload the schema
364
363
return this . reloadData ( ) ;
365
364
} , ( ) => {
@@ -422,14 +421,14 @@ class Schema {
422
421
423
422
// for non-relations, remove all the data.
424
423
// This is necessary to ensure that the data is still gone if they add the same field.
425
- return database . collection ( className )
424
+ return database . adaptiveCollection ( className )
426
425
. then ( collection => {
427
- var mongoFieldName = this . data [ className ] [ fieldName ] . startsWith ( '*' ) ? ' _p_' + fieldName : fieldName ;
428
- return collection . update ( { } , { "$unset" : { [ mongoFieldName ] : null } } , { multi : true } ) ;
426
+ let mongoFieldName = this . data [ className ] [ fieldName ] . startsWith ( '*' ) ? ` _p_${ fieldName } ` : fieldName ;
427
+ return collection . updateMany ( { } , { "$unset" : { [ mongoFieldName ] : null } } ) ;
429
428
} ) ;
430
429
} )
431
430
// Save the _SCHEMA object
432
- . then ( ( ) => this . collection . update ( { _id : className } , { $unset : { [ fieldName ] : null } } ) ) ;
431
+ . then ( ( ) => this . _collection . updateOne ( { _id : className } , { $unset : { [ fieldName ] : null } } ) ) ;
433
432
} ) ;
434
433
}
435
434
0 commit comments