我已经从Firebase导入了数据库,因此我的架构几乎没有限制。因为我的结构就是这样
user: {
...other nodes
pictures: { // this is an object, not an array
autoId: {
pictureUrl: "",
pictureNumber: 1
}
}
}
我想在我的图片对象中插入带有autoId的图片。我找到了this,并据此编写了类似的代码
User.findOneAndUpdate({'_id': userId}, {$push:{pictures: {'pictureName': pictureName, 'pictureNumber': pictureNumber}}}, {new: true}, (err, user) => {
// I am doing something here with user, no need to share
});
但这给了我以下错误
{
"errorCode": "INTERNAL_ERROR",
"errorMessage": "The field 'pictures' must be an array but is of type object in document {_id: \"00Pag7qQiVbBIOw0zn0k6HWzeo22\"}"
}
有人可以帮助我如何用猫鼬中的autoId将对象推入另一个对象内吗?