title: How to create a Post Request for Express/Mongoose Normalized Many-to-Many relationships
body: <p>I am trying to learn how to create a Normalized many to many Post request in express/router and Mongoose.</p>
  <p>I have three collections: User, Building and Room which is also the order of parent to child documents.</p>
  <p>My Building document schema includes both User and Room id's as follows:</p>
  <pre><code>const mongoose = require('mongoose');
  
  
  const BuildingSchema = new mongoose.Schema({
   user: [
     {
       type: mongoose.Schema.Types.ObjectId,
       ref: &quot;user&quot;
     }
   ],
   room: [
     {
       type: mongoose.Schema.Types.ObjectId,
       ref: &quot;room&quot;
     }
   ],
  
  </code></pre>
  <p>My Room document schema includes the Building ID and another child document as follows:</p>
  <pre><code>const mongoose = require('mongoose');
  
  const RoomSchema = new mongoose.Schema({
    building: {
        type: mongoose.Schema.Types.ObjectId,
        ref: &quot;building&quot;
      },
    furniture: [
      {
        type: mongoose.Schema.Types.ObjectId,
        ref: &quot;furniture&quot;
      }
    ],
  </code></pre>
  <p>I am having trouble understanding how to create a post request that allows a user/users to create a Building instance and multiple Room instances associated with it after...</p>
  <p>My express code so far can create a new Building instance but I am unsure how to handle including the Room id's:</p>
  <pre><code>router.post('/createbuilding', [auth, [
    check('name', 'Building Name is required').not().isEmpty(),
   ]
  ], async (req, res) =&gt; {
      const errors = validationResult(req);
      if (!errors.isEmpty()) {
        return res.status(400).json({ errors: errors.array() });
      }
          
      const {
        name,
        type,
        website,
        location,
        bio,      
      } = req.body;
  
      const buildingFields = {
        user: req.user.id,
        //room: req.room.id,
        name,
        type,
        website: website &amp;&amp; website !== '' ? normalize(website, { forceHttps: true }) : '',
        location,
        bio
      };
  
        try {
          let building = await Building.findOneAndUpdate(
            { user: req.user.id },
            //{ room: req.room.id },
            { $set: buildingFields },
            { new: true, upsert: true }
          );
          res.json(building);
        } catch (err) {
          console.error(err.message);
          res.status(500).send('Server Error');
        }
      }
    );
  </code></pre>
  <p>Note: The references to room ID are commented out on purpose because this is what I am unsure of how to include in the Post request.</p>