MongoDB Modifiers(原子操做)

mongodb Modifiers(原子操做)mongodb

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 } ] }it

相關文章
相關標籤/搜索