开发者

Need suggestions to clarify the concept of mongoDB to store and retrieve images

I am new to mongoDB. I was told to use mongoDB to my photo management web app. I am not able to understand mongoDB's basic concept. The documents.

What is documents in mongoDB?

j = { name : "mongo" };
t = { x : 3 };

In mongoDB website they told that the above 2 lines were 2 documents.

But till this time i thought .txt, .doc .excel..开发者_如何学C. etc. were documents.(This may be funny, but i am really in need of understanding its concepts!)

How do you represent a txt file for example example.txt in mongoDB?

What is collection?

Collection of documents is known as "Collections in mongoDB"

How many collections i can create?

All documents were shared in all collections

Finnaly i come to my part, How shall i represent images in mongoDB?

With the help of tutorials i learned to store and retrieve images from mongoDB using java!!

But, without the understanding of mongoDB's concepts i cannot move further!

The blog's and articles about mongoDB is pretty interesting. But still i am not able to understand its basic concepts!!!

Can anyone strike my head with mongoDB!!??


Perhaps comparing MongoDB to SQL would help you ...

In SQL queries work against tables, columns & rows in set-based operations. There are pre-defined schema's (and hopefully indexes) to aid the query processor (as well as the querier!)

SQL Table / Rows

id  | Column1 | Column2
-----------------------
 1  | aaaaa   | Bill
 2  | bbbbb   | Sally
 3  | ccccc   | Kyle

SQL Query

SELECT * FROM Table1 WHERE Column1 = 'aaaaa' ORDER BY Column2 DESC

This query would return all the columns in the table named Table1 where the column named Column1 has a value of aaaaa it then will order the results by the value of Column2 and return the results in descending order to the client.

MongoDB

In MongoDB there are no tables, columns or rows ... instead their are Collections (these are like tables) and Documents inside the Collections (like rows.)

MongoDB Collection / Documents

{
 "_id" : ObjectId("497ce96f395f2f052a494fd4"),
 "attribute1" : "aaaaa",
 "attribute2" : "Bill",
 "randomAttribute" : "I am different"
}
{
 "_id" : ObjectId("497ce96f395f2f052a494fd5"),
 "attribute1" : "bbbbb",
 "attribute2" : "Sally"
}
{
 "_id" : ObjectId("497ce96f395f2f052a494fd6"),
 "attribute1" : "ccccc",
 "attribute2" : "Kyle"
}

However there is no predefined "table structure" or "schema" like a SQL table. For example you can see the second document in this collection has an attribute called randomAttribute that none of the other documents have.

This is just fine, it won't affect our queries but does allow for for some very powerful things ...

The data is stored in a format called BSON which is very close to the Javascript JSON standard. You can find out more at http://bson.org/

MongoDB Query

SELECT * FROM Table1 WHERE Column1 = 'aaaaa' ORDER BY Column2 DESC

How would we do this same thing in MongoDB's Shell?

> db.collection1.find({attribute1:"aaaaa"}).sort({attribute2:-1});

Perhaps you can already see how similar a MongoDB query really is to SQL (while appearing quite different.) I have some posts up on http://learnmongo.com which might help you as well.


MongoDB is a document database : http://en.wikipedia.org/wiki/Document-oriented_database

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