function Unsubscribe(teamName, channelName, fbID){
	console.log("Attempting to unsubscribe " + fbID + " to channel " + channelName + " of team " + teamName + ".");
	//Get team ID
	groups.findOne( { $and: [ {TEAM_NAME: teamName}, {CHANNEL_NAME: channelName} ] }, function(err, doc){
		//stop if the user is not signed into the team
		if(doc === null){
			console.error(fbID + " is not subscribed to channel " + channelName + " of team " + teamName);
			sendTextMessage(fbID, "You are not subscribed to channel " + channelName + " of team " + teamName);
			return;
		}
		console.log("Removing " + fbID + " from exisitng database entry.");
		groups.update( { $and: [ {TEAM_NAME: teamName}, {CHANNEL_NAME: channelName} ] },
			{ $pull: {USERS: fbID} }, {returnUpdatedDocs: true}, function (err, numAffected, updatedDoc){
				if(updatedDoc.USERS.length === 0){
				groups.remove( { $and: [ {TEAM_NAME: teamName}, {CHANNEL_NAME: channelName} ] }, {}, function (){} );
				}
		} );
			sendTextMessage(fbID, "You are now unsubscribed from channel " + channelName + " in team " + teamName);
	} );
}
//Postconditions: the user is subscribed to channelName by adding their fbID to the appropriate database entry
the user is subscribed to channelName by adding their fbID to the appropriate database entry
the user is subscribed to channelName by adding their fbID to the appropriate database entry
function Unsubscribe(teamName, channelName, fbID){
	console.log("Attempting to unsubscribe " + fbID + " to channel " + channelName + " of team " + teamName + ".");
	groups.findOne( { $and: [ {TEAM_NAME: teamName}, {CHANNEL_NAME: channelName} ] }, function(err, doc){
		if(doc === null){
			console.error(fbID + " is not subscribed to channel " + channelName + " of team " + teamName);
			sendTextMessage(fbID, "You are not subscribed to channel " + channelName + " of team " + teamName);
			return;
		}
		console.log("Removing " + fbID + " from exisitng database entry.");
		groups.update( { $and: [ {TEAM_NAME: teamName}, {CHANNEL_NAME: channelName} ] },
			{ $pull: {USERS: fbID} }, {returnUpdatedDocs: true}, function (err, numAffected, updatedDoc){
				if(updatedDoc.USERS.length === 0){
				groups.remove( { $and: [ {TEAM_NAME: teamName}, {CHANNEL_NAME: channelName} ] }, {}, function (){} );
				}
		} );
			sendTextMessage(fbID, "You are now unsubscribed from channel " + channelName + " in team " + teamName);
	} );
}
function Unsubscribe ( teamName , channelName , fbID ) { console . log ( "Attempting to unsubscribe " + fbID + " to channel " + channelName + " of team " + teamName + "." ) ; groups . findOne ( { $and : [ { TEAM_NAME : teamName } , { CHANNEL_NAME : channelName } ] } , function ( err , doc ) { if ( doc === null ) { console . error ( fbID + " is not subscribed to channel " + channelName + " of team " + teamName ) ; sendTextMessage ( fbID , "You are not subscribed to channel " + channelName + " of team " + teamName ) ; return ; } console . log ( "Removing " + fbID + " from exisitng database entry." ) ; groups . update ( { $and : [ { TEAM_NAME : teamName } , { CHANNEL_NAME : channelName } ] } , { $pull : { USERS : fbID } } , { returnUpdatedDocs : true } , function ( err , numAffected , updatedDoc ) { if ( updatedDoc . USERS . length === 0 ) { groups . remove ( { $and : [ { TEAM_NAME : teamName } , { CHANNEL_NAME : channelName } ] } , { } , function ( ) { } ) ; } } ) ; sendTextMessage ( fbID , "You are now unsubscribed from channel " + channelName + " in team " + teamName ) ; } ) ; }
Postconditions: the user is subscribed to channelName by adding their fbID to the appropriate database entry
Postconditions : the user is subscribed to channelName by adding their fbID to the appropriate database entry
//Get team ID //stop if the user is not signed into the team