mongoose.findByIdAndUpdate 只会保存被推入数组的对象的第一个键值

mongoose.findByIdAndUpdate will only save the first key-value of object being pushed into array

我有一个简单的对象,它在内部存储两个值,每个值都是来自客户端发送的数据的 req.body 值。

const pushedVote = {
      answer: req.body.answer, 
      text: req.body.value
    }

现在,当我调用 findByIdAndUpdate 方法时,它看起来像这样(Poll 是我的模型)

//insert answer and text 
    await Poll.findByIdAndUpdate(req.body.id, {
      $push: {
        responseAnswers: pushedVote,
      },
    });

一切正常,但奇怪的是我数据库中更新的数组将只存储对象中的第一个键值对。例如,如果正在存储的 pushedVote 对象的答案为 'A',文本为 'Cat',则数据库将只存储 'A',而不是 'Cat'。我在这里遗漏了什么吗?

根据我的评论,确保 text 属性 在 Mongoose 模式中定义,否则它不会保存到数据库中。