数组中的TypeScript + mongoose对象删除

时间:2016-08-04 13:01:09

标签: node.js typescript interface mongoose

我在使用_id /

从数组中删除对象时遇到了一些困难

USchema.ts

export interface IPayments {
value: string;
name: string;
}

export interface IUser {
    username: string;
    password: string;
    payments: Array<IPayments>;
}
var User = new Schema({    
    username: { type: String, required: true, unique: true },
    password: { type: String, required: true },
    payments: [{
        value: { type: String},
        name: { type: String}
    }]

export interface UserDocument extends IUser, mongoose.Document {
   _id: string;
}

export var userSchema = User;
export let userModel: mongoose.Model<UserDocument> = mongoose.model<UserDocument>('User', userSchema);

Main.ts

//delete elem from array "payments".
let payment_id = new mongoose.Types.ObjectId(req.payment);
let user = userModel.findOne({'_id': uid}).exec();
    user.then((user)=>{
        user.paymens.remove(payment_id);
        user.save();
     });

删除工作正常,但TypeScript说

  

财产&#39;删除&#39;在IPayments类型

上不存在

我尝试添加这个&#34;属性&#34;接口,但仍然没有接触

0 个答案:

没有答案