MongoDB固定集合

來源:互聯網
上載者:User

標籤:sa

固定集合

MongoDB 固定集合(Capped Collections)是效能出色且有著固定大小的集合,對於大小固定,我們可以想象其就像一個環形隊列,當集合空間用完後,再插入的元素就會覆蓋最初始的頭部的元素!

特點:可以插入及更新,但更新不能超出collection的大小,否則更新失敗,不允許刪除,但是可以調用drop()刪除集合中的所有行,但是drop後需要顯式地重建集合。

回到頂部

樣本

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="margin:0px;padding:0px;border:none;" />

> db.createCollection(, {capped:, size:, max: : >> db.del_col2.insert({x: : > db.del_col2.insert({y: : > db.del_col2.insert({z: : > db.del_col2.insert({m: : > db.del_col2. : ObjectId(),  :  : ObjectId(),  : > db.del_col2.insert({n: : > db.del_col2. : ObjectId(),  :  : ObjectId(),  : > :  :  : >

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="margin:0px;padding:0px;border:none;" />

轉化為固定集合

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="margin:0px;padding:0px;border:none;" />

> db.col2.find(){ "_id" : ObjectId("56c6cfd164799370c0ef35a2"), "x" : 1 }{ "_id" : ObjectId("56c6cfd664799370c0ef35a3"), "y" : 2 }{ "_id" : ObjectId("56c6cfdf64799370c0ef35a4"), "z" : 3 }> db.col2.isCapped()false> db.runCommand({"convertToCapped":"col2", size:1000}){ "ok" : 1 }> db.col2.isCapped()true


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.