0

我正在使用loopback v4,我需要使用 MongoDB$unset扩展运算符。MongoDB 连接器上的文档间接声明它可以使用(见这里),但我找不到任何关于它应该如何在我的存储库上使用的示例/文档,你有什么提示吗?

4

1 回答 1

2

根据文档,您需要先修改设置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
)

于 2019-09-06T05:06:00.037 回答