I’m trying to do something like this in MongoDB:
wiki_db
|
+-- Programming --+
|
|
+-- Perl -+
|
+-- tutorials --+
|
+-- 1 --+
|
| +---- id = 1
| |
+------+---- title = Introdaction To Perl
|
+---- Date = 12/11/2100
|
+---- Content = "Perl is .... "
It’s a small database for a wiki application I’m planning to write it in perl, which :
- wiki_db : is the database.
- programming: is the main section.
- perl: is the sub section.
- tutorials: is the thread.
- 1: is the page number.
Like a tree. So, I’ve written this code to describe it :
programming = {
'perl': {
'tutorials': {
'1': {
'id':'1',
'title':'Hello World!',
'lastmod':'Sat Jul 23 14:56:22 AST 2011',
'Content': 'Hello!, This is the first page in the tutorial.'
}
}
}
}
The problem is that when I do some query, it returns nothing:
$ mongo
MongoDB shell version: 1.8.2
connecting to: test
> use wiki
switched to db wiki
> show collections
programming
system.indexes
> db.programming.findOne()
{
"_id" : ObjectId("4e2f2fadce7012941395b103"),
"perl" : {
"tutorials" : {
"1" : {
"id" : "1",
"title" : "Hello World!",
"lastmod" : "Sat Jul 23 14:56:22 AST 2011",
"Content" : "Hello!, This is the first page in the tutorial."
}
}
}
}
> db.programming.find({"perl":{"tutorials":{"1":{"id":"1"}}}})
>
What is the correct way to do write the query? and is the tree design good? I mean will that design slow down the database when the database grow up?
Do this: