Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set max on mongo capped collection

Tags:

mongodb

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?

like image 911
trimbletodd Avatar asked Nov 08 '12 16:11

trimbletodd


1 Answers

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/

like image 106
Brian Cajes Avatar answered Oct 13 '22 23:10

Brian Cajes