Mongoose updateOne使用相似的名称更新两个属性
我正在用updateOne更新一个属性的值,但会影响其他具有类似名称的属性。使用猫鼬5.9.9Mongoose updateOne使用相似的名称更新两个属性,mongoose,Mongoose,我正在用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.
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方法 常量筛选器={u id:'5E969E2E43C243470C19F67'}; 常数更新={ 文件\图像\预览:'http://localhost/image371updated_preview.jpg' }; file.findOneAndUpdatefilter,更新;