[logstash-output-mongodb] Drop collection before insert documents

Hi there,

First of all, I would like to introduce my sinceres apologies, my ingles is not very well. I would to know if there are any way to delete the existing collection before inserting the output lines to mongodb? each new event, he would have to, before inserting the documents, delete the collection, to avoid the accumulation of repeated data in the collection. I've tryed to add an line in the mongo.rb to drop collection inside the receive(event) function, but it not works, because this function is called on loop, it means each call, the collection were dropped and the one only line stay inside the collection instead of all lines. Someone can help me?

The existing output provides no way to do that. When do you want to drop the collection? If it is when logstash starts then you could do it externally to logstash. If you want to do it every time the pipeline reloads you might be able to do it using an exec input to run the mongo shell, but logstash does not provide a guarantee that an exec input has completed before any events reach the outputs. I would be surprised if they did, but it is not impossible.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.