0

I need insert in a subdocument another subdocument I have seen some examples, but they only have a reach to the first level of subdocument

this is my model

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var Infonodo = require('./infonodo.model');


var personSchema = new Schema({
    rfc:         {type:String,required:true,unique:true},
    name:       {type:String,required:true},
    jobs:[
            {
              name:       {type:String,required:true},
              city:  {type:String},
              location:   {type:String},
              skills:    [
                              {
                                name:       {type:String,required:true},
                                time:     {type:String,required:true},
                                where:       {type:Number,required:true},
                                percentage:       {type:String},
                                _info:        { type: mongoose.Schema.Types.ObjectId, ref: 'Infospecific', index: true }
                              }
                            ]
            }
        ]
 });


 module.exports = mongoose.model('Person', personSchema);

I dont know how update or insert into 'skills', only I know update or insert into 'jobs'.

Specifically I need to know a specific job, and in this job update or insert diferent skills.

Can someone help me??

1 Answers1

0

Did you tried this for insertion?

var Person = require('your-module');
var person = new Person(
             { name:"Sachin Sharma"
               jobs: [ { name: 'job1' , city:'New York',
                         skills:[name "Java", time:"3 Years",_info :"02030303"]    
                       }, 
                       { name: 'job2',city:'Bangalore',
                         skills:[name "C++", time:"2 Years",_info :"02030304"]
                       }
                     ] 
              })
enRaiser
  • 2,606
  • 2
  • 21
  • 39
  • yes, but there are a lot of arrays in skills, and when I need update person.jobs, I dont know how to update specifically jobsor skills, and I need to do a reference with another model with person.jobs.skills._info – Gustavo Contreras Aug 09 '16 at 13:57