---
title: "mongo delete data"
author: "dikar"
date: "2011-05-04T13:23:39Z"
tags: ["MongoDB", "SQL"]
categories: ["编程语言"]
slug: "mongo-delete-data"
draft: false
lastmod: "2011-05-04T13:23:39Z"
id: 1028243
url: "https://dikar.iteye.com/blog/1028243"
---

mongo中和普通的sql一样提供了delete接口，不过针对delete有些不一样的是，被删除的数据磁盘空间不会立即释放，而是会重用

 

见 http://www.mongodb.org/display/DOCS/Excessive+Disk+Space

### Deleted Space

MongoDB maintains deleted lists of space within the datafiles when objects or collections are deleted.  This space is reused but never freed to the operating system.

To compact this space, run `db.repairDatabase()` from the mongo shell

  ![](http://www.mongodb.org/images/icons/emoticons/warning.gif) this operation will block and is slow.

When testing and investigating the size of datafiles, if your data is just test data, use `db.dropDatabase()` to clear all datafiles and start fresh.

 

 

同时针对想释放空间的用户可以看以下2篇文章的讨论

MongoDB data remove - reclaim diskspace

http://stackoverflow.com/questions/5518581/mongodb-data-remove-reclaim-diskspace

 

 

Auto compact the deleted space in mongodb

http://stackoverflow.com/questions/4555938/auto-compact-the-deleted-space-in-mongodb/4560096#4560096