我正在用updateOne((更新一个属性的值,但正在影响其他具有类似名称的属性。(使用猫鼬5.9.9(
var file = new Schema({
name: String,
file_image: String,
file_image_preview: String,
});
// I have this document
{
name: 'file.jpg',
file_image: 'http://localhost/image371.jpg',
file_image_preview: 'http://localhost/image371_preview.jpg',
}
// I use the updateOne method
file.updateOne({_id: '5e969e2e43c2433470c19f67'}: ,
{ $set: {
file_image_preview: 'http://localhost/image371updated_preview.jpg'
}
})
// The document is updated to this
{
name: 'file.jpg',
file_image: 'http://localhost/image371updated_preview.jpg',
file_image_preview: 'http://localhost/image371updated_preview.jpg',
}
这是命名约定的问题吗?
尝试使用findOneAndUpdate((方法
const filter = { _id: '5e969e2e43c2433470c19f67' };
const update = {
file_image_preview: 'http://localhost/image371updated_preview.jpg'
};
file.findOneAndUpdate(filter, update);
findOneAndUpdate((方法的链接