mongodb - 如何在 Loopback 4 中使用 MongoDB 扩展运算符?
问题描述
我正在使用loopback v4,我需要使用 MongoDB$unset
扩展运算符。MongoDB 连接器上的文档间接声明它可以使用(见这里),但我找不到任何关于它应该如何在我的存储库上使用的示例/文档,你有什么提示吗?
解决方案
根据文档,您需要先修改设置DataSource
。
xxx.datasource.ts
export class XxxDataSource extends juggler.DataSource {
static dataSourceName = '...';
constructor() {
super({
"name": "...",
"connector": "mongodb",
"url": "...",
"database": "...",
"allowExtendedOperators": true // <= !!!! default is false
});
}
}
xxx.controller.ts
return await this.xxxRepository.updateById(
"....id....",
{
$unset: {
test: ""
}
} as any // <= !!!! you can using `$unset` now, add `as any` to avoid type error
)
推荐阅读
- python-2.7 - 如何在 HAC 中对某些对象进行聚类,但它们具有相同的余弦相似度值
- docker - 即使没有容器映射到该端口,与 K8 pod 端口的连接是否会成功?
- git - Git 和 Intelijj IDEA 远程拉取请求
- r - R igraph 包 - 中心度和密度返回结果 > 1
- java - TestNG 中的注释是强类型的。这是什么意思?
- c++ - getline 循环禁用打印到 txt
- tfs - 导入包含任务组的任务组
- c++ - Raspberry Pi 上的 Portaudio,找不到输入流的设备
- scala - Scala:使用同名的函数和内部对象
- firebase - Flutter 从 QuerySnapshot 转换为 Future
- >>