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

next.js/examples/with-mongodb-mongoose/ TypeError: conn.openUri(...).then is not a function #16290

Closed
TylerJNewman opened this issue Aug 18, 2020 · 4 comments
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@TylerJNewman
Copy link

TylerJNewman commented Aug 18, 2020

Bug report

Describe the bug

When adding a pet, post request to mongoose DB seems returns a 500 internal server error

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to https://github.com/vercel/next.js/tree/canary/examples/with-mongodb-mongoose
  2. yarn create next-app --example with-mongodb-mongoose with-mongodb-mongoose-app
  3. Get the connection string of your MongoDB servermongodb+srv://:@my-project-abc123.mongodb.net/test?retryWrites=true&w=majority
  4. Set MONGODB_URI in .env.local
  5. yarn install && yarn dev
  6. go to localhost:3000
  7. Add pet
  8. Shows the following text ("Failed to add pet")

Expected behavior

Add pet and return home

Screenshots

Screen Shot 2020-08-17 at 11 15 58 PM

Screen Shot 2020-08-17 at 11 15 18 PM

Screen Shot 2020-08-17 at 11 14 42 PM

If applicable, add screenshots to help explain your problem.

System information

  • OS: macOs Catalina
  • Browser Chrome
    "mongoose": "^5.9.13",
    "next": "^9.4.2",
  • Version of Node.js: (v12.18.2 - on my computer)

Additional context

Images are being added to DB sometimes and when I kill server and start back up the data ojbect with images show up which means in must be connecting and retrieving from mongo

Uri string seems to be fine

Add any other context about the problem here.

@timneutkens timneutkens added the good first issue Easy to fix issues, good for newcomers label Aug 18, 2020
@charliewilco
Copy link

this is a problem with mongoose itself in 5.10.0. i'm guessing on your yarn.lock or package-lock.json is grabbing 5.10 instead of 5.9.13 because of the ^. you can checkout by running cat node_modules/mongoose/package.json | grep 'version' to see what's really installed. the fastest way to fix this is by in your project's package.json is to pin the version.

diff --git a/package.json b/package.json
index 1d14380..4382643 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,7 @@
     "start": "next start"
   },
   "dependencies": {
-    "mongoose": "^5.9.13",
+    "mongoose": "5.9.13",
     "next": "^9.4.2",
     "react": "^16.13.1",
     "react-dom": "^16.13.1",

@charliewilco
Copy link

More details here Automattic/mongoose#9335

@TylerJNewman
Copy link
Author

cat node_modules/mongoose/package.json | grep 'version' "version": "5.10.0",
you are exactly right
pinned my version to "mongoose": "5.9.13" and it works! thanks!

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants