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

error in learn you mongo exercise 3 #24

Open
gunrunners-paradise opened this issue Dec 11, 2015 · 16 comments
Open

error in learn you mongo exercise 3 #24

gunrunners-paradise opened this issue Dec 11, 2015 · 16 comments

Comments

@gunrunners-paradise
Copy link

I'm running from c9.IO, whenever I try to run the selected file with the command "learnyoumongo run file.js" I get the below error.

I tried playing around with the code and I tried it with a blank file, the result is always the same...

/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/mongodb/lib/server.js:235
        process.nextTick(function() { throw err; })
                                      ^

TypeError: Cannot read property 'collection' of undefined
    at Exercise.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/exercises/find/exercise.js:37:5)
    at next (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:260:17)
    at Exercise.end (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:266:5)
    at Workshopper.end (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper/workshopper.js:191:12)
    at Workshopper.done (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper/workshopper.js:323:19)
    at Exercise.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:149:14)
    at /home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:136:16
    at /home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/exercises/find/exercise.js:20:21
    at /home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/mongodb/lib/mongo_client.js:269:20
    at /home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/mongodb/lib/db.js:226:14

@vtange
Copy link

vtange commented Dec 13, 2015

Getting the same problem. Seems to be unable to access the collection
I can see the parrots collection in the mongo client though. However. using db.parrots.find() with learnyoumongo being the active db returns absolutely nothing.

@evanlucas
Copy link
Owner

strange. Not really sure what the problem is here. As soon as I get some free cycles, I'll take a look and see if I can reproduce

@mileung
Copy link

mileung commented Jan 4, 2016

I'm getting the same error. Can someone follow up?

@Maroo-b
Copy link

Maroo-b commented Jan 4, 2016

I faced some issue just run mongod server in another terminal:
mongod --port 27017 --dbpath=./data --nojournal

then execute learnyoumongo run file.js.

@systimotic
Copy link

I'm getting the same error as well. If I run mongod myself (with options as shown above) I get an error about the server closing the connection.

Edit: Oops, my bad! Turns out that the problem was largely on my side. I did have to run mongod myself, which maybe should be stated more clearly in the exercise (unless you shouldn't have to and it's an error, then fixing it might be the better solution). The closing connection ended up being because I misplaced db.close(). There's still definitely an issue here though, although a change to the exercise text might be all that's needed to fix it.

@evanlucas
Copy link
Owner

Yes, mongod must be running for all of the exercises

@pyromaticx
Copy link

FWIW I noticed that when installing the npm mongodb package there is an error about the peer dependency kerberos@0.0 I tried installing a current version but have not been able to get it to build properly

@ThomastheBicyclist
Copy link

I have what seems to be the same problem for exercise 3. I resorted to using the "correct solution" but it didn't pass.

Mongod is running.

Mongodb v2.6.11
Node v4.1.1

Error message:

module.js:338
    throw err;
    ^

Error: Cannot find module 'mongodb'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/home/ubuntu/workspace/ex3of9.js:2:13)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)

Your submission results compared to the expected:

                 ACTUAL                                 EXPECTED                
────────────────────────────────────────────────────────────────────────────────

   ""                                  !=    "[ { _id: 56de07ece7777cf009209332, name: 'Jenny', age: 10 } ]"
                                       !=    ""                                 

────────────────────────────────────────────────────────────────────────────────

✗ Submission results did not match expected!

# FAIL

Your solution to FIND didn't pass. Try again!

@manishupadhyay
Copy link

Yes, There is problem.
It seems it clears the DB. Because when i debugged directly into the DB using Robomongo. I found no documents in the DB.
Solution to problem insert the data manually and than try it.
Thanks
-Manish

@ygautomo
Copy link

ygautomo commented Jun 5, 2016

@manishupadhyay

Sure there is the problem with the DB, somehow it's not created.
Actually I have pass the exam 3, with the result.

[ { _id: 5753ba9f84bd376d11a4ebd8, name: 'Jenny', age: 10 } ]

But i've checked on mongo shell using this command

> db
learnyoumongo
> show collections
parrots
system.indexes
> db.parrots.count()
0
> db.system.indexes.count()
1

So actually there is no document in collection parrots?
Where should i check the data?

@evanlucas
Copy link
Owner

@ThomastheBicyclist you would need to run npm install mongodb whenever you see that error

@evanlucas
Copy link
Owner

@ygautomo The data is inserted and then removed when the process exists, so it will show 0 for the count after the exercise is run. That is by design (if I can even call it that?) :]

@ygautomo
Copy link

@evanlucas Ok. thanks for the response. now i understand how it's works.

@hellsinglord22
Copy link

hellsinglord22 commented Aug 27, 2016

i tried the following and it worked with me
delete the database directory and recreate it, (care this will delete every database you have in this directory )

mkdir ./data
mongod --dbpath ./data

after this i did forget to add db.end(); after i am done so i add it and it work just fine after .

@arhyth
Copy link

arhyth commented Aug 24, 2017

hi! i was googling for a hint on why
var collectables = db.collection('<parrots>');
returns
Property 'collection' of object learnyoumongo is not a function

and then i tried testing db.parrots.find() and alas, also got 0.

i have not yet worked out and run a solution file so i don't know why there's no more document in the parrots collection. though i was trying out individual statements/commands if anything would stick so i could compose the successful ones later into a .js file. i have not succeeded on running anything at all except for the "db.parrots.find()" which returned 0.

i already tried deleting the data folder and rerunning learnyoumongo and mongod.
still 0. what to do?

@mahdiASC
Copy link

Was having same issue and this helped:
https://stackoverflow.com/questions/47662220/db-collection-is-not-a-function-when-using-mongoclient-v3-0/47662979

Essentially, the newer version of mongodb has changed how the .connect() method works. It no longer provides a db, but a Client object. You can extract the db from this object by referring to the db by name. For example:

const mongo = require("mongodb").MongoClient;
const url = "mongodb://localhost:27017/learnyoumongo";
const database = "learnyoumongo";
const ageThresh = parseInt(process.argv[2]);

mongo.connect(url, function (err, client) {
    if (err) throw err;
    const col = client.db(database).collection("parrots");
    col.find({
        age: {$gt:ageThresh}
    }).toArray(function (err, docs) {
            if (err) throw err;
            console.log(docs);
        })
    client.close();
});

Note how you close the client now, and not the db

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