Subcircuits on mongoose without arrays

So, I was interested, although I realized that you cannot create a separate subdocument, I would still like to create a sub-document in order to correctly use standard and other types of mongooses, is there a way still doing this thing?

eg:

var SomeOtherScheme = new Schema({ a : { type:String, default:'test' }, b : { type:Boolean, default:false } ... }); var GroupSettings = new Schema({ x : { type:Number, default:20 }, y : { type:Boolean, default:false }, ... else : { type:SomeOtherScheme, default:SomeOtherScheme } }); var Group = new Schema({ name : { type:String , required:true, unique:true}, description : { type:String, required:true }, ... settings : {type:GroupSettings,default:GroupSettings} }); 
+1
javascript mongodb mongoose document
source share
1 answer

The schema of built-in objects must be defined using simple objects, so if you want the definitions to be separated, you can do it like:

 var SomeOther = { a : { type:String, default:'test' }, b : { type:Boolean, default:false } ... }; var SomeOtherSchema = new Schema(SomeOther); // Optional, if needed elsewhere var GroupSettings = { x : { type:Number, default:20 }, y : { type:Boolean, default:false }, ... else : SomeOther }; var GroupSettingSchema = new Schema(GroupSettings); // Optional, if needed elsewhere var GroupSchema = new Schema({ name : { type:String , required:true, unique:true}, description : { type:String, required:true }, ... settings : GroupSettings }); 
+1
source share

All Articles