Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB/*mongoose* deprecations #1516

Open
Martii opened this issue Aug 26, 2018 · 2 comments
Open

MongoDB/*mongoose* deprecations #1516

Martii opened this issue Aug 26, 2018 · 2 comments
Labels
CODE Some other Code related issue and it should clearly describe what it is affecting in a comment. migration Use this to indicate that it may apply to an existing or announced migration.

Comments

@Martii
Copy link
Member

Martii commented Aug 26, 2018

(node:26124) DeprecationWarning: collection.count is deprecated, and will be removed in a future version. Use collection.countDocuments or collection.estimatedDocumentCount instead

We use .count in at least [one place] where this can be changed although upstream says it's still using the MongoDB v3.x driver... so that's confusing.

Refs:

With --trace-deprecation:

(node:7904) DeprecationWarning: collection.count is deprecated, and will be removed in a future version. Use collection.countDocuments or collection.estimatedDocumentCount instead
    at NativeCollection.(anonymous function) [as count] (~/OpenUserJS.org2/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:146:28)
    at NodeCollection.count (~/OpenUserJS.org2/node_modules/mquery/lib/collection/node.js:50:19)
    at model.Query.Query._count (~/OpenUserJS.org2/node_modules/mongoose/lib/query.js:2081:20)
    at process.nextTick (~/OpenUserJS.org2/node_modules/kareem/index.js:369:33)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:7904) DeprecationWarning: Cursor.each is deprecated. Use Cursor.forEach instead.
    at ~/OpenUserJS.org2/libs/modifySessions.js:293:19
    at handleCallback (~/OpenUserJS.org2/node_modules/mongodb/lib/utils.js:128:55)
    at Collection.<anonymous> (~/OpenUserJS.org2/node_modules/mongodb/lib/collection.js:432:45)
    at Collection.deprecated [as find] (~/OpenUserJS.org2/node_modules/mongodb/lib/utils.js:661:17)
    at exports.findSessionData (~/OpenUserJS.org2/libs/modifySessions.js:279:15)
    at Timeout.ttlSanity [as _onTimeout] (~/OpenUserJS.org2/app.js:552:3)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)

... doing this kills session management... so delay.... FIXED (this one code fence only)


(node:10349) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
@Martii Martii added migration Use this to indicate that it may apply to an existing or announced migration. CODE Some other Code related issue and it should clearly describe what it is affecting in a comment. labels Aug 26, 2018
@Martii Martii changed the title collection.count is deprecated MongoDB/*mongoose* deprecations Aug 26, 2018
@Martii
Copy link
Member Author

Martii commented Aug 26, 2018

These show up in local pro (different MongoDB version... already emailed sizzle about this incongruity):

(node:26443) DeprecationWarning: collection.find option [fields] is deprecated and will be removed in a later version.
(node:26443) DeprecationWarning: collection.find option [fields] is deprecated and will be removed in a later version.
Connected to MongoDB v3.0.15
GitHub client authenticated
(node:26443) DeprecationWarning: collection.update is deprecated. Use updateOne, updateMany, or bulkWrite instead.
(node:26443) DeprecationWarning: collection.count is deprecated, and will be removed in a future version. Use collection.countDocuments or collection.estimatedDocumentCount instead
(node:26443) DeprecationWarning: Cursor.each is deprecated. Use Cursor.forEach instead.

And some more...

(node:26443) DeprecationWarning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.
(node:26443) DeprecationWarning: collection.update is deprecated. Use updateOne, updateMany, or bulkWrite instead.
(node:26443) DeprecationWarning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.

Ref:


(node:32265) DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.

... string findAndModify not found in our project but other deps have it.

...

(node:12406) DeprecationWarning: Mongoose: `findOneAndUpdate()` and `findOneAndDelete()` without the `useFindAndModify` option set to false are deprecated. See: https://mongoosejs.com/docs/deprecations.html#-findandmodify-

Ref: Automattic/mongoose#7865

Martii added a commit to Martii/OpenUserJS.org that referenced this issue Oct 13, 2018
* Please read their CHANGELOGs
* Delete op retested

NOTE:
* Some of *express* update applies to OpenUserJS#1516 but we still have some as well ex. delete op that I mention usually is one
Martii added a commit that referenced this issue Oct 13, 2018
* Please read their CHANGELOGs
* Delete op retested

NOTE:
* Some of *express* update applies to #1516 but we still have some as well ex. delete op that I mention usually is one

Auto-merge
Martii added a commit to Martii/OpenUserJS.org that referenced this issue Dec 19, 2018
* Hopefully this will squash some warning messages.
* We still have on legacy URL API call to migrate but waiting a bit

Ref:
* https://mongoosejs.com/docs/connections.html#use-mongo-client

Applies to OpenUserJS#1516
Martii added a commit that referenced this issue Dec 19, 2018
* Hopefully this will squash some warning messages.
* We still have on legacy URL API call to migrate but waiting a bit

Ref:
* https://mongoosejs.com/docs/connections.html#use-mongo-client

Applies to #1516 

Auto-merge
@Martii Martii self-assigned this Jan 16, 2019
Martii added a commit to Martii/OpenUserJS.org that referenced this issue Jan 16, 2019
* Utilize this method for mongodb native... `async`/`await` with `hasNext()`/`next()` tested and can also work but part of ES6+

NOTE:
* Code looks more uniform with this method e.g. always wondered why there wasn't a final `aCallback`

Ref:
* https://stackoverflow.com/questions/25507866/how-can-i-use-a-cursor-foreach-in-mongodb-using-node-js#answer-25508173

Applies to OpenUserJS#1516
Martii added a commit that referenced this issue Jan 16, 2019
* Utilize this method for mongodb native... `async`/`await` with `hasNext()`/`next()` tested and can also work but part of ES6+

NOTE:
* Code looks more uniform with this method e.g. always wondered why there wasn't a final `aCallback`

Ref:
* https://stackoverflow.com/questions/25507866/how-can-i-use-a-cursor-foreach-in-mongodb-using-node-js#answer-25508173

Applies to #1516

Auto-merge
@Martii Martii removed their assignment Jan 16, 2019
@Martii Martii self-assigned this May 29, 2019
Martii added a commit to Martii/OpenUserJS.org that referenced this issue May 29, 2019
* Please read their CHANGELOGs
* Delete op retested

NOTES:
* Squashing one *mongoose*/MongoDB deprecation ... doesn't appear to negatively affect anything in dev. Applies to OpenUserJS#1516
* Some bug fixes from at least one of our major deps
* DB backend updated
Martii added a commit that referenced this issue May 29, 2019
* Please read their CHANGELOGs
* Delete op retested

