Truncates capped collections. captrunc is an internal command to support testing that takes the following form:

{ captrunc: "<collection>", n: <integer>, inc: <true|false> }.

captrunc has the following fields:

Field Type Description
captrunc string The name of the collection to truncate.
n integer The number of documents to remove from the collection.
inc boolean Specifies whether to truncate the nth document.


captrunc is an internal command that is not enabled by default. captrunc must be enabled by using --setParameter enableTestCommands=1 on the mongod command line. captrunc cannot be enabled during run-time.


The following command truncates 10 older documents from the collection records:

db.runCommand({captrunc: "records" , n: 10})

The following command truncates 100 documents and the 101st document:

db.runCommand({captrunc: "records", n: 100, inc: true})