title: How to make the mongoose update array work properly?
body: <p>this is my schema.it has a user field and an array of object which contains a text message and direction will hold a either sent or received value.</p>
  <pre><code>const MessageSchema = new mongoose.Schema({
    
      
          user:{type: String,required: true},
          textArray:[
              {
                  text:{type: String,required: true},
                 
                  direction:{ type: String,required: true }
                  
              }]
      
  
  });
  </code></pre>
  <p>This is the router code.btw should there be double quotes on the keys in var textmessage?</p>
  <pre><code>router.post('/',async(req,res)=&gt;{
      const {user,text,direction}=req.body;
      
      const errors = validationResult(req);
          if (!errors.isEmpty()) {
            return res.status(400).json({ errors: errors.array() });
          }
      
     
  
       
          var textmessage={
              &quot;text&quot;:text,
              &quot;direction&quot;:direction
          }
          const doc = await Message.updateOne(
              { user: user },
              { $set: { user:user,$push:{textArray:textmessage}} },
              { upsert: true },
              function(err,result){
                  if (err){
                      console.log(err);
                  }
                  else{
                      console.log(result)
                      res.send(result)
                  }// Make this update into an upsert
              });
  
        })
  </code></pre>
  <p>this is how it showsup in mongodb.the user is working ok but when i click theres is  nothing under textArray.What am I doing wrong exactly?</p>
  <p><a href="https://i.stack.imgur.com/gO2JC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gO2JC.png" alt="mongo error" /></a></p>