title: How to push an object array using mongoose
body: <p>I'm trying to push an array of objects and save changes using in-memory objects instead of <code>$push</code> command but it only accepts a single ObjectId. Is there a way of doing it? My goal is efficiency as I've got the database object in memory already.</p>
  <p>The Schema:</p>
  <pre><code>const mongoose = require(&quot;mongoose&quot;);
  
  const planejamentoSchema = new mongoose.Schema({
    user: {
      type: mongoose.Schema.Types.ObjectId,
      ref: &quot;users&quot;,
    },
    dia: Date,
    receitas: [
      {
        _id: {
          type: mongoose.Schema.Types.ObjectId,
          ref: &quot;receitas&quot;,
        },
        nome: String,
        refeicao: String,
      },
    ],
  });
  
  const Planejamentos = mongoose.model(&quot;planejamentos&quot;, planejamentoSchema);
  
  module.exports = Planejamentos;
  </code></pre>
  <p>The route with $push</p>
  <pre><code>router.post(&quot;/&quot;, tokenValidation.checkToken, (req, res) =&gt; {
    let user = req.body.user;
    let dia = req.body.dia;
  
    const query = { user, dia };
  
    Planejamentos.findOne(query).exec((err, result) =&gt; {
        // AS YOU CAN SEE, I'VE GOT TO QUERY IT AGAIN 
        // INSTEAD OF JUST result.receitas.push(req.body.receitas)
        Planejamentos.updateMany(
          query,
          {
            $push: {
              receitas: { $each: req.body.receitas },
            },
          },
          (err, result) =&gt; {
              res.send(
                `Planejamento para ${query.user} em ${query.dia} atualizado com sucesso`
              );
          }
        );
    });
  });
  </code></pre>