【MonogoDB】The high update operation of MongoDB

來源:互聯網
上載者:User

標籤:mongodb

In the last four blog, we talked about the high query operation of mongodb. Now in this blog let‘s know about the high update operation about monodb.

1. Saveas for save(), whose function is to update the existing record and to create the new record.
grammar: db.mycollection.save(x);
2. General Operation2.1 $inc grammar: { $inc : { field : value } }
function: add the value to the certain field. 
example: 

2.2 $Set and $unset{ $set : { field : value } }  /  { $unset : { field : 1 } } 
function: set the field value, if the field does not exist, then add the new field, and value will support all the type. 


2.3 $push, $pushAll,$addToSet{ $push : { field : value }  } 
function: if the field is a existing arry, this function will add the value to the end.  if filed doesnot exist, it will add the new field, and then set the field value.  if field do exists but not array, it will throw error. 
$pushAll:  { $pushAll : {field : value_array } } 
this function is the same as $push, but only the value_array is array.
$addToSet: { $addToSet : { field : value } }


2.4   $pop and $pull $pullAll

2.5 $rename{ $rename : { old_friend_name: new_field_name}}



【MonogoDB】The high update operation of MongoDB

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.