Thursday, February 28, 2013

The Reality of Developer’s Life

PROBLEM:
You want to be a developer

SOLUTION:
Read this first


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

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!

Union vs. Union All

PROBLEM:
What happens when you combine the same retrieval commands UNION (performs distinct query) and UNION ALL ?

SOLUTION:
Lets create test data:
CREATE TABLE #T (N INT);
GO
INSERT INTO #T
SELECT 1;
INSERT INTO #T
SELECT 2;
INSERT INTO #T
SELECT 2;
INSERT INTO #T
SELECT 3;
INSERT INTO #T
SELECT 3;
INSERT INTO #T
SELECT 3;
GO
SELECT *
FROM #T;


Now, lets query it:
SELECT * FROM #T
UNION ALL
SELECT * FROM #T
UNION
SELECT * FROM #T

SELECT * FROM #T
UNION
SELECT * FROM #T
UNION ALL
SELECT * FROM #T;



In the first case, the UNION makes distinct query and contracted three output lines, and in the second case the UNION ALL received three lines added all six.

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