node.js - `$set` 可以替换 mongoDB 中 Boolean 类型的字段值吗?
问题描述
这是该问题的示例架构:
const sample = new Schema({
scope: {
type: String,
enum: ['draft', 'published'],
default: 'draft',
},
isOutOfService: {
type: Boolean,
default: false,
},
});
以及模式的示例数据:
const data = {
_id: 1,
scope: 'draft',
isOutOfService: false,
};
现在我想将字段scope
值更新为published
并将isOutOfService
值更新为true
.
我将下面的代码与猫鼬一起使用:
const updated = await sample.findOneAndUpdate({
_id: 1
}, {
$set: {
scope: 'published',
isOutOfService: true
}
}, {
new: true,
}).lean().exec();
而更新操作的结果是:
{
_id: 1,
scope: 'published',
isOutOfService: false,
}
我不知道为什么scope
被替换而isOutOfService
没有被替换?
解决方案
推荐阅读
- javascript - 从组件外部打开一个 modal 的 vue-js-modal
- vue.js - import { ipcRenderer } from 'electron' 产生此错误:__dirname is not defined
- spring-boot - Spring Boot Hystrix maximumSize 不起作用
- javascript - 具有特定数量的样式化实例的样式化组件错误
- spring - 如何使用 Jackon 和 Spring Boot 从“内容”键中解开自定义序列化对象
- reactjs - 使用 react-hook-form 引用问题
- cypress - 无法在特定位置运行测试
- flutter - 在图像上添加小部件 -flutter, dart
- python - 获取 Pandas Dataframe 中列名的排名
- python - 在 Python 中从循环创建不同的函数