javascript - mongodb won't find my schema method in nested container -



javascript - mongodb won't find my schema method in nested container -

i trying access method of schema stored within mixed container. here situation : have cases model can many different things, have schema each of these things stored in "casecontent" mixed property.

var caseschema = mongoose.schema({ casecontent : {}, object : {type:string, default : "null"}, collision : {type : boolean, default : false} });

the casecontent property filled model of 1 of schemas, 1 exemple :

var treeschema = new mongoose.schema({ applecount : {type : number, default : 3} }); treeschema.methods.dostuff = function (data) { console.log('hey, listen'); homecoming true; };

then, want utilize method of schema original container :

caseschema.methods.dostuff = function (data) { if (this.casecontent.dostuff !== undefined) { this.casecontent.dostuff(); console.log('it worked'); } else { console.log('dostuff undefined'); console.log(this.casecontent.dostuff); } };

on first time (when added on database) works. then, casecontent.dostuff seems undefined (the console.log('dostuff undefined'); appears each time).

so think there keeps me calling method because of mixed type of container... there workarround ?

you seek utilize schema type schema.types.mixed

var caseschema = mongoose.schema({ casecontent : schema.types.mixed, object : {type:string, default : "null"}, collision : {type : boolean, default : false} });

javascript node.js mongodb mongoose

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -