# How to reference field value from Environment plugin?

**URL:** <https://discuss.elastic.co/t/how-to-reference-field-value-from-environment-plugin/73394>\
**Category:** Logstash\
**Created:** [January 31, 2017, 4:30pm UTC](https://discuss.elastic.co/t/how-to-reference-field-value-from-environment-plugin/73394 "2017-01-31T16:30:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jimmy\_Kang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimmy_kang/32/14050_2.png) [@Jimmy\_Kang](https://discuss.elastic.co/u/Jimmy_Kang)\
**Post date:** [January 31, 2017, 4:30pm UTC](https://discuss.elastic.co/t/how-to-reference-field-value-from-environment-plugin/73394/1 "2017-01-31T16:30:00Z")

</div>

Hi Guys.

I am on logstash 1.5 and I'm trying to use environment plugin and then pass that field value to mongo as part of the URI for the password. This is mainly to mask the password so that it is not in plaintext in logstash.conf

```
filter {

	environment {
		add_field_from_env => {
			"mongopwd" => "mpwd"
		}
	}
}

```

This is my environment plugin setup. I have confirmed that mongopwd field is now referencing mpwd, the environment variable we set. So now mongopwd = "mypassword".

In output for mongodb I am trying to get the value of this field but the combinations i have tried all are not working.

```
		mongodb {
    		collection => "mydbcollection"
   	 		database => "mydb"
   	 		uri => "mongodb://user:%{mongopwd}@mymongodb"
		}

```

I have tried ${mongopwd}, mongopwd, [mongopwd] and none are working.

Is my syntax for referencing wrong or am I missing a step?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 1, 2017, 7:05am UTC](https://discuss.elastic.co/t/how-to-reference-field-value-from-environment-plugin/73394/2 "2017-02-01T07:05:22Z")

</div>

Unfortunately the `uri` option isn't subject to `%{fieldname}` expansions. One reason could be that fields are event-specific and you don't want to risk reinitializing the connection for each event.

---

<div class="post-metadata">

**Author:** ![Jimmy\_Kang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimmy_kang/32/14050_2.png) [@Jimmy\_Kang](https://discuss.elastic.co/u/Jimmy_Kang)\
**Post date:** [February 1, 2017, 2:34pm UTC](https://discuss.elastic.co/t/how-to-reference-field-value-from-environment-plugin/73394/3 "2017-02-01T14:34:39Z")

</div>

Is there any way on logstash 1.5 for masking the password then?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 1, 2017, 2:36pm UTC](https://discuss.elastic.co/t/how-to-reference-field-value-from-environment-plugin/73394/4 "2017-02-01T14:36:44Z")

</div>

None that I can think of.

---

<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:** [March 1, 2017, 2:36pm UTC](https://discuss.elastic.co/t/how-to-reference-field-value-from-environment-plugin/73394/5 "2017-03-01T14:36:52Z")

</div>

Closed on March 1, 2017, 2:36pm UTC

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