[英]How do i push an object into an array which is inside an object which is also inside an another array
I want to push an object into an array which is inside another object which is inside an array,我想将一个 object 推入一个数组,该数组位于另一个数组内的 object 内,
As in the above picture likes
= vote
I have changed that later on,如上图
likes
= vote
我后来改了,
But I am not able to push an object inside this vote array I am using this code to push into an array但是我无法将 object 推入此投票数组我正在使用此代码推入数组
Question.updateOne(
{ _id: questionId, comments: { $elemMatch: { _id: commentId } } },
{ $push: { "comments.$.vote": { userId } } }
)
I don't know what is wrong here, in the console it shows 200 status but it is not added to the database.我不知道这里出了什么问题,在控制台中它显示 200 状态但它没有添加到数据库中。
Have you tried with destructuring?你试过解构吗? ie if you have array of likes, you can do this:
即如果你有很多喜欢,你可以这样做:
myArray= [...myArray, {myNewObject: data}] myArray= [...myArray, {myNewObject: 数据}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.