Skip to content

Why do I get the Must call setClient() with an instance of MongoClient error ? #11494

Answered by vkarpov15
robots4life asked this question in Q&A
Discussion options

You must be logged in to vote

The error message I get when running the above script is:

MongooseError: Cannot call `setClient()` with a MongoClient that you have not called `connect()` on yet.

Which is fairly self explanatory, you need to do await client.connect() before calling setClient().

The error message you posted, though, makes me think that you have an incompatible version of the mongodb driver. Try running npm list | grep "mongo" and paste the output here. The output should look something like:

projectname@0.0.2 /home/user/projectname
└─┬ mongoose@6.2.5
  ├─┬ mongodb@4.3.1
  │ ├─┬ mongodb-connection-string-url@2.5.2

Replies: 1 comment 14 replies

Comment options

You must be logged in to vote
14 replies
@Uzlopak
Comment options

Uzlopak May 3, 2022
Collaborator

@robots4life
Comment options

@Uzlopak
Comment options

Uzlopak May 3, 2022
Collaborator

@robots4life
Comment options

@Uzlopak
Comment options

Uzlopak May 3, 2022
Collaborator

Answer selected by Uzlopak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants