-
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
Parrots collection? #3
Comments
The parrots collection is created by the exercise |
I realized that the HINTS for the FIND problem could have been better. Went ahead and added additional info in 9def6d5. |
I've tried 'show dbs' from the mongo shell after running the exercise; but I cannot see the collection or database. Also tried cheating and just running the solution and it just gave a blank [] as the result. The problem must be my setup? |
Yea, the exercise deletes the collection on cleanup. After you connected via the mongo shell, did you run |
Also, how did you run the solution? |
I ran using 'node ... path to solution' and I think when I did this mongo created an empty learnyounode database. I've just dropped that empty database and tried opening the exercise again, thinking that it may be blocking a fresh one being made; and then in a different window tried 'mongo, use learnyoumongo, show collections' and there is still no content. |
Yea, there won't be any content because it gets cleaned up after the exercise is done running. |
try using |
Alright, I can get it to work but I need to go back the run Exercise 1 MONGOD again. If I go straight into
I know mongo is running as if I use But if I go back and run Exercise 1 MONGOD again, and then try the verify on Exercise 3's solution... it works. Not sure if this intended or a problem in the code for Ex3? If it is intended it will be worth noting that the exercises should run in one sequential session. Also, to explain a bit of more of why I struggled. I usually read the problem and then try to fix it in isolation of |
strange, the mongodb module should be bundled so I am assuming that the error is being thrown from the file that you ran against verify? |
I am verifying the solution like a good cheat... ~/.npm/learnyoumongo/1.1.4/package/exercises/find/solution/solution.js |
@mr-cjk did you run "npm install mongodb"? |
I am having a lot of problems finishing these modules. It appears there is configuration/setup to be done every single time that is not clearly explained. |
@EightArmCode can you give me some more details on the issues you are having? |
I am also having trouble with the FIND exercise. I run this command: learnyoumongo run [solution.js] and get the following error: Am I supposed to create a solution.js file with the code? I tried this but did not seem to work (I even copied the solution of the exercise and it did not seem to make a difference). If you can provide some insight/help, I would appreciate it. Please feel free to let me know if you need additional information regarding the errors I get. Thank you. Nikolaos |
Can you share the code you ran to get that error? |
Hi Evan, I actually was able to figure it out. Basically, I had to run the command at the terminal like this: learnyoumongo run solution.js (once I got rid of the brackets from the solution.js filename, it worked!) Maybe it would be helpful to note this somewhere. -Nikolaos ORIGINAL COMMENT..... var mongo = require('mongodb').MongoClient
var age = parseInt(process.argv[2])
var url = 'mongodb://localhost:27017/learnyoumongo'
mongo.connect(url, function(err, db) {
if (err) throw err
var parrots = db.collection('parrots')
parrots.find({
age: {
$gt: age
}
}).toArray(function(err, docs) {
if (err) throw err
console.log(docs)
db.close()
})
}) |
Hi all, I'm new in Node.js and learning mongoDB just today morning, and here comes problem with exercise 3 also... var mongo = require('mongodb').MongoClient
var url = 'mongodb://localhost:27017/learnyoumongo'
var age = parseInt(process.argv[2])
mongo.connect(url, function (err, db) {
if (err) throw err
db.collection('parrots').find({
age: {
$gt: +age
}
}).toArray(function (err, documents) {
if (err) throw err
console.log(documents)
db.close()
})
}) And I run: learnyoumongo verify mongoFind.js
Even I tried solution.js in ./learnyoumongo/exercises/find/solution/solution.js with learnyoumongo verify solution.js, always return above error message... Please help me! Thanks!!! |
It seems it's necessary to run "npm install mongodb" before doing exercise 3. |
Hello @rulanfuse I've tried your suggestion and run npm install mongodb before verify Exercise 3 with my mongoFind.js but still got error message below
I think maybe was mongodb install path issue, I ran npm install mongodb and it goes to
Is it? And then I try again, but this time learnyoumongo return another error message...
Oh my god... Please help me... |
I have same problem |
I have similar problem. I've ran
and tried running
only to find
|
I ran into this problem, too. At first I presumed there was just some error in the js file I was trying to verify. However, no matter what I commented out (even if I commented everything out and hand a blank file), the solution would still fail. It made me realize that it's probably not my code. I finally did what mr-cjk mentioned he did in his post, above. I ran learnyoumongo again, selected the first exercise, and hit enter. Then, without doing anything else, I ran "learnyoumongo verify mongo-find.js" and exercise 3 finally passed (despite it failing before, despite I did not modify the .js file at all afterwards, and despite exercise 1 being the most recent exercise selected in learnyoumongo). Edit: Just realized that, although my file for exercise 3 PASSES when I do those steps, learnyoumongo marks exercise 1 as passing and not exercise 3 (which would make sense since that was the last exercise I selected when I tried the method mr-cjk mentioned). |
I was having an issue with step 3 as well, until reading an answer on SO that db.close() needs to be inside a callback, like toArray. Posting link to SO here for others who may be stuck on this step. |
I had a similar problem, but finally realised that the square brackets in the verify command weren't necessary. Having come from learnyounode, I noticed the difference in verify commands and assumed that the square brackets were necessary. It might be worth removing the square brackets from the instructions. |
For anyone having problem You have to start mongodb server in another terminal with this command: Then verify the file. I hope this will help anyone. |
Hi all, I have the same problem and stucked in exercise 3.But then i realized it wasn't my fault.So I go to exercise 1 and do it again, then exercise 2 and then exercise 3 and it works! Note that |
The solution is already provided above by @nalexiou . However, for those running into: 1)Make sure in another terminal MongoDb is running (see @Maroo-b 's answer) And lastly another very basic advice: use console logs when stuck, even Hope this helps someone, GL & HF. |
I was having same problem: @Maroo-b and @atan77 comments helped me. so here is steps if anyone having this problem:
|
I have pass the exam 3, with the result.
But i've checked on mongo shell using this command
So actually there is no document in collection parrots? |
The data is removed after the exercise is completed. Thanks! |
I'm seeing the same issue: The entire learnyoumongo db is empty. Is there a way to repopulate this db? Thanks. |
Hi @kristianjaeger, As mentioned above, the collection only exists when the exercise is being run, and deleted when it finishes. Longer term, it might make sense to populate the database as a step when we test che connection in the first lesson, that way folks can use normal MongoDB tooling to inspect the database to see what they are working with. |
@JoeDoyle23 Yes, that would be great. Right now, it's difficult to debug one's code as it stands or inspect the database itself. |
I haven't been able to get this to work - even using the solution.js provided here. I can start the server just fine with --nojournal. When I shell into mongo and type: It seems there aren't any sessions running... I went back and completed exercise 1, verified, and 2, then verifired just fine. I am not able to get past 3 for the life of me... *** I also tried using npm install mongod in the working directory *** |
Hey guys, the issue happen with latest version of mongodb, try to use another version, remove node_modules and |
After MongoDB 3.0, the hints and solutions are now obsolete. The main difference is, you can't specify the db name along with url, but have to use the client's db function to associate. Ex: |
Thank You! I've been going crazy trying to figure this out.. |
when i run: learnyoumongo verify find.js TypeError: db.collection is not a function Your submission results compared to the expected:
──────────────────────────────────────────────────────────────────────────────── "" != "[ { _id: 5a846f7fcbad8a21a813b260, name: 'Jenny', age: 10 } ]" ──────────────────────────────────────────────────────────────────────────────── ✗ Submission results did not match expected! FAILYour solution to FIND didn't pass. Try again! Someone can help me to solve this? thanks... |
NinemillaKA, did you use the client's db function to associate the database, before getting to the collection? The code is present two comments above.... |
Solved my issue, thanks! |
Hey --
I just tried this tutorial and hit a wall on exercise three, as I do not have a parrots collection?
I can see this is a fresh repo, sorry if I've jumped the gun!
The text was updated successfully, but these errors were encountered: