Currently, I am implementing a blog application with nodejs/expressjs and
mongoDB (+mongoose) as a database. It works fine so far but now I am trying
to implement nested/threaded comments.
As I read about the different ways how to store such comments in
mongoDB I will store each comment in a separate document to retain
flexiblity.
In contrast to store all comments embedded in a thread I will retrieve
my comments in a unordered form from the DB with references to each parent…
Materialized paths would be an alternative but then, indexing can be problematic
due to their length.
I am planning to to the actual sorting client side when rendering
the comments – a good idea?
I read about backboneJS (relational) and ask myself if
this is a suitable tool that can help to implement it.
Yes storing the comments as separate documents in Mongo would be fine. Keyed lookups are generally fast in Mongo so maintaining a separate normalized structure of Threads and Comments should work.
Backbone is a good framework if you’re building a single page app. Additionally I’d suggest looking at Backbone Marionette. It’s an extension that makes a lot of cool things possible (good documentation too).