Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKilleon Patterson
18,528 PointsUpdating data to MongoDB (mongoose)
I've made my Schema and created a seeder file to upload data to my MongoDB server, but the data appears to remain unsent. I've restarted npm, run mongo, and mongod in seperate consoles (windows 10 machine). When I run 'use shopping' , then db.shopping.find(), nothing populates the console.
Here is a link to my gist https://gist.github.com/Satellite9/5e4ce3de5c19cee2f355d872b6d7d3c8
Killeon Patterson
18,528 PointsHi Florian, the command line just moves down and displays nothing. I get the same response when I use "show collections." I changed my systems variable path to include the 'seed' directory. When I run command 'node product-seeder.js,' in the console, I receive a depracationwarning. Thank you for your reply.
3 Answers
Andrew Chalkley
Treehouse Guest TeacherHi Killeon,
How does the product-seeder know which database it connects to? The connection string to the database is in the app.js file as far as I can see. I think if you start the connection in your seeder and then run it, you should have the data populated.
Regards
Andrew
Killeon Patterson
18,528 PointsHello Andrew,
Thank you for your reply. It resolved my issue.
Did the connection string need to go into seeder, as opposed to the app.js file, because the seeder is not technically part of the app? Because my understanding was the app.js was the place where I needed to require all packages that pertain to the application. Thank you again.
Andrew Chalkley
Treehouse Guest Teacherapp.js
is just an entry point in to code that you want to run for the server. If you create other files that perform different tasks, mini-apps if you will, you need to establish their own connections to databases or what ever it needs to do. Your seeder had no idea of what the app.js
is doing because it's not require()
d.
Seth Kroger
56,413 PointsThe problem is you are using the database name instead of the collection's name for find(). Since your Mongoose Schema is named Product your collection should be named products and the find command should be db.products.find().
Killeon Patterson
18,528 PointsHi Seth, That is the syntax that I'm using, it does not appear to resolve the issue. Thank you for your reply.
Ken Alger
Treehouse TeacherKilleon;
I'd be interested to see what information you get back from
show databases
as well.
Killeon Patterson
18,528 PointsHello Ken,
The 'show databases' command showed and empty admin and an empty local. The problem was the location of my connection string. It was in my app.js file and not my seeder. Although, my understanding, when I created the app.js, was that the everything had to run through that file first and always. I didn't realize the string was suppose to go into the seeder.
Thank you for your reply and time.
Ken Alger
Treehouse TeacherGreat that you resolved the issue.
For future trouble shooting, if doing a show databases
or show dbs
doesn't result in showing the desired database, that is an indication that the specific DB hasn't been created.
Remember that MongoDB doesn't create a database or collection until a document is created in the database.
Again, I'm pleased it all worked out.
Happy coding.
Killeon Patterson
18,528 PointsThank you. Happy coding.
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 PointsFlorian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 PointsWhat does mongo say when you run "use shopping" and then "show collections"?