发布于 2015-09-14 15:06:19 | 164 次阅读 | 评论: 0 | 来源: 网络整理
The $unset operator deletes a particular field. Consider the following example:
db.collection.update( { field: value1 }, { $unset: { field1: "" } } );
The above example deletes field1 in collection from documents where field has a value of value1. The value of the field in the $unset statement (i.e. "" above) does not impact the operation.
If documents match the initial query (e.g. { field: value1 } above) but do not have the field specified in the $unset operation (e.g. field1), then the statement has no effect on the document.