Oliver Nassar

I can be reached at onassar@gmail.com.

For my open source work, check out github.com/onassar


Accessing Mongo collection from the command line

View more posts

I was having a weird problem with mongo whereby my application was hitting mongo and storing everything perfectly, but I couldn't access it from the command line. Turns out I'm just stupid, and didn't know how to access it properly.

Via the mongo console, I was trying to access my collection's data via:

db.users.find()

The reason? I was following the mongo tutorials which used a similar syntax. Turns out, I should've been running the following:

use dbname
db.users.find({})
db.users.find()

The last two lines return the same response, for the record. I just needed to be explicitity write that I'm using the the dbname database, and then reference the users collection to query against it. I think I failed to understand that in the tutorial, the name of their db was actually the string, db.

Anyway, that helped out.