如何在 Loopback 4 存储库中调用 MongoDB 的“$inc”?
How is MongoDB's "$inc" called in a Loopback 4 repository?
我正在尝试使用 Typescript 和 loopback-connector-mongodb 库执行以下操作,但出现错误 Object literal may only specify known properties
.
interface Foo {
likes: number;
}
// increase likes with MongoDB's '$inc'
async increaseLikes(id: string): Promise<void> {
await this.fooRepository.updateById(id, {"$inc": {likes: 1}})
}
这是一个 Typescript 编译错误,即使代码有效 Javascript.
可以使用 // @ts-ignore
抑制错误
interface Foo {
likes: number;
}
// increase likes with MongoDB's '$inc'
async increaseLikes(id: string): Promise<void> {
// error suppressed to allow use of MongoDB's extended operators
// @ts-ignore
await this.fooRepository.updateById(id, {$inc: {likes: 1}})
}
我正在尝试使用 Typescript 和 loopback-connector-mongodb 库执行以下操作,但出现错误 Object literal may only specify known properties
.
interface Foo {
likes: number;
}
// increase likes with MongoDB's '$inc'
async increaseLikes(id: string): Promise<void> {
await this.fooRepository.updateById(id, {"$inc": {likes: 1}})
}
这是一个 Typescript 编译错误,即使代码有效 Javascript.
可以使用 // @ts-ignore
interface Foo {
likes: number;
}
// increase likes with MongoDB's '$inc'
async increaseLikes(id: string): Promise<void> {
// error suppressed to allow use of MongoDB's extended operators
// @ts-ignore
await this.fooRepository.updateById(id, {$inc: {likes: 1}})
}