title: Mongoose Foregin Key mapping
body: <p>I'm new to MongoDB/Mongoose and trying to figure out how to map relationships between Schema. I don't think issue is with .populate(). At creation of new user and clients, I do not see the relationship reflected in collection</p>
  
  <p>User (login via local/social) has many Clients.
  A set of Clients belong to 1 User </p>
  
  <ol>
  <li>Is this the correct way to declare foreign key? {type: Schema.Types.ObjectId, ref: 'Client'}</li>
  <li>Should both Schema have the each other's foreign key to relate to one another? </li>
  <li>Is there any additional code required when creating User/Client in order for the data from foreign key to show up? I read something about populate() </li>
  </ol>
  
  <p>User</p>
  
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  var userSchema = new Schema({
  
  local: {
      id: String,
      email: String,
      password: String,
      name: String,
      mobile: String,
      clients: {type: Schema.Types.ObjectId, ref: 'Client'}
  
  },
  
  google: {
      id: String,
      token: String,
      email: String,
      name: String,
      clients: {type: Schema.Types.ObjectId, ref: 'Client'}
  
  }
  
  });
  module.exports = mongoose.model('User', userSchema);
  </code></pre>
  
  <p>Client</p>
  
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  
  var clientSchema = new Schema({
  
      id: String,
      firstname: String,
      lastname: String,
      mobile: String,
      user: {type: Schema.Types.ObjectId, ref: 'User'}
  
  });
  
  module.exports = mongoose.model('Client', clientSchema);
  </code></pre>
  
  <p>Create User</p>
  
  <pre><code>app.post("/api/user", function (req, res) {
  const user = req.body;
  console.log(user);
  
  User.findOne({ 'local.email': user.email },
    function (err, result) {
      if (err) {
        console.log(err);
        handleError(err, res);
        return;
      }
      if (result) {
        res.status(500).send("Email already exists in database");
      } else {
        var newUser = new User();
        newUser.local.password = generateHash(user.password);
        newUser.local.email = user.email;
        newUser.local.name = user.name;
        newUser.local.mobile = user.mobile;
        newUser.save(function (err, result) {
          res.status(201).send("User added to database");
        });
      }
  
    });
   });
  </code></pre>
  
  <p>Create Client</p>
  
  <pre><code>app.post("/api/client", function (req, res) {
  const client = req.body;
  console.log(client);
  
  Client.findOne({
    $and: [
           { firstname: client.firstname },
           { lastname: client.lastname }
         ]
  },
    function (err, result) {
      if (err) {
        console.log(err);
        handleError(err, res);
        return;
      }
      if (result) {
        res.status(500).send({msg:"Client already exists in database"});
      } else {
        var newClient = new Client();
        newClient.firstname = client.firstname;
        newClient.lastname = client.lastname;
        newClient.mobile = client.mobile;
        newClient.save(function (err, result) {
          res.status(201).send("Client added to database");
        });
      }
  
    });
  
   });
  </code></pre>