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 trial

Databases Mongo Basics Understanding MongoDB Store Your Blog In Mongo

Jesse Thompson
Jesse Thompson
10,684 Points

Cant use commands after a period of time

When im in gitbash and I start mongo shell. Ill be able to do something like post.author and it will work when I press enter, but after that I type var id = post.author then db.users.find(id) and all it does is send me to the next line.

If I press ctrl C it exits the shell and then I have to do everything over again. How do I stop this behaviour?

edit: This doesnt seem to work either https://stackoverflow.com/questions/15673120/how-can-i-signal-eof-to-the-git-bash-terminal. I decided to switch to command terminal for mongo

See below:

ObjectId("5ad2dfe77f463f252a84f820")
post.author
ObjectId("5ad2dfe77f463f252a84f820")
var id = post.author
db.users.find(id)
db.users.find(id);
post.author
shows dbs
show dbs
show dbs
       show dbs

show dbs
`

1 Answer

Neil McPartlin
Neil McPartlin
14,662 Points

Hi Jesse. I don't think you have done anything wrong but based on my experience playing with it today, it can crash quietly. I'm on Windows 7 and I probably installed GitBash when I installed Git, but seeing your problem, I decided to try and replicate it.

With the Mongo daemon running in another terminal, I opened a GitBash session in the same Mongo folder where mongo.exe is located. It took a bit of Googling to find that I needed to type ./mongo to actually open the Mongo shell.

It's really disconcerting that there is no prompt. A bit of Googling revealed I was not alone. https://groups.google.com/forum/#!msg/mongodb-user/8SB7wGr3tPQ/np_vMGFRjZoJ

I did find how to enable a flashing cursor so at least I knew where to type. But very quickly, and repeatably, I could query for databases (show dbs), show tables (show collections), select a database (use [databaseName]) and then it just hangs, 'game over'.

A fellow Treehouse student even makes a passing remark about the stability of GitBash when accessing the Mongo Shell. https://teamtreehouse.com/community/how-to-setup-mongodb-on-windows-cmd-or-gitbash-with-shortcuts

So long story short, I could get those commands that you copied from the teacher (Huston), to work, but given the stability of the terminal, best to go with another terminal like you said. If you are a Windows user, the one mentioned when you actually start the Mongo shell (ConEmu at https://github.com/Maximus5/ConEmu) works well.

Jesse Thompson
Jesse Thompson
10,684 Points

Really appreciate the thorough answer Neil, yeah for the mongo command Ive decided to use the normal windows terminal as I couldnt get to the bottom of this issue. Seems that the overall experience for git bash on windows isn't full proof.