-
Notifications
You must be signed in to change notification settings - Fork 89
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
Comments
Getting the same problem. Seems to be unable to access the collection |
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 |
I'm getting the same error. Can someone follow up? |
I faced some issue just run mongod server in another terminal: then execute learnyoumongo run file.js. |
I'm getting the same error as well. If I run Edit: Oops, my bad! Turns out that the problem was largely on my side. I did have to run |
Yes, mongod must be running for all of the exercises |
FWIW I noticed that when installing the npm mongodb package there is an error about the peer dependency |
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 Error message:
|
Yes, There is problem. |
Sure there is the problem with the DB, somehow it's not created.
But i've checked on mongo shell using this command
So actually there is no document in collection parrots? |
@ThomastheBicyclist you would need to run |
@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?) :] |
@evanlucas Ok. thanks for the response. now i understand how it's works. |
i tried the following and it worked with me
after this i did forget to add |
hi! i was googling for a hint on why and then i tried testing 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. |
Was having same issue and this helped: 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 |
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...
The text was updated successfully, but these errors were encountered: