Friday, 23 August 2013

Keep track of the children in the parent, or keep track of the parent in the children?

Keep track of the children in the parent, or keep track of the parent in
the children?

So let's say I'm creating a list with sections.
Is it preferred to keep an Array of ObjectId's in the parent element.
var listSchema = new mongoose.Schema({
sections : {type: [ObjectId], ref : "Section"}
});
Or do I just keep a reference to the parent's ObjectId in each item and
simply find
var sectionSchema = new mongoose.Schema({
list : {type: ObjectId, ref : "List"}
});
(Or both for maximum flexibility?)
I've been doing the second way, but I'm thinking I might be too stuck in
the relational DB paradigm. Because once there are multiple levels of
nesting it seems to get pretty dirty with all the callbacks to get the
data I want. And I don't really get to take advantage of the populate
function.

No comments:

Post a Comment