I have code where I update a document in one collection, and then in the callback updates a document in another collection. The problem is that sometimes the code in the first collection doesn’t actually update but the callback is called without any error.
Has anyone experienced anything like this before?
The code looks something like this:
const callback = (err, n) => {
if (err || n === 0) {
log.error('didnt pick player. leagueId:', leagueId);
return;
}
Teams.update(teamId, {
$addToSet: { playerIds: playerId }
});
};
const modifier = {
$push: {
draftHistory: {
pickNo: league.draftPick,
teamId: teamId,
playerId: playerId
}
},
$inc: {
draftPick: 1
},
$set: {
nextPickTill: someDate
}
};
Leagues.update(selector, modifier, callback);
The Teams doc gets updated even though the Leagues doc isn’t updated (or at least the draftHistory field in $push).