Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongoose updateOne使用相似的名称更新两个属性_Mongoose - Fatal编程技术网

Mongoose updateOne使用相似的名称更新两个属性

Mongoose 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.

我正在用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方法

常量筛选器={u id:'5E969E2E43C243470C19F67'}; 常数更新={ 文件\图像\预览:'http://localhost/image371updated_preview.jpg' }; file.findOneAndUpdatefilter,更新;