tingodb icon indicating copy to clipboard operation
tingodb copied to clipboard

how to trigger compactCollection from mongoose?

Open ElderOrb opened this issue 8 years ago • 3 comments

At the moment I'm using the following to export 'compactDatabase' and then call it from my code:

module.exports['compact'] = Q.nfbind(mongoose.connections[0].db.compactDatabase.bind(mongoose.connections[0].db));

.. but I'm not sure how to access compactCollection from mongoose. Any hints on this?

ElderOrb avatar Feb 16 '16 18:02 ElderOrb

After some debugging...

var col = mongoose.connections[0].db._cols.entries;
module.exports['compactEntries'] = Q.nfbind(col.compactCollection.bind(col))

... so the issue can probably be closed. Besides the fact that this is ugly. Would be nice to find the right way still :)

ElderOrb avatar Feb 16 '16 18:02 ElderOrb

I afraid this is only single method to do it because this is non standard function. Just in case compactionation will happens automatically after reaching certain garbage ratio.

sergeyksv avatar Feb 16 '16 18:02 sergeyksv

Thank you for quick reply! I'm ok with this method for now, but do I need to re-init compact functions in the case of re-opening mongoose connection? As for the garbage ratio, is it possible to specify it from code?

ElderOrb avatar Feb 16 '16 19:02 ElderOrb