In this mongodb official guide on how to use mongodb in order to store discussion threads they suggest 3 strategies of which I chose the first one: storing each comment in its own document. In this strategy it is suggested to use full_slug
for threaded discussions. full_slug
is composed of a slug
(which is an id of some resource in a CMS like Wordpress) and a date. This way sorting on full_slug
gives results ordered hierarchically and chronologically.
In addition it's suggested to create 2 compound indices on discussion_id
and posted
fields as well as for discussion_id
and full_slug
.
Because the query to retrieve the comments sorts by full_slug
which already includes time information why do we need to create an index for discussion_id
and posted
?
In addition, if we use full_slug
doesn't this mean that the slug
part must be guaranteed to be sequentially incremented? Because if slug
is not strictly incremented then the sort will not be always correct.
Aucun commentaire:
Enregistrer un commentaire