loopbackio / loopback-connector-mongodb

The official MongoDB connector for the LoopBack framework.
https://loopback.io/doc/en/lb4/MongoDB-connector
Other
187 stars 236 forks source link

v7.0.0-alpha.1 - MongoInvalidArgumentError: Argument "options" must not be function #729

Open lien-dkseo opened 1 year ago

lien-dkseo commented 1 year ago

Steps to reproduce

const cursor = (await this.studyRepository.execute(
  'Study',
  'aggregate',
  [
    {
      $facet: {
        StudyCount: ...,
        SampleTypeCount: ...,
      },
    },
  ],
)) as AggregationCursor;

Current Behavior

MongoInvalidArgumentError: Argument "options" must not be function
    at Collection.aggregate (d:\dev\lien\samplebox-web-backend\node_modules\loopback-connector-mongodb\node_modules\mongodb\lib\collection.js:371:19)
    at d:\dev\lien\samplebox-web-backend\node_modules\loopback-connector-mongodb\lib\mongodb.js:602:38

Expected Behavior

working code in 6.2.0

Link to reproduction sandbox

Additional information

win32 x64 18.15.0

├── @loopback/authentication-jwt@0.12.9
├── @loopback/authentication@9.0.9
├── @loopback/authorization@0.12.9
├── @loopback/boot@5.0.9
├── @loopback/core@4.0.9
├── @loopback/repository@5.1.4
├── @loopback/rest-explorer@5.0.9
├── @loopback/rest@12.0.9
├── @loopback/service-proxy@5.0.9
├── loopback-connector-mongodb@7.0.0-alpha.1
├── mongodb@5.2.0

Related Issues

See Reporting Issues for more tips on writing good issues

achrinza commented 1 year ago

MongoDB v5 dropped support for the already-deprecated callback-style approach in favour of async/await: https://github.com/mongodb/node-mongodb-native/pull/3499

Offending line is the use of a callback for a Juggler observer:

https://github.com/loopbackio/loopback-connector-mongodb/blob/21a25fe8f42073c85784fe7e19f6272495a0fada/lib/mongodb.js#L600-L602

AFAIK, Juggler v4 already supports async/await. Hence this should be a straightforward fix.