title: How to link a collection with user?
body: <p>I am working on MEAN application(Angular2+). I want to maintain a seprate data for each user. As of now the data are like anyone can view any of the details but i want like, If i login and enter details, only I can view those details. Basically I want to link user collection with other collection. Since I am new to Mongo, I have no idea about this.</p>
  
  <p>user.ts</p>
  
  <pre><code>  import * as mongoose from 'mongoose'
    const userSchema = new mongoose.Schema({
    username: String,
    email: { type: String, unique: true, lowercase: true, trim: true },
    password: String,
    role: String
    });
  </code></pre>
  
  <p>cat.ts</p>
  
  <pre><code>import * as mongoose from 'mongoose';
  const catSchema = new mongoose.Schema({
  name : String,
  height: String,
  weight: String,
  });
  </code></pre>
  
  <p>I have no idea what is this</p>
  
  <p>base.ts</p>
  
  <pre><code>abstract class BaseCtrl {
  abstract model: any;
  
  // Get all
  getAll = (req, res) =&gt; {
  this.model.find({}, (err, docs) =&gt; {
    if (err) { return console.error(err); }
    res.json(docs);
  });
   }
  
  // Count all
  count = (req, res) =&gt; {
  this.model.count((err, count) =&gt; {
    if (err) { return console.error(err); }
    res.json(count);
  });
   }
  
  // Insert
  insert = (req, res) =&gt; {
  const obj = new this.model(req.body);
  obj.save((err, item) =&gt; {
    // 11000 is the code for duplicate key error
    if (err &amp;&amp; err.code === 11000) {
      res.sendStatus(400);
      }
    if (err) {
      return console.error(err);
     }
    res.status(200).json(item);
    });
    }
  // Get by id
  get = (req, res) =&gt; {
  this.model.findOne({ _id: 'req.params.id '}, (err, obj) =&gt; {
    if (err) { return console.error(err); }
    res.json(obj);
    });
    }
  
  // Update by id
  update = (req, res) =&gt; {
  this.model.findOneAndUpdate({ _id: req.params.id }, req.body, (err) =&gt; {
    if (err) { return console.error(err); }
    res.sendStatus(200);
  });
  }
  
   // Delete by id
   delete = (req, res) =&gt; {
  this.model.findOneAndRemove({ _id: req.params.id }, (err) =&gt; {
    if (err) { return console.error(err); }
    res.sendStatus(200);
   });
   }
   }
  
  export default BaseCtrl;
  </code></pre>
  
  <p>Reference project : <strong><a href="https://github.com/DavideViolante/Angular-Full-Stack" rel="nofollow noreferrer">https://github.com/DavideViolante/Angular-Full-Stack</a></strong></p>