diff --git a/lib/logstash/outputs/mongodb.rb b/lib/logstash/outputs/mongodb.rb index ce853a8..c80cdeb 100644 --- a/lib/logstash/outputs/mongodb.rb +++ b/lib/logstash/outputs/mongodb.rb @@ -63,6 +63,14 @@ def receive(event) # and generate a new primary key. # If the duplicate key error is on another field, we have no way # to fix the issue. + elsif e.message =~ /^not authorized/ + # Sometime worker cannot login when first insert. + # Re-login can resolve this not authorized problem. + @logger.warn("Not authorized, re-login...") + conn = Mongo::Client.new(@uri) + @db = conn.use(@database) + sleep @retry_delay + retry else sleep @retry_delay retry