updateOne - modifiedCount : 1, but no change in document

Hello everyone,
I’m hoping I can get some help with something I’ve been working on all day and can’t solve. I am attempting to $push into an embedded array using updateOne.

The response shows { acknowledged: true, modifiedCount: 1, upsertedId: null, upsertedCount: 0, matchedCount: 1 }

however, when I review the document, there is no change.

I am using
Team.updateOne({ _id: teamId, "tournaments.id": tournamentId }, { "$push" : {"tournaments.$.matches": matchIds}})

teamId and tournamentId are ObjectIds and matchIds is an array of ObjectIds that I’d like to push into the matches array. The matches array is a embedded into a tournaments array.

The Model looks like this:

const Team = new Schema({
 no: {
   type: Number,
   required: true,
   unique: true
 },
 name: String,
 tournaments: {
   id: {
     type: Schema.Types.ObjectId,
     ref: 'Tournament'
   },
   tournamentRank: Number,
   tournamentPoints: Number,
   fivbNo: Number,
   matches: [{
     type: Schema.Types.ObjectId,
     ref: 'Match'
   }]
 }
 playerA: {
   type: Schema.Types.ObjectId,
   ref: 'Player'
 },
 playerB: {
   type: Schema.Types.ObjectId,
   ref: 'Player'
 }
}

At this point the none of the teams in the Teams collection have an array called matches inside of the tournaments array. I expect the $push to create the array based on the documentation. I am confused about why it isn’t working, but also about the response that indicates it is working.

If I can get this to work, I will use it as the basis for a bulkWrite, but for now, I just want to get one update to work before I try that.

Thank you for any help out there in the community.

2 Likes