MongoDB--資料庫與Collection注意事項

來源:互聯網
上載者:User

標籤:com   存在   .com   返回   不同的   mongod   欄位   ace   建立   

<h2>
    <strong>注意事項:</strong>
</h2>
1、資料庫名注意應該全部小寫,不能包含空格,最大長度為64K名稱<br />
2、資料庫儲存為多個檔案,庫名:Per ,檔案:Per1、Per2 等,庫名:Sun ,檔案:Sun1、Sun2 等,但是單個檔案最大為2G<br />
3、集合和索引對應的命名空間中繼資料儲存在.ns檔案中<br />
<br />
<br />

<h2>
    表:
</h2>
1、儲存的資料欄位為強型別,“age”與“Age”是兩個不同的屬性<br />
2、同一行資料的列明不能重複<br />
3、列名是有順序的,相同列名與內容,順序不同為2條記錄,{“name”:1,&quot;age&quot;:2} &nbsp;與 {&quot;age&quot;:2,“name”:1} 是兩條記錄<br />
4、盡量將相同結構的文檔放在一個集合裡面,因為建立的索引頁會有結構。不同結構的資料會影響索引效率<br />
5、db.createCollection(&quot;XXXXX&quot;) 建立集合<br />
6、當執行個體啟動的時候 加上--objcheck 選項的時候,會對象資料庫插入的內容做校正,無效的格式不允許插入<br />
7、{“$addToSet”:{“emails”:“[email protected]”}} &nbsp;如果集合存在則不進行添加,如果不存在則進行建立<br />
8、$addToSet 與 $each 組合使用 {“$addToSet”:{“emails”:{“$each”:[&quot;[email protected]&quot;,&quot;[email protected]&quot;]}}} ,大量新增,並且進行是否存在判斷。<br />
9、$pop 數組刪除操作 {&quot;$pop&quot;:{&quot;emails&quot;:-1}} 開頭刪除一個 {&quot;$pop&quot;:{&quot;emails&quot;:1}} 結尾刪除一個<br />
10、數組可以使用下標index進行修改 db.sun.update({&quot;name&quot;:&quot;sun&quot;},{“$set”:{&quot;like.0&quot;:&quot;haha&quot;}}) &nbsp;修改like數組裡面第一個資料<br />
11、數組集合的內容還可以根據條件進行更新,使用$符號<br />
<span style="white-space:pre"></span>db.sun.update({&quot;address.city&quot;:&quot;shanghai&quot;},{&quot;$set&quot;:{&quot;address.$.state&quot;:&quot;HH&quot;}})<br />
<span style="white-space:pre"></span>根據子物件條件搜尋,修改子物件<br />
12、update 方法,第3個參數為不存在則進行建立,第4個參數為是否可以進行批量修改,預設為根據查詢器修改匹配到的第一條<br />
13、db.runCommand({getLastError:1}) 擷取上一次更新的情況<br />
14、findAndModify() &nbsp;//查詢後,執行更新或者刪除,<br />
<span style="white-space:pre"></span>db.runCommand({&quot;findAndModify&quot;:&quot;表名&quot;,<br />
<span style="white-space:pre"></span>&quot;query&quot;:&quot;查詢條件&quot;,<br />
<span style="white-space:pre"></span>&quot;sort&quot;:&quot;排序條件&quot;,<br />
<span style="white-space:pre"></span>&quot;update&quot;:&quot;根據查詢條件更新的內容&quot;<br />
<span style="white-space:pre"></span>&quot;remove&quot;:false,//&quot;刪除和更新只能存在一個&quot;<br />
<span style="white-space:pre"></span>&quot;new&quot;:false //返回的記錄是更新前還是更新後的})

MongoDB--資料庫與Collection注意事項

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.