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

Model.find.then() results in MongoInvalidArgumentError: Method "collection.find()" accepts at most two arguments #10634

Closed
nwongsavit opened this issue Aug 29, 2021 · 4 comments
Milestone

Comments

@nwongsavit
Copy link

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

What is the current behavior?
Model.find().then() results in MongoInvalidArgumentError: Method "collection.find()" accepts at most two arguments.

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

  1. Connect to Mongo DB using Mongoose (6.0.2)
  2. Chain Model.find() with .then()
  3. Get a MongoInvalidArgumentError on collection.find()

Code:

Person.find({}).then(result => {
  result.forEach(person => {
    console.log(person)
  })

  mongoose.connection.close()
})

Error:

(node:7142) UnhandledPromiseRejectionWarning: MongoInvalidArgumentError: Method "collection.find()" accepts at most two arguments
    at Collection.find (/Users/nwongsavit/Projects/fso/part3/phonebook/node_modules/mongodb/lib/collection.js:238:19)
    at NativeCollection.<computed> [as find] (/Users/nwongsavit/Projects/fso/part3/phonebook/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:191:33)
    at NativeCollection.Collection.doQueue (/Users/nwongsavit/Projects/fso/part3/phonebook/node_modules/mongoose/lib/collection.js:135:23)
    at /Users/nwongsavit/Projects/fso/part3/phonebook/node_modules/mongoose/lib/collection.js:82:24
    at processTicksAndRejections (internal/process/task_queues.js:75:11)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:7142) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7142) [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.

What is the expected behavior?
Should be able to chain .then() to Model.find() without an error.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: v14.15.4
Mongoose: 6.0.2
MongoDB: 4.1.1

@marcusgchan
Copy link

marcusgchan commented Aug 29, 2021

I am having the same problem. I found a post that says downgrading to version 5.13.8 gets rid of the issue. https://stackoverflow.com/questions/68957133/mongoose-model-find-throws-a-unhandledpromiserejectionwarning-error

@AndrewBarba
Copy link

Same issue. Downgrading to 6.0.1 also works.

@AndrewBarba
Copy link

Similar to previous issue... awaiting the default connection before running any queries works correctly

@lorand-horvath
Copy link
Contributor

This is a duplicate of the issue I reported here initially #10610 (comment) and should be fixed in 6.0.3 via 9de60a7

@vkarpov15 vkarpov15 added this to the 6.0.3 milestone Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants