mongodb Modifiers(原子操作)

mongodb Modifiers(原子操作)

Modifiers(原子操作)

$set:{ $set : { field : value } }

$unset :删除,{ $unset : { field : 1} }

$inc :{ $inc : { field : value } }

$push

$pushAll :{ $pushAll : { field : value_array } }

$pull:{ $pull : { field : _value } }

$pullAll :

$addToSet:不存在则添加。

$pop:删除数组的第一个或最后一个元素。{ $pop : { field : 1 } }

$rename:{ $rename : { old_field_name : new_field_name } }

$bit – 位操作,integer类型。{$bit : { field : {and : 5}}}

$ 偏移操作符:

> t.find() { "_id" : ObjectId("4b97e62bf1d8c7152c9ccb74"), "title" : "ABC", "comments" : [ { "by" : "joe", "votes" : 3 }, { "by" : "jane", "votes" : 7 } ] }

> t.update( {'comments.by':'joe'}, {$inc:{'comments.$.votes':1}}, false, true )

> t.find() { "_id" : ObjectId("4b97e62bf1d8c7152c9ccb74"), "title" : "ABC", "comments" : [ { "by" : "joe", "votes" : 4 }, { "by" : "jane", "votes" : 7 } ] }

你可能感兴趣的:(mongodb Modifiers(原子操作))