trimbletodd
trimbletodd

Reputation: 337

Set max on mongo capped collection

I have an existing collection that I need to convert into a Capped Collection using the method listed:

> db.runCommand({"convertToCapped": "mycoll", size: 100000});

However, the max field is not accepted as a parameter

> db.mycol1.convertToCapped
function (bytes) {
    if (!bytes) {
        throw "have to specify # of bytes";
    }
    return this._dbCommand({convertToCapped: this._shortName, size: bytes});
}

Any idea how to set this?

Upvotes: 10

Views: 2519

Answers (1)

Brian Cajes
Brian Cajes

Reputation: 3402

max is only an option in the createCollection method, not convertToCapped:

db.createCollection("mycoll", {capped:true, size:100000, max:100});

There's a cloneCollectionAsCapped, but it doesn't look like there's a max doc option there either: http://docs.mongodb.org/manual/reference/command/cloneCollectionAsCapped/

You may need to create a new capped collection with the max parameter and transfer data and indices from the existing collection. See http://learnmongo.com/posts/easily-move-documents-between-collections-or-databases/

Upvotes: 7

Related Questions