devconcept / multer-gridfs-storage

🍃 GridFS storage engine for Multer to store uploaded files directly to MongoDb
MIT License
237 stars 67 forks source link

DeprecationWarning from MongoClient #503

Closed bailor1 closed 2 years ago

bailor1 commented 2 years ago

Describe the bug When used with MongoDB v5, the following deprecation warning is displayed due to the usage of isConnected() within multer-gridfs-storage:

(node:19016) DeprecationWarning: isConnected is deprecated and will be removed in the next major version

Environment

To Reproduce Simply create a new GridFsStorage in node. I traced the depreciation from the new GridFsStorage() call (not including parameters because they're irrelevant to the deprecation):

    at GridFsStorage._updateConnectionStatus (myapp/node_modules/multer-gridfs-storage/lib/gridfs.js:407:33)
    at GridFsStorage._setDb (myapp/node_modules/multer-gridfs-storage/lib/gridfs.js:446:14)
    at GridFsStorage._connect (myapp/node_modules/multer-gridfs-storage/lib/gridfs.js:335:18)
    at new GridFsStorage (myapp/node_modules/multer-gridfs-storage/lib/gridfs.js:91:14)
    at singleFileUpload (myapp/api/src/routes/file.js:46:21)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

The warning occurs because of the isConnected() call in the following screenshot: Screenshot from 2022-08-10 14-57-33

The warning is thrown within myapp/node_modules/mongodb/lib/mongo_client.js: Screenshot from 2022-08-10 14-59-34

Expected behavior Not showing the warning/the package no longer being deprecated

bailor1 commented 2 years ago

Perhaps this Mongo documentation about moving away from isConnected() could be of use: https://mongodb.github.io/node-mongodb-native/3.3/reference/unified-topology/

devconcept commented 2 years ago

If you check the code you'll see that the isConnected function is only executed if is present. When the function is finally removed it will not be used anymore and the library will still work. The warning is the price to pay for compatibility.