Users.findOneAndUpdate({
user_id: user_id
}, {
$push: {
"chat.$[item].record": {
"role": 'me',
"item_record": item_record,
"item_time": item_time
}
}
}, {
arrayFilters: [{
"item":{
$type:"object"
},
"item.ta_id": ta_id
}]
}, function(err) {
if (err) {
...........
} else {
...........
}
})
})
在先前的本地测试中没有任何问题,就是利用arrayFilters,简单地插入数据到特定的位置,但是现在报错了,非常离谱...
{ MongoError: exception: cannot use the part (chat of chat.$[item].record) to traverse the element ({chat: [ { is_hiden: false, ta_id: "1619759159250", ta_img: "/public/image/users/test.png", me_id: "1619758422666", record: [ { role: "ta", item_record: "(你好)" } ], char_time: 1619941310624.0 } ]})