我的文档中存储了一个数组:
"properties" : [
{
"createdate" : 1375981035,
"updated" : 1375981035
},
{
"accessdate" : 1375981035,
"updated" : 1375981035
},
{
"code" : "4ffa04fe06000000",
"updated" : 1375981038
}
],
执行更新以取消设置属性“代码”:
db.coll.update({'properties.code':'4ffa04fe06000000'},{'$unset':{'properties.$':1}});
我的结果是这样的:
"properties" : [
{
"createdate" : 1375981035,
"updated" : 1375981035
},
{
"accessdate" : 1375981035,
"updated" : 1375981035
},
null
],
但我希望它是这样的:
"properties" : [
{
"createdate" : 1375981035,
"updated" : 1375981035
},
{
"accessdate" : 1375981035,
"updated" : 1375981035
}
],
如果没有生成的空键,有什么更好的取消设置方法?'$pull' 更好吗?