node.js - Keep track of the children in the parent, or keep track of the parent in the children? -


so let's i'm creating list sections.

is preferred keep array of objectid's in parent element.

var listschema = new mongoose.schema({      sections : {type: [objectid], ref : "section"} }); 

or keep reference parent's objectid in each item , find

var sectionschema = new mongoose.schema({      list : {type: objectid, ref : "list"} }); 

(or both maximum flexibility?)

i've been doing second way, i'm thinking might stuck in relational db paradigm. because once there multiple levels of nesting seems pretty dirty callbacks data want. , don't take advantage of populate function.

assuming each object has 1 parent, it's easier keep parent id in child object.

although, if you're trying find children of object, rather parent, easier store array of children ids in parent object.

i'm not sure of availability of maps in language you're using, youcan use maps link parent ids children ids. works storing parent id key, , child id value. way, have parent id , values, or child id , parent.

this means ids not stored in either child or parent, in separate data structure they'll both need access to.

also, regular map may allow 1 value per key. if case, need multimap. there's info on internet somewhere how use , how access class.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -