0

Case: when spawning new dev-environments, I would like to go through some collections and change TLD's in certain string-values, so e.g. "bla bla mydomain.com" becomes "bla bla mydomain.localhost".

I tried simply in patch-window in Raven Studio:

this.MyProperty = this.MyProperty.replace(".com", ".localhost");

But I got:

TypeError: Property 'replace' of object is not a function

After that I went to the docs, where indeed it seems string-replacement is not an option.

My question is: is it possible in any way to do string-replacement in js-patches in RavenDB?

Frederik Struck-Schøning
  • 12,981
  • 8
  • 59
  • 68

2 Answers2

1

This should just work:

this.Name = this.Name.replace("food", "drink");

I just tested it on http://live-test.ravendb.net/studio/index.html#databases/patch/recentpatch--374082468?&database=Northwind and it does work.

However, make sure that the property actually exists and is of type string.

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
0

Ah - found out 5 minutes later:

_.replace(this.MyProperty, ".com", ".localhost");

As docs say, underscore_ references the lodash library (hashtag rtfm)

Frederik Struck-Schøning
  • 12,981
  • 8
  • 59
  • 68
  • lodash works. However, .replace works too. I'm guessing you just needed to a do a null or undefined check, e.g. if (this.Name) { this.Name.replace(...) } – Judah Gabriel Himango May 10 '17 at 14:02