title: Subdocument not being saved in its own collection - Mongoose
body: <p>I found this on the documentation for mongoose:</p>
  <blockquote>
  <p>Subdocuments have save and validate middleware just like top-level
  documents. Calling save() on the parent document triggers the save()
  middleware for all its subdocuments, and the same for validate()
  middleware.</p>
  </blockquote>
  <p>But that hasn't been working for me. when I call save on my parent, the subdocument doesn't get created in its own collection. Here's my code:</p>
  <p><strong>Cart Model</strong></p>
  <pre><code>const mongoose = require(&quot;mongoose&quot;);
  
  const cartSchema = new mongoose.Schema({
      numOfSessions: {
          type: Number,
          required: true
      },
      status:{
          type: String,
          enum: [&quot;completed&quot;, &quot;active&quot;, &quot;deleted&quot;],
          required: true
      }
      
  }, { timestamps: true, versionKey: false });
  
  const Cart = mongoose.model('shoppingCart', cartSchema);
  module.exports = Cart;
  </code></pre>
  <p><strong>User Model</strong></p>
  <pre><code>const mongoose = require(&quot;mongoose&quot;);
  const Cart = require(&quot;./xxxx&quot;).schema
  const Schema = mongoose.Schema;
  
  
  const userSchema = new Schema({
      firstName: {
          type: String,
          required: true
      },
      lastName: {
          type: String,
          required: true
      },
      password: {
          type: String,
          required: true,
      },
      email: {
          type: String,
          required: true,
          unique: true
      },
      shoppingCarts: [ Cart ]
  }, { timestamps: true, versionKey: false });
  
  const User = mongoose.model('user', userSchema);
  module.exports = User;
  </code></pre>
  <p><strong>Server Side</strong></p>
  <pre><code>const new_user = new User({
                  firstName: req.body.firstname,
                  lastName: req.body.lastname,
                  username: req.body.username,
                  phoneNum: req.body.phone,
                  userType: req.body.userType,
                  email: req.body.email,
                  password: hashedPassword
              });
  
              new_user.shoppingCarts.push(new_cart);
              console.log('pushed')
              new_cart.save(); //If i take out this line, this subdocument doesn't get saved
              new_user.save()
                  .then((result) =&gt; {
                      console.log(result);
   });
  </code></pre>
  <p>To save the subdocument, I'm having to call save on it them well. Is this how it's supposed to be? Thx :D</p>