0

Schema:

const userSchema = new mongoose.Schema(
  {
    images: {
      type: [{id: String, url: String, description: String, likes: []}],
    },
  },
  {
    timestamps: true,
  }
);

I want to push the user id to the likes array of a specific image object in the array (identified by the postid). The query below successfully identifies the correct document but doesn't update it:

const result = await User.findOneAndUpdate(
      {'images.id': postid},
      {$push: {likes:
              {userid}}},
)

I have also tried

const result = await User.findOneAndUpdate(
      {'images.id': postid},
      {$push: {'images.likes':
              {userid}}},
)

But neither of these approaches work.

0 Answers0