I am currently doing the mongoDB tutorial on “Storing comments”…
trying to use the “one document per comment” concept.
http://docs.mongodb.org/manual/use-cases/storing-comments/
I added the following documents to my database:
a = {'discussion_id': 55, slug: '34db', full_slug: '2012.02.08.12.21.08:34db', text:'1'}
b = {'discussion_id': 66, slug: '34db/8bda', full_slug: '2012.02.08.12.21.08:34db/2012.02.09.22.19.16:8bda', text:'1.1'}
c = {'discussion_id': 77, slug: '88uz', full_slug: '2012.03.08.12.21.08:34db', text:'2'}
saved all documents im my db.test and performed:
db.test.find().sort('full_slug':1)
As it is said in the documentation:
“…you can use a simple sort on the full_slug field to retrieve a threaded view”
I wonder how that output should look like…
I only get JSON looking like:
{}
{}
{}
when I expected something more “threaded/nested” like…
{
{}
}
{}
Can you tell me if there is a problem
with my input or do I have a wrong expectation?
In case this output is fine:
How can I render the information as threaded html output?
(the order seems good but how to get the indentation information from that?)
It’s your expectation. Mongo is going to return all of the documents in an array. Any relational or conditional logic/implementation needs to be handled in code (either before insert or after select). For example:
Before inserting into mongo, calculate the correct indentation level and add another property on the document to store the calculated value.
After retrieving the documents, use context elements in each document to calculate (on the fly) the correct indentation level.