title: How do I create a number of objects with insertMany with existing data from the db?
body: <p>I'm currently trying to insert a large number of models through insertMany, but I can't seem to figure out how to populate the array when creating an object. I'm relatively new to Mongoose and any help would be appreciated, here is the code I have right now.</p>
  <pre><code>const ProgramsSchema = new mongoose.Schema({
     program_id: {
         type: String,
         required: true
     },
     description: {
         type: String
     },
  });
  </code></pre>
  <pre><code>const schoolsSchema = new mongoose.Schema({
      inst_url: {
          type: String
      },
      programs: {
          type: [{type: ProgramsSchema, ref: &quot;Programs&quot;}]
      }
  });
  </code></pre>
  <p>And here's the code where I try to create a number of schools and add it to the database.</p>
  <pre><code>let new_schools = []
  for (let i = 0; i &lt; schools.length; i++) {
    let school = schools[i]
    let p_arr = []
    for (let p_index = 0; p_index &lt; school[&quot;PROGRAMS&quot;].length; p_index++) {
       let p_id = school[&quot;PROGRAMS&quot;][p_index]
        Programs.find({program_id: p_id}).populate('Programs').exec(function(err, data) {
        if (err) {
          console.log(err);
        } else {
          p_arr.push(data[0])
        }
      })
    }
    let newSchool = {
      inst_url: school[&quot;INSTURL&quot;],
      programs: p_arr,
    }
    new_schools.push(newSchool);
  }
  
  Schools.insertMany(new_schools);
  </code></pre>
  <p>I can basically add all of the school data into the db, but none of the programs are being populated. I was wondering if there was a way to do this and what the best practice was. Please let me know if you guys need more info or if my question wasn't clear.</p>