Tag Archives: MongoDB

Return Distinct Elements in a Field of a MongoDB Collection

I’ve been working with MongoDB, and I noticed that querying the unique values in a field of a given collection follows a non-idiomatic pattern. That is to say, it does not look like,

db.collection.find( { "Field": { $unique: 1 } } )

Rather, it looks like this,

db.runCommand( { distinct: <collection>, key: <field> } )

And this returns a document with a "values" and "stats" field, and hopefully an "ok":1 field. This is the documentation.

Using Node and Mongo to Collect Data from Reddit

I am taking a course on MongoDB development with Node.js from Mongo University. In the second week we covered a thing that I thought was very interesting. They walked you through how to grab the JSON data out of a Reddit page. Reddit apparently offers its data up as a JSON if you pass it a .json path. Here is the coffeescript that produces the code provided in the development course.

Continue reading

Getting Started with MongoDB and Python

In this post I’ll walk through getting started with MongoDB using the Python PyMongo module. I’ll go through the installation process, and then walk through an example of entering data into a MongoDB through Python. (In a future post I’ll cover querying documents.) For the installation, I’ll assume that you’re running Ubuntu, but there are instructions for all major operating systems on the link that I have provided.

Continue reading