title: How to create and update referenced documents with mongoose?
body: <p>I have this setup</p>
  <pre><code>var NotesSchema = new mongoose.Schema({
      title: String,
      category: [{  type: mongoose.ObjectId, ref: &quot;Categories&quot;, default: [] }],
  },{ timestamps: { createdAt: 'created_at' } });
  var CategoriesSchema = new Schema({
      name: {type: String, required: true}
  })
  
  var Notes = mongoose.model('Notes', NotesSchema);
  var Cat = mongoose.model('Categories', CategoriesSchema);
  </code></pre>
  <p>If I want to create a new note and categories I do this</p>
  <pre><code>.get('/new', async (req, res) =&gt; {
      var post1=  {
          title : &quot;Post: books, thriller, crime and classics&quot;,      
          favorite : true,
          categories:[ 'thriller', 'books']
      } 
      try{ 
          var note = post1.categories.map(  (cat)=&gt;{
              var ca = new Cat({name: cat})
              ca.save()
              return ca._id
          })
          post1.category = note 
          const newNote = new Notes(post1);
          const n = await newNote.save()
          res.send(n)
      } catch(error) {
          console.error(error);
      }; 
  })
  </code></pre>
  <p>If I were to create a new note that has some new categories I'm stuck.</p>
  <pre><code>var post1=  {
         ...
          categories:[ 'thriller', 'books', 'classics']
      }
  </code></pre>
  <p>'thriller' and 'books' already exist, but 'classics' doesn't.</p>
  <p>I tried <code>Cat.find({&quot;name&quot;: {$in: post1.categories}}).exec()</code> but I can't seem to look through that data.</p>
  <p>All the example tutorials seem to just add one new entry at a time.</p>