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

Uday Ramakrishna
Uday Ramakrishna
226 Points

Mongo collection returns blank

Hi,

I just started learning mongo here and was hoping to apply this to a work situation. I have a collection called sessions where when i go db.sessions.count() i see 2 records but when i do db.sessions.find() i receive no response. Any thoughts on why this might be the case?

6 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Uday;

Which version of MongoDB are you using?

Ken

Uday Ramakrishna
Uday Ramakrishna
226 Points

Hi Ken, i am using version 3.0.9 based on the response to db.version();

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Great. Thanks for that.

I find it odd as well that doing a db.sessions.find() returns nothing. What happens if you do a db.sessions.findOne()? Do you get a result from that?

Are you attempting to run these commands in the Mongo Shell?

Ken

Uday Ramakrishna
Uday Ramakrishna
226 Points

Hi Ken,

Yes, i was running these from command line. Looks like the database i was trying to access did not have much data in it. Since i am learning as well as trying to apply, i found a php solution to try and view the data in this database which helped me get a peek at the underlying data which turned out to be blank except the index. Thanks for checking in. But i think i will need to try more as i cant reproduce the exact issue.

Best Regards Uday

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Uday;

No problem at all. I would recommend generating some test data quickly from the Mongo Shell just to make sure if you still have concerns. Small datasets can sometimes lead to strange results, but you should still be able to do a find() and have the returned cursor display all of the documents in the collection, even if those documents only contain an _id field.

Please post back if you still have additional issues or questions. And congratulations on working with MongoDB!

Best wishes and happy coding, Ken

Uday Ramakrishna
Uday Ramakrishna
226 Points

Thank you for the quick response Ken. I will certainly drop a note here should i encounter any further issues. I used http://www.phpmongodb.org to take a peek at my data and might be useful for others hence listing it here.

Best Regards Uday

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Uday;

MongoDB is making a large move towards, and investment in, visual ways to access and manage a MongoDB database. Some of their options are things like Cloud Manager and Ops Manager which are awesome, but likely overkill for what you need. Although I would highly recommend you at least take a look at them.

The other option which might be of use is MongoDB Compass which could be of some use for your current level of use.

Happy coding, Ken