title: Node mongoose move one array element into another array
body: <p>I currently have a UserSchema that looks as follows:</p>
  
  <pre><code>UserSchema = new mongoose.Schema({
      username: String,
      email:  String,
      password: String,
      pendingFriends: [this],
      friends: [this]
  })
  </code></pre>
  
  <p>Given a username, how would I move a record from the pendingFriends array into the friends array? This would take place in the currently logged in user's schema. This is a route I currently have for putting a friend into the pendingFriends array:</p>
  
  <pre><code>app.post("/addFriend", function(req, res) {
  var conditions = {
      username: req.body.globalUserName,
      'pendingFriends._id': {$ne: req.user._id},
      'friends._id': {$ne: req.user._id}
  }
  var update = {
      $addToSet: {pendingFriends: { _id: req.user._id, username: req.user.username, language: req.user.language, profilePicture: req.user.profilePicture}}
  }
  
  User.findOneAndUpdate(conditions, update, function(error, doc) {
      if(error) {
          console.log(currentTime + " - FRIEND_REQUEST_SEND_ERROR: '" + req.user.username + "' TRIED TO SEND A FRIEND REQUEST TO '" + req.body.globalUserName + "'");
      }
      else {
          console.log(currentTime + " - FRIEND_REQUEST_SENT: '" + req.user.username + "' SENT A FRIEND REQUEST TO '" + req.body.globalUserName + "'");
      }
      res.redirect("/talk");
  });
  </code></pre>
  
  <p>});</p>