NOTES:
* Squashing one *mongoose*/MongoDB deprecation ... doesn't appear to negatively affect anything in dev. Applies to #1516
* Some bug fixes from at least one of our major deps
* DB backend updated

Auto-merge
@Martii Martii removed their assignment May 29, 2019
Martii added a commit to Martii/OpenUserJS.org that referenced this issue Jun 4, 2019
* Please read their CHANGELOGs
* Delete op retested
* Attempt to squash another MongoDB/*mongoose* deprecation ... applies to OpenUserJS#1516
* Dependency update failure with *moment-duration-format*... keeping pinned to older version. See jsmreese/moment-duration-format#131
Martii added a commit that referenced this issue Jun 4, 2019
* Please read their CHANGELOGs
* Delete op retested
* Attempt to squash another MongoDB/*mongoose* deprecation ... applies to #1516
* Dependency update failure with *moment-duration-format*... keeping pinned to older version. See jsmreese/moment-duration-format#131

Auto-merge
Martii added a commit to Martii/OpenUserJS.org that referenced this issue Jun 5, 2019
Martii added a commit that referenced this issue Jun 5, 2019
* Big durr on my part

Post #1611 via #1516

Auto-merge
Martii added a commit to Martii/OpenUserJS.org that referenced this issue Jun 28, 2019
* Keeping applicable TLS restricted for eventual 12.x+ compatibility
* Search query *(modelQuery)* on, at the very least, `about` field causes maximum CPU usage in *node*@12.0.0 through *node*@12.5.0 but not v11.x or v10.x. This causes severe lag for everyone up to observed sustained 20+ seconds on queries.
* Restarting and exposing with transforming to secondary indexing for Script model as per all [*mongoose*/MongoDB documentation](https://mongoosejs.com/docs/guide.html#indexes). Use `syncIndexes` to maintain DB indexes.
* Squash new deprecation warning for OpenUserJS#1516

NOTES:
* This is going to be a major issue when v10.x is EOL'd if *node* and related dep issues *(mongoose, mongodb)* aren't resolved
* For some reason *mongoose* is emitting the `index` event twice when used globally... unknown reason atm. Picking local disable in favor.

Applies to OpenUserJS#1548 and post OpenUserJS#1603 with observed issue since then.

Refs:
* https://mongoosejs.com/docs/guide.html#indexes

Dev startup:

``` console
$ node app.js
Starting application...
Disabling GitHub `hooks` in unsecure mode
S3rver initialized
error: Error creating bucket. Bucket "openuserjs.org" already exists
info: PUT /openuserjs.org 409 11ms -
Default dev S3 bucket already exists
MongoDB connection is opened
Connected to MongoDB v3.6.12
GitHub client authenticated
Index event triggered/trapped for Script model
Script indexes:
 [ { v: 2,
    key: { _id: 1 },
    name: '_id_',
    ns: 'openuserjs_devel.scripts' },
  { v: 2,
    key: { _authorId: 1, flagged: 1, isLib: 1 },
    name: '_authorId_1_flagged_1_isLib_1',
    ns: 'openuserjs_devel.scripts',
    background: true },
  { v: 2,
    key: { installName: 1 },
    name: 'installName_1',
    ns: 'openuserjs_devel.scripts',
    background: true },
  { v: 2,
    key: { isLib: 1, author: 1, name: 1 },
    name: 'isLib_1_author_1_name_1',
    ns: 'openuserjs_devel.scripts',
    background: true } ]
```

Recent db stats:

``` console
> db.scripts.aggregate( [ { $indexStats: { } } ] );
{ "name" : "_id_", "key" : { "_id" : 1 }, "host" : "<db>:<port>", "accesses" : { "ops" : NumberLong(12842), "since" : ISODate("2019-06-27T04:10:25.453Z") } }
{ "name" : "isLib_1_author_1_name_1", "key" : { "isLib" : 1, "author" : 1, "name" : 1 }, "host" : "<db>:<port>", "accesses" : { "ops" : NumberLong(7348), "since" : ISODate("2019-06-27T12:26:13.574Z") } }
{ "name" : "installName_1", "key" : { "installName" : 1 }, "host" : "<db>:<port>", "accesses" : { "ops" : NumberLong(144052), "since" : ISODate("2019-06-27T04:10:25.453Z") } }
{ "name" : "_authorId_1_flagged_1_isLib_1", "key" : { "_authorId" : 1, "flagged" : 1, "isLib" : 1 }, "host" : "<db>:<port>", "accesses" : { "ops" : NumberLong(16691), "since" : ISODate("2019-06-27T04:10:25.453Z") } }
```
Martii added a commit that referenced this issue Jun 28, 2019
* Keeping applicable TLS restricted for eventual 12.x+ compatibility
* Search query *(modelQuery)* on, at the very least, `about` field causes maximum CPU usage in *node*@12.0.0 through *node*@12.5.0 but not v11.x or v10.x. This causes severe lag for everyone up to observed sustained 20+ seconds on queries.
* Restarting and exposing with transforming to secondary indexing for Script model as per all [*mongoose*/MongoDB documentation](https://mongoosejs.com/docs/guide.html#indexes). Use `syncIndexes` to maintain DB indexes.
* Squash new deprecation warning for #1516

NOTES:
* This is going to be a major issue when v10.x is EOL'd if *node* and related dep issues *(mongoose, mongodb)* aren't resolved
* For some reason *mongoose* is emitting the `index` event twice when used globally... unknown reason atm. Picking local disable in favor.

Applies to #1548 and post #1603 with observed issue since then.

Refs:
* https://mongoosejs.com/docs/guide.html#indexes

Dev startup:

``` console
$ node app.js
Starting application...
Disabling GitHub `hooks` in unsecure mode
S3rver initialized
error: Error creating bucket. Bucket "openuserjs.org" already exists
info: PUT /openuserjs.org 409 11ms -
Default dev S3 bucket already exists
MongoDB connection is opened
Connected to MongoDB v3.6.12
GitHub client authenticated
Index event triggered/trapped for Script model
Script indexes:
 [ { v: 2,
    key: { _id: 1 },
    name: '_id_',
    ns: 'openuserjs_devel.scripts' },
  { v: 2,
    key: { _authorId: 1, flagged: 1, isLib: 1 },
    name: '_authorId_1_flagged_1_isLib_1',
    ns: 'openuserjs_devel.scripts',
    background: true },
  { v: 2,
    key: { installName: 1 },
    name: 'installName_1',
    ns: 'openuserjs_devel.scripts',
    background: true },
  { v: 2,
    key: { isLib: 1, author: 1, name: 1 },
    name: 'isLib_1_author_1_name_1',
    ns: 'openuserjs_devel.scripts',
    background: true } ]
```

Recent db stats:

``` console
> db.scripts.aggregate( [ { $indexStats: { } } ] );
{ "name" : "_id_", "key" : { "_id" : 1 }, "host" : "<db>:<port>", "accesses" : { "ops" : NumberLong(12842), "since" : ISODate("2019-06-27T04:10:25.453Z") } }
{ "name" : "isLib_1_author_1_name_1", "key" : { "isLib" : 1, "author" : 1, "name" : 1 }, "host" : "<db>:<port>", "accesses" : { "ops" : NumberLong(7348), "since" : ISODate("2019-06-27T12:26:13.574Z") } }
{ "name" : "installName_1", "key" : { "installName" : 1 }, "host" : "<db>:<port>", "accesses" : { "ops" : NumberLong(144052), "since" : ISODate("2019-06-27T04:10:25.453Z") } }
{ "name" : "_authorId_1_flagged_1_isLib_1", "key" : { "_authorId" : 1, "flagged" : 1, "isLib" : 1 }, "host" : "<db>:<port>", "accesses" : { "ops" : NumberLong(16691), "since" : ISODate("2019-06-27T04:10:25.453Z") } }
```

Auto-merge
@Martii
Copy link
Member Author

Martii commented Jan 7, 2020

During a dep update test cycle...

(node:9303) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'createCollection' of undefined
    at NativeConnection.createCollection (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/connection.js:356:11)
    at ~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/connection.js:451:12
    at Object.promiseOrCallback (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/utils.js:261:12)
    at NativeConnection.createCollection (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/connection.js:445:18)
    at ~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/model.js:1299:13
    at Object.promiseOrCallback (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/utils.js:261:12)
    at Function.createCollection (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/model.js:1296:16)
    at ~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/model.js:1340:10
    at ~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/utils.js:283:5
    at new Promise (<anonymous>)
    at Object.promiseOrCallback (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/utils.js:282:10)
    at Function.syncIndexes (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/model.js:1337:16)
    at Object.<anonymous> (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/models/script.js:86:8)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
(node:9303) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:9303) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

... as far as I know we don't use promises but deps may internally.

Squashed during testing:

(node:8993) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
(node:9088) DeprecationWarning: The option `reconnectTries` is incompatible with the unified topology, please read more by visiting http://bit.ly/2D8WfT6
(node:9088) DeprecationWarning: The option `reconnectInterval` is incompatible with the unified topology, please read more by visiting http://bit.ly/2D8WfT6

Martii added a commit to Martii/OpenUserJS.org that referenced this issue Jan 24, 2020
* Please read their CHANGELOGs
* Delete op retested
* *diff* not bumped on GH repo but on npmjs.com
* Downgrade *mongoose* to remove secondary index failure reported at OpenUserJS#1516 (comment)
Martii added a commit that referenced this issue Jan 24, 2020
* Please read their CHANGELOGs
* Delete op retested
* *diff* not bumped on GH repo but on npmjs.com
* Downgrade *mongoose* to remove secondary index failure reported at #1516 (comment)

Auto-merge
Martii added a commit to Martii/OpenUserJS.org that referenced this issue Feb 5, 2020
* Please read their CHANGELOGs
* Delete op retested
* OpenUserJS#1516 (comment) addressed at Automattic/mongoose#8534
Martii added a commit that referenced this issue Feb 5, 2020
* Please read their CHANGELOGs
* Delete op retested
* #1516 (comment) addressed at Automattic/mongoose#8534

Auto-merge
Martii added a commit to Martii/OpenUserJS.org that referenced this issue Sep 6, 2020
* Possible recommendation as `expires` alias to `expireAfterSeconds` may need this to properly set values of an index that is created app side to sync with back-end.
* Increase event `emitter.setMaxListeners` to accommodate additional MongoDB usage with error thrown:

``` console
Index event triggered/trapped for User model
Index event triggered/trapped for Discussion model
Index event triggered/trapped for Strategy model
Index event triggered/trapped for Remove model
Index event triggered/trapped for Comment model
Index event triggered/trapped for Group model
Index event triggered/trapped for Flag model
Index event triggered/trapped for Vote model
(node:10567) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 open listeners added to [NativeConnection]. Use emitter.setMaxListeners() to increase limit
```

Applies to OpenUserJS#1744 OpenUserJS#1730 and followup for OpenUserJS#1516 ... followup needed on mLab for index that's already there *(which I didn't put there)*
Martii added a commit that referenced this issue Sep 6, 2020
* Possible recommendation as `expires` alias to `expireAfterSeconds` may need this to properly set values of an index that is created app side to sync with back-end.
* Increase event `emitter.setMaxListeners` to accommodate additional MongoDB usage with error thrown:

``` console
Index event triggered/trapped for User model
Index event triggered/trapped for Discussion model
Index event triggered/trapped for Strategy model
Index event triggered/trapped for Remove model
Index event triggered/trapped for Comment model
Index event triggered/trapped for Group model
Index event triggered/trapped for Flag model
Index event triggered/trapped for Vote model
(node:10567) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 open listeners added to [NativeConnection]. Use emitter.setMaxListeners() to increase limit
```

Applies to #1744 #1730 and followup for #1516 ... followup needed on mLab for index that's already there *(which I didn't put there)*

Auto-merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CODE Some other Code related issue and it should clearly describe what it is affecting in a comment. migration Use this to indicate that it may apply to an existing or announced migration.
Development

No branches or pull requests

1 participant