@@ -39,6 +39,45 @@ describe_only_db('mongo')('Read preference option', () => {
39
39
} ) ;
40
40
} ) ;
41
41
42
+ it ( 'should preserve the read preference set (#4831)' , async ( ) => {
43
+ const { MongoStorageAdapter } = require ( '../src/Adapters/Storage/Mongo/MongoStorageAdapter' ) ;
44
+ const adapterOptions = {
45
+ uri : 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase' ,
46
+ mongoOptions : {
47
+ readPreference : ReadPreference . NEAREST ,
48
+ }
49
+ } ;
50
+ await reconfigureServer ( { databaseAdapter : new MongoStorageAdapter ( adapterOptions ) } ) ;
51
+
52
+ const databaseAdapter = ( Config . get ( Parse . applicationId ) ) . database . adapter ;
53
+
54
+ const obj0 = new Parse . Object ( 'MyObject' ) ;
55
+ obj0 . set ( 'boolKey' , false ) ;
56
+ const obj1 = new Parse . Object ( 'MyObject' ) ;
57
+ obj1 . set ( 'boolKey' , true ) ;
58
+
59
+ await Parse . Object . saveAll ( [ obj0 , obj1 ] )
60
+ spyOn ( databaseAdapter . database . serverConfig , 'cursor' ) . and . callThrough ( ) ;
61
+
62
+ const query = new Parse . Query ( 'MyObject' ) ;
63
+ query . equalTo ( 'boolKey' , false ) ;
64
+
65
+ const results = await query . find ( ) ;
66
+ expect ( results . length ) . toBe ( 1 ) ;
67
+ expect ( results [ 0 ] . get ( 'boolKey' ) ) . toBe ( false ) ;
68
+
69
+ let myObjectReadPreference = null ;
70
+ databaseAdapter . database . serverConfig . cursor . calls . all ( ) . forEach ( ( call ) => {
71
+ if ( call . args [ 0 ] . indexOf ( 'MyObject' ) >= 0 ) {
72
+ myObjectReadPreference = true ;
73
+ expect ( call . args [ 2 ] . readPreference . preference ) . toBe ( ReadPreference . NEAREST ) ;
74
+ }
75
+ } ) ;
76
+
77
+ expect ( myObjectReadPreference ) . toBe ( true ) ;
78
+ console . log ( 'OK!' ) ;
79
+ } ) ;
80
+
42
81
it ( 'should change read preference in the beforeFind trigger' , ( done ) => {
43
82
const databaseAdapter = ( Config . get ( Parse . applicationId ) ) . database . adapter ;
44
83
0 commit comments