title: Removing an Object from an Array in Mongoose/MongoDB
body: <p>I'm a mongoDB rookie and having trouble removing a team object from an array in MongoDB using Mongoose. My collection for a user looks like;</p>
  
  <pre><code>{  "orders":[],
     "teams":[
        {
           "teamname":"Team One",
           "_id":{"$oid":"566a038404ebcdc344c5136c"},
           "members":[
              {
                 "firstname":"Member ",
                 "lastname":"Three",`enter code here`
                 "email":"memberthree@team.com",
                 "initials":"MT",
                 "_id":{"$oid":"566a038404ebcdc344c5136d"}
              },
           ]
        },
        {
           "teamname":"Team Two",
           "_id":{"$oid":"566a07f404ebcdc344c51370"},
           "members":[
              {
                 "firstname":"Member",
                 "lastname":"Two",
                 "email":"membertwo@team.com",
                 "initials":"MT",
                 "_id":{"$oid":"566a07f404ebcdc344c51371"}
              },
           ]
        },
        {
           "teamname":"Team Three",
           "_id":{"$oid":"566a083504ebcdc344c51373"},
           "members":[
              {
                 "firstname":"Member",
                 "lastname":"Four",
                 "email":"memberfour@team.com",
                 "initials":"MF",
                 "_id":{"$oid":"566a083504ebcdc344c51374"}
              },
           ]
        }
     ],
  } 
  </code></pre>
  
  <p>And my removal route looks like;</p>
  
  <pre><code>exports.getTeamDelete = function(req, res) {
  
    User.findById(req.user.id, function(err, user) {
      if (err) return next(err);
      var selectedTeamIndex;
      for (i = 0; i &lt; user.teams.length; i++){
        if (user.teams[i]._id==req.params.teamid){
          selectedTeamIndex=i;
          break
        }
      }
  
      console.log("before", user.teams)
      console.log(req.params.teamid)
  
      teamID=req.params.teamid;
      userID=req.user.id;
  
      User.update(
      {'_id': userID},
      { $pull: { "teams" : { teamID } } },
      { multi: true },
                   function(err, data){
                        console.log(err, data);
                   }
      );
  
      user.markModified("teams");
      user.save(function(err) {
        console.log("after", user.teams)
        if (err) return next(err);
        req.flash('success', { msg: 'Team deleted' });
      });
    });
  };
  </code></pre>
  
  <p>The console logs before and and after the User.update are exactly the same and I get no errors thrown.  The output of console.log(err,data) ends up being </p>
  
  <pre><code>null { ok: 1, nModified: 0, n: 1 } 
  </code></pre>
  
  <p>which I'm not really sure how to interpret.  I've tried also not passing in the userID as suggested here;<a href="https://stackoverflow.com/a/24289161/574869">https://stackoverflow.com/a/24289161/574869</a>  to no avail(same results). Additionally I've tried doing the user update as;</p>
  
  <pre><code>User.update(
      {'_id': userID},
      { $pull: { "teams" : { id: teamID } } },
      false,
      true
  );
  </code></pre>
  
  <p>as mentioned here <a href="https://stackoverflow.com/a/15641895/574869">https://stackoverflow.com/a/15641895/574869</a> which results in and error of;</p>
  
  <pre><code>    /Users/markbreneman/Desktop/GatherRoundApp/node_modules/mongoose/lib/query.js:2022
        oldCb(error, result ? result.result : { ok: 0, n: 0, nModified: 0 });
        ^
  
  TypeError: oldCb is not a function
  </code></pre>
  
  <p>which I'm also not sure how to interpret.  If anyone's got any insights into what I'm doing wrong, or how to easily remove a team from my teams array I'd be greatful.</p>