title: How to return current user information from MongoDB in a MEVN stack app
body: <p>I am attempting to build a basic login/registration app using Vue, Express, Node, and MongoDB. I have been successful in setting up the Express router to enable registration and logging in of users, with basic user info stored in MongoDB. I am attempting to return user data back to the screen after logging in. So far, I have set up <code>router.get()</code> in Express to return the username of all users back to the screen. However, I want to configure the <code>axios.get()</code> method in Vue.js to return only the username of the logged in user, as opposed to all the user names stored in MongoDB. Normally in Firebase I would use something like <code>let snapshot = await ref.where('userid', '==', firebase.auth().currentUser.uid).get()</code> to send back info exclusively about the current user. How can I set up my <code>axios.get()</code> method to execute something similar? My code is below:</p>
  
  <p>logged in page</p>
  
  <pre><code>&lt;template&gt;
    &lt;b-row&gt;
      &lt;b-col cols="12"&gt;
        &lt;h2&gt;
          You are now logged in!
          &lt;b-link @click="logout()"&gt;(Logout)&lt;/b-link&gt;
        &lt;/h2&gt;
        &lt;table style="width:100%"&gt;
          &lt;tr&gt;
            &lt;th&gt;User Names&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr v-for="user in users" :key="user._id"&gt;
            &lt;td&gt;{{ user.username }}&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
        &lt;ul v-if="errors &amp;&amp; errors.length"&gt;
          &lt;li v-for="error of errors" :key="error._id"&gt;
            &lt;b-alert show&gt;{{error.message}}&lt;/b-alert&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/b-col&gt;
    &lt;/b-row&gt;
  &lt;/template&gt;
  
  &lt;script&gt;
  
  import axios from 'axios'
  
  export default {
    name: 'BookList',
    data () {
      return {
        users: [],
        errors: []
      }
    },
    created () {
      axios.defaults.headers.common['Authorization'] = localStorage.getItem('jwtToken')
      axios.get(`http://localhost:3000/api/auth`)
        .then(response =&gt; {
          this.users = response.data
        })
      },
      methods: {
        logout () {
          localStorage.removeItem('jwtToken')
          this.$router.push({
            name: 'Login'
          })
        }
      }
    }
    &lt;/script&gt;
  
  </code></pre>
  
  <p>GET route in Express</p>
  
  <pre><code>router.get('/', function(req, res) {
    User.find(function (err, products) {
      if (err) return next(err);
      res.json(products);
    });
  });
  </code></pre>
  
  <p>User.js</p>
  
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  var bcrypt = require('bcryptjs');
  
  var UserSchema = new Schema({
    username: {
          type: String,
          unique: true,
          required: true
      },
    password: {
          type: String,
          required: true
      }
  });
  
  UserSchema.pre('save', function (next) {
      var user = this;
      if (this.isModified('password') || this.isNew) {
          bcrypt.genSalt(10, function (err, salt) {
              if (err) {
                  return next(err);
              }
              bcrypt.hash(user.password, salt, null, function (err, hash) {
                  if (err) {
                      return next(err);
                  }
                  user.password = hash;
                  next();
              });
          });
      } else {
          return next();
      }
  });
  
  UserSchema.methods.comparePassword = function (passw, cb) {
      bcrypt.compare(passw, this.password, function (err, isMatch) {
          if (err) {
              return cb(err);
          }
          cb(null, isMatch);
      });
  };
  
  module.exports = mongoose.model('User', UserSchema);
  
  </code></pre>
  
  <p>Register route</p>
  
  <pre><code>router.post('/register', function(req, res) {
    if (!req.body.username || !req.body.password) {
      res.json({success: false, msg: 'Please pass username and password.'});
    } else {
      var newUser = new User({
        username: req.body.username,
        password: req.body.password
      });
      // save the user
      newUser.save(function(err) {
        if (err) {
          return res.json({success: false, msg: 'Username already exists.'});
        }
        res.json({success: true, msg: 'Successful created new user.'});
      });
    }
  });
  </code></pre>