# Big issue with custom javascript

**URL:** <https://forums.rocket.chat/t/big-issue-with-custom-javascript/261>\
**Category:** Community Support\
**Created:** [February 26, 2018, 9:15am UTC](https://forums.rocket.chat/t/big-issue-with-custom-javascript/261 "2018-02-26T09:15:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![silvia-8](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/silvia-8/32/75_2.png) [@silvia-8](https://forums.rocket.chat/u/silvia-8)\
**Post date:** [February 26, 2018, 9:15am UTC](https://forums.rocket.chat/t/big-issue-with-custom-javascript/261/1 "2018-02-26T09:15:23Z")

</div>

Hello,

I did a big mistake,

i added this code in the section custom script

document.write(‘

Print this after the script tag
’);

And now on all my pages i can only see this sentence : “Print this after the script tag” [https://chatpsy.herokuapp.com/home](https://chatpsy.herokuapp.com/home)

If someone could tell me how can i remove this javacript via the database?

Or is there a way to block this specific line of code, enter in the admin and remove it ?

Thanks for your help

---

<div class="post-metadata">

**Author:** ![TwizzyDizzy](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/twizzydizzy/32/11_2.png) [@TwizzyDizzy](https://forums.rocket.chat/u/TwizzyDizzy)\
**Post date:** [February 26, 2018, 8:41pm UTC](https://forums.rocket.chat/t/big-issue-with-custom-javascript/261/2 "2018-02-26T20:41:45Z")

</div>

Without any guarantee: you should be able to restore the MongoDB database of Rocket.Chat - more specifically to your case: the settings collection from your last backup.

If you got no backup (then first: shame on your house!) you could also try to look up the document in the settings collection that stores the custom script settings and either edit or delete it. It will be initialized with default settings once you restart Rocket.Chat.

Cheers  
Thomas

---

<div class="post-metadata">

**Author:** ![aaron.ogle](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/aaron.ogle/32/15_2.png) [@aaron.ogle](https://forums.rocket.chat/u/aaron.ogle)\
**Post date:** [February 27, 2018, 12:48am UTC](https://forums.rocket.chat/t/big-issue-with-custom-javascript/261/3 "2018-02-27T00:48:17Z")

</div>

My suggestion is find the setting name. You can right click it in browser and inspect element and see the id. Then goto mongo and do: `db.rocketchat_settings.remove({_id: 'Setting_Id'})`

---

<div class="post-metadata">

**Author:** ![xet7](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/xet7/32/444_2.png) [@xet7](https://forums.rocket.chat/u/xet7)\
**Post date:** [August 24, 2018, 4:17pm UTC](https://forums.rocket.chat/t/big-issue-with-custom-javascript/261/4 "2018-08-24T16:17:32Z")

</div>

TLDR:

I needed this today, so I finally found how to do this:

```
db.rocketchat_settings.remove({_id: 'Custom_Script_Logged_In'})
db.rocketchat_settings.remove({_id: 'Custom_Script_Logged_Out'})

```

Longer description, how I found this:

To find this, I dumped MongoDB to JSON files with script from [https://stackoverflow.com/questions/11255630/how-to-export-all-collection-in-mongodb](https://stackoverflow.com/questions/11255630/how-to-export-all-collection-in-mongodb)

export.sh:

```
#!/bin/bash

if [! $1]; then
        echo " Example of use: $0 database_name [dir_to_store]"
        exit 1
fi
db=$1
out_dir=$2
if [! $out_dir]; then
        out_dir="./"
else
        mkdir -p $out_dir
fi

tmp_file="fadlfhsdofheinwvw.js"
echo "print('_ ' + db.getCollectionNames())" > $tmp_file
cols=`mongo $db $tmp_file | grep '_' | awk '{print $2}' | tr ',' ' '`
for c in $cols
do
    mongoexport -d $db -c $c -o "$out_dir/exp_${db}_${c}.json"
done
rm $tmp_file

```

I did have Rocket.Chat snap installed, with database at port 27017. I did run script this way, to export parties database to parties directory:

```
chmod +x ./export.sh
./export.sh parties parties

```

Then in that directory I did search for my errorneous text `replaceText` that is part of search-replace script from [https://stackoverflow.com/questions/5558613/replace-words-in-the-body-text](https://stackoverflow.com/questions/5558613/replace-words-in-the-body-text) that I added to custom Javascript and broke UI, so I could not get into admin settings:

```
cd parties
find . | xargs grep 'replaceText' -sl

```

It did show that setting was at `exp_parties_rocketchat_settings.json`

Then I opened it with nano:

```
nano exp_parties_rocketchat_settings.json

```

And used `Ctrl-w` to search for that text `replaceText`, and find that setting.

---

<div class="post-metadata">

**Author:** ![aaron.ogle](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/aaron.ogle/32/15_2.png) [@aaron.ogle](https://forums.rocket.chat/u/aaron.ogle)\
**Post date:** [September 11, 2018, 4:27am UTC](https://forums.rocket.chat/t/big-issue-with-custom-javascript/261/5 "2018-09-11T04:27:48Z")

</div>

Nice thanks for sharing this! Very useful
