-
Type: Bug
-
Resolution: Fixed
-
Priority: Critical - P2
-
Affects Version/s: 3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.3.4, 3.3.5, 3.4.0, 3.4.1
-
Component/s: None
-
Empty show more show less
I've just upgraded to version 3.3.0 from version 3.2.7 and receive the following exception:
TypeError: readPreference.equals is not a function
at executeWithServerSelection (<PATH_TO_SRC>/node_modules/mongodb/lib/operations/execute_operation.js:125:40)
at executeOperation (<PATH_TO_SRC>/node_modules/mongodb/lib/operations/execute_operation.js:92:16)
at AggregationCursor._initializeCursor (<PATH_TO_SRC>/node_modules/mongodb/lib/core/cursor.js:545:7)
at AggregationCursor._initializeCursor (<PATH_TO_SRC>/node_modules/mongodb/lib/cursor.js:191:11)
at nextFunction (<PATH_TO_SRC>/node_modules/mongodb/lib/core/cursor.js:748:10)
at AggregationCursor._next (<PATH_TO_SRC>/node_modules/mongodb/lib/core/cursor.js:202:5)
at fetchDocs (<PATH_TO_SRC>/node_modules/mongodb/lib/operations/to_array.js:27:14)
at ToArrayOperation.execute (<PATH_TO_SRC>/node_modules/mongodb/lib/operations/to_array.js:60:5)
at <PATH_TO_SRC>/node_modules/mongodb/lib/operations/execute_operation.js:109:26
at new Promise (<anonymous>)
The exception arises from using an aggregate function and calling .toArray() on the result:
unprocessedCompanyAggregate = await getCollection('company').aggregate([ { '$match': { '_id' : createIDForDatabase(companyID) } }, { '$project': { 'financialPeriod': { '$arrayElemAt': ['$financialPeriods', financialPeriodsIndex] } } }, { '$project': { 'statementsName': '$financialPeriod.statementsType.name' } } ],{ 'session': session }).toArray(); // toArray needed so converts the cursor for the aggregation to an array of documents.
The problem bit of mongodb code is in execute_operation.js:
const readPreference = operation.readPreference || ReadPreference.primary; const inTransaction = operation.session && operation.session.inTransaction(); if (inTransaction && !readPreference.equals(ReadPreference.primary)) { ... }
The only time this exception seems to occur is when operation.readPreference exists.
I'm using transactions, and the only time I'm setting readPreference is when starting a transaction:
session.startTransaction({ 'writeConcern': { 'w': WRITE_CONCERN_W_MAJORITY, 'j': WRITE_CONCERN_J_TRUE, 'wtimeout': WRITE_CONCERN_WTIMEOUT_1000, }, 'readConcern': { 'level': 'snapshot' }, 'readPreference': { 'mode': 'primary' } });
Where
const WRITE_CONCERN_W_MAJORITY = 'majority'; const WRITE_CONCERN_J_TRUE = true; const WRITE_CONCERN_WTIMEOUT_1000 = 1000;
Any ideas what is going on?