简体   繁体   English

我如何将 object 推入 object 内的数组,该数组也在另一个数组内

[英]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.

相关问题 如何将一个数组推入另一个数组内部的对象中? - How to push an array into an Object which is inside of another array? 如何将 object 插入到 object 内的数组中? - How to insert an object into an array which is inside an object? 图像路径在 React 中不起作用,因为我尝试在 object 中使用图像路径,它也在数组内部 - Image path not working in React as I tried to use use Image path inside an object which is also inside of an array 如何访问对象数组内的对象,该对象数组在JavaScript中的另一个数组内? - how to access object inside an object Array which is inside another array in javascript? 如何将元素推入 Mongoose 中另一个数组中的 object 中的数组? - How to push an element into an array inside an object inside another array in Mongoose? 如何遍历 object 数组,该数组位于 object 中,作为 v-for 中的列表 - How do I iterate through a array of object which is inside an object as a list in v-for 获取对象数组内的值,该值是另一个对象内的值 - get the value that is inside an array of objects which is a value inside another object 如何推送到对象内部的数组,MongoDB 的数组内部? - How do you push to an array inside of an object, inside of an array with MongoDB? 如何获取对象内部的数组大小? - How to get array size which is inside an object? 如何在 Z0ECD11C1D7A287401D148A23BBD7A2 数组中的 object 中获取 JSON object - How to get JSON object inside an object which is inside JSON array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM