Wednesday, February 27, 2013

Your first MongoDB application

PROBLEM:
What you need to know to build your first MongoDB application?

SOLUTION:
MongoDB Terminology
As you build your first application with MongoDB, you should start by knowing some basic terminology. Here are a few key terms and the equivalent concepts in a relational database:

RDBMSMongoDB
Rows, ViewsDocuments
TablesCollections
IndexIndex
JoinEmbedded Documents
PartitionShard

Data as Documents
One of the major benefits of MongoDB is schema flexibility. In MongoDB, there are no predefined fields, collections can have heterogenous structure across documents, and the fields and their value datatypes can vary. For example, here is how you might model a blog post in MongoDB:

{author: "meghan",
date: new Date(),
text: "MongoDB is great!",
tags: ["mongodb", "intro"]}

As you can see with the tags field in the example above, we have stored an array of strings within our document. And if we want to add another field to our document, we can do so easily. This facility enables you to develop applications iteratively with MongoDB.

Querying
Even though MongoDB is a NoSQL database, you can still access your data with dynamic queries. You'll find that many SQL queries translate easily to MongoDB's document-based query language.
For example, suppose we're using the MongoDB shell and want to return every document in the users collection. Our query would look like this:

db.users.find({})

In this case, our selector is an empty document, which matches every document in the collection. Here's a more selective example:

db.users.find({'last_name': 'Smith'})

Here our selector will match every document where the last_name attribute is 'Smith.'
MongoDB supports a wide array of possible document selectors. For more examples:


For more information
Interested in learning more about building applications with MongoDB? Here are a few resources to get you started:


If you find this solution useful, you are welcome to press one of the ads in this page.. Thanks!

No comments:

Post a Comment