I've imported my Database from Firebase so I have few limitations in my schema. as My structure is like this
user: {
...other nodes
pictures: { // this is an object, not an array
autoId: {
pictureUrl: "",
pictureNumber: 1
}
}
}
I want to insert a picture with autoId in my pictures object. I found this and according to this I wrote my code like
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
});
but it gives me following error
{
"errorCode": "INTERNAL_ERROR",
"errorMessage": "The field 'pictures' must be an array but is of type object in document {_id: \"00Pag7qQiVbBIOw0zn0k6HWzeo22\"}"
}
Can anyone help me how to push object inside another object with autoId in mongoose?