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

Secondary Indexes with UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'createCollection' of undefined #8534

Closed
Martii opened this issue Jan 24, 2020 · 2 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@Martii
Copy link

Martii commented Jan 24, 2020

Do you want to request a feature or report a bug?

Possible bug

What is the current behavior?

Dependencies:

$ node -v
v12.14.1

$ 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 9ms -
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
  }
]

Update to anything above mongoose@5.7.11 (Trying 5.8.9 currently)

$ node app.js
Starting application...
Disabling GitHub `hooks` in unsecure mode
(node:22429) 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:1300: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:1297:16)
    at ~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/mongoose/lib/model.js:1341: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:1338:16)
    at Object.<anonymous> (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/models/script.js:86:8)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
(node:22429) 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:22429) [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.
S3rver initialized
error: Error creating bucket. Bucket "openuserjs.org" already exists
info: PUT /openuserjs.org 409 10ms -
Default dev S3 bucket already exists
MongoDB connection is opened
Connected to MongoDB v3.6.12
GitHub client authenticated

If the current behavior is a bug, please provide the steps to reproduce.

Update https://github.com/OpenUserJS/OpenUserJS.org/blob/1261d161171f0558aa27d4de97f4a9a6c4fc9a15/package.json#L41 to use 5.8.9 (or anything above 5.7.11)

What is the expected behavior?

Print out the secondary indexes we add and not throw the UnhandledPromiseRejectionWarning event.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
See dependency list links and code blocks above.

Been trying to figure this out for some weeks in spare time, even with some other issues regarding .catch which didn't work on connect, and I'm stumped. We can trap the global UnhandledPromiseRejectionWarning with process but that doesn't seem to be the correct methodology. I assume, hopefully correct, that our secondary indexes aren't being synchronized with Mongo backend with this warning event.

Thanks so much for your assistance.

@vkarpov15 vkarpov15 added this to the 5.8.11 milestone Jan 28, 2020
@vkarpov15 vkarpov15 added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary labels Jan 28, 2020
@vkarpov15
Copy link
Collaborator

This issue is related to #8319 - your code is calling syncIndexes() before calling connect(). We added a workaround for that, fix will be in v5.8.11.

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 to OpenUserJS/OpenUserJS.org that referenced this issue Feb 5, 2020
* Please read their CHANGELOGs
* Delete op retested
* #1516 (comment) addressed at Automattic/mongoose#8534

Auto-merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants