【发布时间】:2019-10-14 10:55:38
【问题描述】:
我在 mongodb 中有一个带有架构的集合:
{
"_id" : "",
"vins" : [ { "field" : "" } ],
"xyz" : "",
"password" : "",
"username" : ""
}
我想删除“vins”数组中匹配特定条件的对象。通常,使用“$pull”操作符可以很容易地做到这一点。但我找不到任何关于如何使用 TypeORM 的信息。
(值得一提的是,我几乎没有使用 typeorm 的经验,而是在我的整个职业生涯中都使用过 mongoose)。
当我尝试时
this.repo.update({ "xyz" : <value>} ,{ $pull : { "fields" : { "field": <value> } } })
我收到一个错误
类型参数 '{ $pull: { "vins": { "vin": any; }; }; }' 不可分配给“DeepPartial”类型的参数。对象字面量只能指定已知属性,而 '$pull' 不存在于 'DeepPartial' 类型中
【问题讨论】:
-
FindOneAndUpdate 看起来很简单,与猫鼬或本机驱动程序没有太大区别。你试过了吗?
-
当我尝试这个查询
this.repo.update({ "xyz" : <value>} ,{ $pull : { "fields" : { "field": <value> } } })时,打字稿编译器给出了这个错误Argument of type '{ $pull: { "vins": { "vin": any; }; }; }' is not assignable to parameter of type 'DeepPartial<User>'. Object literal may only specify known properties, and '$pull' does not exist in type 'DeepPartial<User>'。
标签: node.js mongodb typescript typeorm