# Logstash MongoDB Output Plugin - command insert requires authentication

**URL:** <https://discuss.elastic.co/t/logstash-mongodb-output-plugin-command-insert-requires-authentication/268265>\
**Category:** Logstash\
**Created:** [March 24, 2021, 9:05pm UTC](https://discuss.elastic.co/t/logstash-mongodb-output-plugin-command-insert-requires-authentication/268265 "2021-03-24T21:05:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![christiancj](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@christiancj](https://discuss.elastic.co/u/christiancj)\
**Post date:** [March 24, 2021, 9:05pm UTC](https://discuss.elastic.co/t/logstash-mongodb-output-plugin-command-insert-requires-authentication/268265/1 "2021-03-24T21:05:42Z")

</div>

I'm using logstash 7.10.2 with MongoDB logstash-output plugin (tested 2 diff versions), I'm trying to write documents from elastic to mongodb, however I'm getting the following errors for each version,

plugin version **logstash-output-mongodb (3.1.5)**

```auto
[2021-03-24T16:28:04,774][DEBUG][logstash.outputs.mongodb][main][875e71ebe6badsfddsdf06ff929e4fasadfsd34535435b35sdfsd919asfdsafsf9c] MONGODB | COMMAND | namespace=MyMongoDB.$cmd selector={:insert=>"myMongoCollection", :docu
ments=>[{"field_1"=>"value", "@version"=>"1", "@timestamp"=>"\"2021-03-24T20:27:43.100Z\"", "field_2"=>"value", "field_3"=>"value", "field_4"=>"value", ... flags=[] limit=-1 skip=0 project=nil | runtime: 0.0000ms

exception=>#<Mongo::Auth::Unauthorized: User ABC123 is not authorized to access MyMongoDB.>
<Mongo::Error::OperationFailure: command insert requires authentication (13)>

```

plugin version **logstash-output-mongodb (3.1.6)**

```auto
}
[2021-03-24T17:00:16,871][WARN][logstash.outputs.mongodb][main] MONGODB | Failed to handshake with myMongoDB-server.com:1234: ArgumentError: wrong number of arguments (given 2, expected 1)
[2021-03-24T17:00:16,871][WARN][logstash.outputs.mongodb][main] MONGODB | Error running ismaster on myMongoDB-server.com:1234: ArgumentError: wrong number of arguments (given 2, expected 1)
[2021-03-24T17:00:16,886][DEBUG][logstash.outputs.mongodb][main] MONGODB | Server description for myMongoDB-server.com:1234changed from 'unknown' to 'unknown'.

```

the user that I'm providing in the uri connection has privileges to add documents, I've tested manually via MongoDB Compass UI.

Any suggestion if this is a bug in the plugins ?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 24, 2021, 9:29pm UTC](https://discuss.elastic.co/t/logstash-mongodb-output-plugin-command-insert-requires-authentication/268265/2 "2021-03-24T21:29:32Z")

</div>

> [@christiancj](#):
>
> Any suggestion if this is a bug

It pretty much has to be, but where to start looking? If you look at the [issues](https://github.com/logstash-plugins/logstash-output-mongodb/issues?q=is%3Aissue+%22wrong+number+of+arguments%22) for the plugin it comes up from time to time. Some of them appear to be version dependencies where an underlying library change their interfaces.

Here is an [example](https://jira.mongodb.org/browse/RUBY-2146) from last year that turned out to be in the mongodb client code.

Last year another user had a similar [issue](https://discuss.elastic.co/t/logstash-warning-hanshaking-error-when-connecting-with-mongodb/250979). I pointed them at an unmerged PR and they said they would try to build it themselves. No indication whether that worked.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 21, 2021, 9:29pm UTC](https://discuss.elastic.co/t/logstash-mongodb-output-plugin-command-insert-requires-authentication/268265/3 "2021-04-21T21:29:52Z")

</div>

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