CNode

mongoose $unset 删除某属性

问答
Kkingche发布于12 年前最后回复12 年前2 回复12452 浏览0 收藏

某文档的属性为

var ComSchema = new Schema({
	name : String ,
    icon_s : String ,
    icon_l : String ,
    number : Number ,
    illustrations :[ String]
});	

生成的文档为

{
name:"chat",
icon_s:"",
icon_l:"",
number:20,
illustrations:[]
}

如果想删除 icon_lnumberillustrations 属性 执行的操作

Com.update({name:"chat"},{$unset:{icon_l:1,number:1,illustrations:1}},function(err){
});

发现执行成功后,属性并没有被删除,请问该如何正确操作?

查看回复

回复 (2)

J
jysperm#1·12 年前

是否有报错在 err 里?

K
kingche#2·12 年前
引用 jysperm是否有报错在 err 里?

@jysperm

if(err) {
  console.log("modify ComModel failed.");
} else {
console.log("modify ComModel success."); 
}

没有报错,都是打印modify ComModel success.

参与回复
登录后即可参与回复。登录