我如何使用 typeORM、nestjs 和 mongodb 更新库存
how i can update inventory with typeORM, nestjs and mongodb
如何使用 MongoDB typeORM
执行这种查询
return await this.inventoryRepository.update(
{ id },
{ $inc: { totalInventory: -1 } },
);
相同的查询正在 mongodb shell :
db.inventory.findOneAndUpdate({id:"someidhere"},{ $inc: {totalInventory: -1}});
但是在 nextjs 服务中它给我一个错误:
Argument of type '{ $inc: { totalInventory: number; }; }' is not assignable to parameter of type 'QueryDeepPartialEntity<Inventory>'.
我用下面的代码管理这个:
async updateInventory(id: string, dif: number) {
const manager = getMongoManager();
try {
return await manager.findOneAndUpdate(
Inventory,
{ id },
{ $inc: { totalInventory: dif } },
);
} catch (err) {
console.log(err);
}
}
如何使用 MongoDB typeORM
执行这种查询return await this.inventoryRepository.update(
{ id },
{ $inc: { totalInventory: -1 } },
);
相同的查询正在 mongodb shell :
db.inventory.findOneAndUpdate({id:"someidhere"},{ $inc: {totalInventory: -1}});
但是在 nextjs 服务中它给我一个错误:
Argument of type '{ $inc: { totalInventory: number; }; }' is not assignable to parameter of type 'QueryDeepPartialEntity<Inventory>'.
我用下面的代码管理这个:
async updateInventory(id: string, dif: number) {
const manager = getMongoManager();
try {
return await manager.findOneAndUpdate(
Inventory,
{ id },
{ $inc: { totalInventory: dif } },
);
} catch (err) {
console.log(err);
}
}