使用feathersJs和Reactjs更新嵌套在数组中的对象中的项



我的后端使用feathersjs,我的用户服务/集合类似于这样:

{ name :'my Name',
email: 'example@gmail.com',
_id "9878787977377827..."
students:[
{name: 'student 1 name', _id: 2113232..., active: true},
{name: 'student 2 name', _id: 2113232..., active: true}
]
}

例如,我想将学生一的活跃状态更改为虚假状态。我试过这个

client.service('users').update({ 'students._id': id },
{$set: {'students.$.active': false,}},function (err, model) {if (err) {console.log(err);}})

但似乎什么都不起作用

如果你在这里,我可以使用这个查询来修补子文档(学生(

const query = { "subdoc._id": id }
client.service('users').patch(mainDoc._id, { "students.$.active": false 
}, { query });

就我而言;

const query = { "students._id": id }
client.service('users').patch(user._id, { "students.$.active": false 
}, { query });

为了修补我的学生数组中的一个特定对象,我传入了作为用户的主文档的id_id和嵌套对象的_id,即学生的_id,然后我将student.active设置为false。谢谢

如果仍然感到困惑,请点击此链接。https://github.com/feathersjs-ecosystem/feathers-mongoose/issues/208

最新更新