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 trialVicente Canhoto
Courses Plus Student 1,140 PointsSeed.js loading error
I'm not being able to load the seed.js file, I get the following error:
> load('seed.js')
2016-01-06T00:35:34.287+0100 E QUERY [thread1] TypeError: authors[Math.floor(
...)] is undefined :
@seed.js:54:25
@(shell):1:1
The file is in the same folder as the mongo executable. What am I doing wrong?
7 Answers
Lewis Cowles
74,902 PointsThe error seems to be relating to accessing an index of the authors array. (shouldn't be able to happen as Math.floor rounds down and if the users table was unable to be setup, then it should multiply by zero, giving Math.floor(x*0)).
https://github.com/hdngr/treehouse-mongo-basics/blob/master/seed.js#L31
Please can you post your mongo version, OS please as I am having trouble replicating, when I run load('seed.js')
it just works.
Also check permissions for your data folder in-case something went wrong when setting up.
My setup did differ to Huston Hedinger in that I downloaded an msi (windows), and used the mongo docs for ubuntu install.
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
Vicente Canhoto
Courses Plus Student 1,140 PointsI'm running 3.2 on Windows 10. I also downloaded and installed the msi file.
Ken Alger
Treehouse TeacherVicente;
That is what I am running as well.
To update my understanding of the issue, you have started a mongod
instance from the command line and, thus, have an active database.
You have seed.js
stored locally on your system, probably have pulled it from GitHub a few times to make sure it is current and correct.
Inside the Mongo Shell you are running the load()
command and using the path to the seed.js
file as the parameter, or you have made sure that you are in the proper directory inside Mongo Shell to directly load the seed.js
file. You can use the pwd()
command from Mongo Shell to see the directory you are working in. And that you are using the mongoBasics
database and not the default test
database, that shouldn't matter, but from the standpoint of the course it might.
When it attempts to load seed.js
you get the error you stated. Everything else seems to be working fine with MongoDB outside of this one issue?
Post back if you are still stuck, there are a few other ways to get the data outside of the load()
command. It will take some outside assistance though.
Happy coding,
Ken
silvercoder
11,113 PointsHi, so i was getting this annoying error:
load('seed.js'); 2017-12-31T09:39:21.517+0000 E QUERY [thread1] [seed.js:54:25] TypeError: authors[Math.floor(...)] is undefined Stack trace: @seed.js:54:25
@(shell):1:1
2017-12-31T09:39:21.517+0000 E QUERY [thread1] Error: error loading js file: seed.js @(shell):1:1
If you're taking this course and you get the same error here is what i did to fix it:
- Clone seed from git.
- Edit the seed.js file.
- Change the following line:
var db = db.getSiblingDB('mongoBasics');
to
var db = db.getSiblingDB('MongoBasics');
- Type load('seed.js') and it should work.
Thanks.
J llama
12,631 PointsThank you so much for finding this easy fix. SOOOO frustrating that treehouse made such a critical mistake like this + none of their staff could find it. What a waste of my time on a part of the course that should be a quick set up/over with in minutes, here I am an hour later. Makes me question why the heck I'm paying so much $ A MONTH!!!
Ken Alger
Treehouse TeacherVicente;
Welcome to Treehouse!
Are you trying to run the git
command that was shown in the video? I guess I am missing what command you are attempting to run that is causing an error.
Ken
Vicente Canhoto
Courses Plus Student 1,140 PointsHi Ken, thank you for your reply.
I git cloned the repo and copied the seed.js file to the mongod.exe folder, to be easier to load. Then on the mongo shell I ran the load('seed.js') command, and that's were I got the error you can see in my post.
Thanks for your help.
Vicente
Vicente Canhoto
Courses Plus Student 1,140 PointsApparently there was some issue with the /data/db folder. After I deleted it and created a new one in the Command Prompt it worked.
Thank you very much Ken and Lewis, for your help and patience.
Cheers, Vicente
Ken Alger
Treehouse TeacherPleased it worked out. Enjoy the rest of MongoDB Basics and MongoDB in general.
Happy coding,
Ken
Lewis Cowles
74,902 PointsGlad it worked out Vicente Canhoto. Permissions are one of those things, it's likely this won't be your last rodeo with them.
Tim Pinkerton
23,019 PointsI'm getting the same error. How did you delete the /data/db folder? Thanks.
Pierre Smith
11,842 Pointsmake sure that inside the seed.js file the file name is the same as the db you created inside of mongo, That obviously can cause errors and prevent it from loading because your trying to get and drop a table that doesn't exist.
Check to see if you added the capital B to the mongoBasics collection
T SL
Courses Plus Student 378 PointsIt's in case you have followed the tutorial and have a databse with the same name set up.
Do this
use mongoBasics db.dropDatabase()
then run the load('./seed.js'); command again
La-Keisha Towner
Courses Plus Student 3,211 PointsLa-Keisha Towner
Courses Plus Student 3,211 PointsHey, so I just had the same error, but it did not have anything to do with my path. I named my collection 'MongoBasics' in the first step instead of 'mongoBasics', all I needed to do was open the seed.js file and changed the line where it says
var db = db.getSiblingDB('mongoBasics'); to var db = db.getSiblingDB('MongoBasics');
and my error was fixed. I hope this helps someone because I spent about 30mins trying to figure out what was wrong and it was as simple as fixing this line to match what was inside my database.